如何在 Hummingbot 中配置 V2 策略控制器¶

什么是控制器?¶
在 Hummingbot 的新策略 V2 框架中,控制器 是用于管理你的交易策略的工具。它们收集市场数据(如价格信息和交易量),并据此自动做出交易决策。
控制器让你无需运行多个机器人,即可同时管理多个交易策略或交易对,从而简化管理并节省资源。
示例场景¶
假设你希望在 Binance 期货市场上为两个不同的加密货币交易对提供流动性(挂买单和卖单)。每个交易对可能需要不同的设置,例如订单大小、杠杆倍数以及买卖价差。
以前,你需要使用多个机器人来实现。但现在通过 Hummingbot 的 V2 控制器,你可以仅用一个脚本来统一管理所有配置:
- 控制器脚本:pmm_simple.py
- 通用执行脚本:v2_with_controllers.py
分步指南¶
步骤 1:创建控制器配置¶
要设置你的控制器,请运行以下命令:
系统将提示你输入以下配置信息:
- 交易金额:你将用于交易的资金数量。
- 连接器:你所使用的交易所(例如,Binance)。
- 交易对:具体的加密货币交易对。
- 价差:你的订单与当前市场价格之间的距离。
- 刷新时间:机器人更新订单的频率。
- 杠杆:交易仓位的放大倍数(例如,20 倍杠杆)。
- 止损和止盈:用于最小化亏损并锁定收益的限制条件。
以下是完整的提示内容:
Enter the total amount in quote asset to use for trading: (e.g, 1000):  >>> 100
Enter the connector name (e.g., binance_perpetual):   >>> binance_perpetual
Enter the trading pair to trade on (e.g., WLD-USDT):  >>> WLD-USDT
Enter a comma-separated list of buy spreads: (e.g., '0.01, 0.02')   >>> 0.01, 0.02
Enter a comma-separated list of sell spreads: (e.g., '0.01, 0.02')  >>> 0.01, 0.02
Enter a comma-separated list of buy amounts as percentages (e.g., '50, 50'), or leave blank to distribute equally:  >>> 
Enter a comma-separated list of sell amounts as percentages (e.g., '50, 50'), or leave blank to distribute equally:   >>> 
Enter the refresh time in seconds for executors (e.g., 300 for 5 minutes):  >>> 20
Enter the cooldown time in seconds between replacing an executor that traded (e.g., 15):  >>>
Enter the leverage to use for trading (e.g., 20 for 20x leverage). Set it to 1 for spot trading:  >>> 20 
Enter the stop loss (as a decimal, e.g., 0.03 for 3%):  >>> 0.03
Enter the take profit loss (as a decimal, e.g., 0.02 for 2%):  >>> 0.02
Enter the time limit in seconds (e.g., 2700 for 45 minutes):  >>> 2700
Enter the order type for take profit (LIMIT/MARKET):  >>> OrderType.LIMIT
Enter the trailing stop as activation_price, trailing_delta (e.g., 0.0015,0.003):   >>> 0.013, 0.003
Enter the position rebalance threshold percentage  (e.g., 0.05 for 5%):   >>> 0.05
Enter a new file name for your configuration >> conf_market_making.pmm_simple_1.yml
使用不同的名称保存你的配置文件,例如:
- conf_market_making.pmm_simple_1.yml
- conf_market_making.pmm_simple_2.yml
这些文件将位于以下路径:
步骤 2:创建通用脚本¶
现在,创建一个通用脚本以同时运行这两个控制器配置:
输入您之前创建的配置:
Controller configurations >>> conf_market_making.pmm_simple_1.yml, conf_market_making.pmm_simple_2.yml
Configuration filename >>> conf_v2_with_controllers_1.yml
提示
设置完成后,直接手动编辑此配置文件比每次重新创建更加简便。
步骤 3:启动您的机器人¶
使用以下命令启动您的机器人:
使用以下命令检查其状态:
进行动态更新¶
Strategy V2 最佳特性之一是,您可以在机器人运行时调整交易参数。只需直接编辑您的控制器 YAML 文件即可:
编辑示例:
connector_name: binance_perpetual
trading_pair: WLD-USDT
total_amount_quote: 100.0
buy_spreads:
  - 0.01
  - 0.02
sell_spreads:
  - 0.01
  - 0.02
leverage: 20
stop_loss: 0.03
take_profit: 0.02
保存(CTRL + O)并退出(CTRL + X)后,您的机器人将在一分钟内自动更新。
总结思考¶
Hummingbot 的 Strategy V2 控制器使自动化交易更简单、更灵活且更高效。现在,您只需一个机器人实例即可轻松运行复杂策略,并管理多个配置。
 
                 
                    


