Hummingbot 第7章:Client 命令行工具

Hummingbot Client 提供了丰富的命令行接口,用于控制交易机器人的全部生命周期。本章详细介绍所有命令的用法。

Hummingbot CLI 命令大全

交互式 Shell

启动 Hummingbot 后进入交互式 Shell 模式:

# 启动容器(Docker)
docker start hummingbot
docker attach hummingbot

# 直接启动(源码)
conda activate hummingbot
hummingbot

基础命令分类

类别命令说明
配置与连接connect, create, import, config管理交易所连接和策略配置
运行控制start, stop, script启动和停止策略
状态查询status, balance, history查看运行状态和交易记录
系统管理export, gateway, pmm, exit系统操作和退出

start 命令

启动当前已导入的策略或脚本:

>>> start

# 输出示例:
# Strategy pmm_btc.yml started.
# All orders created successfully.

# 启动时指定日志级别
>>> start --log-level DEBUG

参数说明

参数类型说明
--log-levelstring设置日志级别(DEBUG/INFO/WARNING/ERROR)
--scriptstring直接启动脚本
--script-configstring脚本配置文件路径

stop 命令

停止当前运行的策略,并取消所有挂单:

>>> stop

# 输出示例:
# Stopping strategy...
# All active orders have been cancelled.
# Strategy pmm_btc.yml stopped.

停止方式对比

# 正常停止(取消订单)
>>> stop

# 强制停止(快速退出)
>>> exit

# 关机停止(关闭进程)
Ctrl + C (两次)

status 命令

查看当前机器人的运行状态,是最常用的监控命令:

>>> status

# 基础状态输出:
# ====== Status ======
# Strategy: pure_market_making
# Exchange: binance
# Trading Pair: BTC-USDT
# Active Orders:
#   Buy: 0.01 BTC @ 50000.0
#   Sell: 0.01 BTC @ 50500.0
# Filled Orders (24h): 5
# Total PnL (24h): 12.50 USDT
# ===================

# 详细状态
>>> status --live

# 持续刷新的实时状态(按 Ctrl+C 退出)

状态字段说明

字段说明
Strategy当前运行的策略名称
Exchange连接的交易所
Trading Pair交易对
Active Orders当前活跃的挂单
Filled Orders已成交订单统计
Total PnL总盈亏(24小时)
Balance各币种余额
Fees手续费统计

balance 命令

查看交易所账户余额:

>>> balance

# 输出示例:
# ====== Balances ======
# Exchange: binance
#   Asset    Balance     Available
#   BTC      0.0500      0.0400
#   USDT     1000.00     950.00
#   ETH      0.0000      0.0000
# ======================

# 查看所有交易所余额
>>> balance --all

# 查看汇总
>>> balance --summary

# Asset    Total       Available   In Order
# BTC      0.0500      0.0400      0.0100
# USDT     1000.00     950.00      50.00

config 命令

查看或修改当前策略的运行参数:

# 查看所有配置
>>> config

# 查看特定参数
>>> config bid_spread
# bid_spread: 0.5

# 修改参数(无需重启策略)
>>> config bid_spread 0.8
# bid_spread = 0.8

# 参数已更新,下一次订单刷新时生效

# 高级用法:显示可调参数列表
>>> config --help

# 可用可调参数:
#   bid_spread                  当前值: 0.5
#   ask_spread                  当前值: 0.5
#   order_amount                当前值: 0.01
#   order_refresh_time          当前值: 60
#   inventory_skew_enabled      当前值: false

其他重要命令

connect 命令

# 连接交易所
>>> connect binance

# 断开交易所
>>> connect binance --disconnect

# 查看当前连接状态
>>> connect --list

# 连接的交易所:
#   - binance (connected)
#   - okx (not connected)
#   - uniswap_v3_ethereum (gateway required)

history 命令

# 查看今日交易记录
>>> history

# 查看最近 7 天
>>> history --days 7

# 查看特定交易对
>>> history --trading-pair BTC-USDT

# 导出交易记录
>>> history --days 30 --export csv
# Trading history exported to data/trade_history_20250101.csv

# 表格格式:
# Timestamp          | Type | Pair      | Side | Price     | Amount | Fee
# 2025-01-01 10:00   | BUY  | BTC-USDT  | BUY  | 50000.00  | 0.01   | 0.50
# 2025-01-01 10:01   | SELL | BTC-USDT  | SELL | 50250.00  | 0.01   | 0.50

export 命令

# 导出策略配置
>>> export pmm_btc.yml
# Config exported to conf/pmm_btc.yml

# 导出密钥备份
>>> export_keys
# Keys exported to conf/exported_keys.yml

import 命令

# 导入策略配置
>>> import conf/pmm_btc.yml

# 导入时验证配置
>>> import conf/pmm_btc.yml --validate
# Config validation passed.

# 导入密钥
>>> import_keys conf/exported_keys.yml

gateway 命令

# 查看 Gateway 状态
>>> gateway status

# 连接 EVM 链
>>> gateway connect ethereum

# 查看已配置的链
>>> gateway list

pmm 命令

Pure Market Making 策略专属命令:

# 调整买单价差
>>> pmm bid_spread 0.3

# 调整卖单价差
>>> pmm ask_spread 0.4

# 查看做市统计
>>> pmm stats

高级命令行技巧

命令组合

# 一条命令完成停止、导入、启动
>>> stop && import new_config.yml && start

# 适用于快速切换策略

历史命令

# 查看命令历史
>>> history --cmd

# 重复执行上一条命令
>>> !!

# 执行历史中的第 N 条命令
>>> !3

脚本模式运行

# 非交互模式:直接执行命令
docker exec hummingbot hummingbot start --script my_script.py

# 管道模式
echo "status" | docker exec -i hummingbot hummingbot

故障排除命令

命令用途
ping测试交易所连接延迟
rate_limits查看当前 API 速率限制状态
ticker查看实时价格
order_book查看订单簿深度