使用 Vega 协议与 Hummingbot¶

引言¶
在本指南中,我们将逐步介绍如何顺利设置 Vega 钱包、将其与 Hummingbot 连接,并在 Vega 去中心化交易所上运行强大的算法交易策略。
观看 YouTube 上的教程视频,然后开始吧!
创建 Vega 钱包¶
Vega 钱包对于与 Vega 网络交互至关重要,无论是质押还是交易。Vega 钱包应用允许你管理钱包和密钥对、存取资产、进行质押以及签署交易。
连接 MetaMask Snap¶
要开始操作,请访问Vega 控制台并点击连接到 Vega。之后,系统会提供几种创建 Vega 钱包的选项:
下方我们展示如何使用MetaMask Snap,这是我们推荐给 Hummingbot 用户的方案。
在上方菜单中选择MetaMask Snap,并通过你在MetaMask中的首选以太坊地址进行连接。
你会看到一个弹窗提示所需权限——点击安装。
随后,同意其余弹窗提示,最终应看到“连接成功”的通知。现在你已准备好存款资产并使用新的 Vega 钱包。
存入资金¶
创建 Vega 钱包后,前往Vega 控制台,默认情况下你会被重定向至 MAINNET 交易所。
如果你想切换到 Fairground 测试网,请先退出弹窗,然后点击 Vega 交易所网站左上角,以更改网络。
选择好网络后,点击上方弹窗中的 充值 按钮,并连接你的以太坊钱包,以批准并将符合条件的代币存入你的新 Vega 钱包。
将 Hummingbot 连接到 Vega¶
在为你的 Vega 钱包充值后,你现在可以连接 Hummingbot 并开始运行算法交易策略。由于我们使用了 MetaMask Snap 来连接 Vega,因此需要以下两个信息:
- Snap Key:Vega 公钥或用户 ID(party id)
- 助记词(Seed Phrase)
下面我们来看看如何获取这些信息:
获取 Snap Key¶
连接 Vega 钱包后,在屏幕右上角找到你的 Snap Key。
Snap Key 0 地址应是你之前从以太坊钱包充值资产的那个 Vega 公钥 地址。点击该地址可将其复制到剪贴板,之后在 Hummingbot 中提示输入 Vega 公钥(party id) 时粘贴即可。
获取钱包助记词¶
由于我们使用 MetaMask Snap 连接 Vega,你的私钥就是用于建立连接的以太坊钱包的 助记词。在将 Vega 钱包连接到 Hummingbot 时,系统会要求你输入此助记词,作为身份验证和设置流程的一部分。
请参考这篇 MetaMask 文章来查找你的助记词:如何显示你的秘密恢复短语。按照文章中的步骤获取你的以太坊钱包助记词。
警告
你的钱包助记词极为敏感,请严格保密,切勿在线分享或告知任何你不信任的人。处理助记词时,请始终确保处于安全且私密的环境中。
安装 Hummingbot¶
在获取 Snap Key 和助记词后,你就可以将 Hummingbot 连接到 Vega 了!建议收藏 Vega 连接器 文档页面,以便随时查阅。
现在,请按照 安装流程 安装 Hummingbot。最简单的入门方式是克隆 GitHub 仓库并启动 Docker 镜像:
git clone https://github.com/hummingbot/hummingbot
cd hummingbot
docker compose up -d
docker attach hummingbot
运行连接命令¶
在 Hummingbot 客户端中,通过运行 connect vega_perpetual 来连接 Vega 主网。若要连接到 Vega Fairground 测试网,请运行 connect vega_perpetual_testnet。
首先,系统会提示你输入 Vega 公钥——在此输入你的 Snap Key。然后,输入你的钱包助记词。
如果两个凭据均有效,你应该会看到如下消息:
为确认连接成功,请运行 balance 命令。你的资产余额应与你存入 Vega 的金额一致。
运行方向性策略¶
现在,让我们在 Vega 上配置并运行一个示例算法交易策略 —— v2_directional_rsi.py。
这是一个简单的方向性策略:当市场超卖时(由 RSI 指标衡量),策略将建立多头仓位;反之,当市场超买时,机器人将建立空头仓位。仓位建立后,该策略会使用 PositionExecutor 来进行管理。
配置脚本¶
首先,让我们为此策略创建一个针对 Vega 的配置文件。运行:
根据提示输入你希望设置的参数值,并保存文件。该文件位于 /conf/scripts 文件夹下,你可以使用任意文本编辑器或 IDE(如 VSCode)打开该 YAML 文件并进行修改。
请注意:
- 由于 Vega 目前尚不支持K 线图,因此您需要为candles_exchange使用除 Vega 以外的其他交易所(例如 Binance Futures)。
- 每个交易所的交易对符号都需要正确定义。对于 Vega,我们将使用ETHUSDT-USDT,而在 Binance Futures 上则使用ETH-USDT交易对。
- 此配置将 RSI 上下限均设置为 50,以便策略启动后立即开仓。您可能希望使用不同的数值。
作为参考,以下是该策略针对 Vega 的特定配置:
markets: {}
candles_config: []
controllers_config: []
config_update_interval: 60
script_file_name: v2_directional_rsi.py
exchange: vega_perpetual
trading_pair: ETHUSDT-USDT
candles_exchange: binance_perpetual
candles_pair: ETH-USDT
candles_interval: 1m
candles_length: 60
rsi_low: 50.0
rsi_high: 50.0
order_amount_quote: 30
leverage: 10
position_mode: ONEWAY
stop_loss: 0.03
take_profit: 0.01
time_limit: 2700
启动脚本¶
现在,我们可以使用start命令来运行脚本:
机器人已进入空头仓位。随后,它设置了买入限价止损单。
您可以运行status命令或按下CTRL + S键来查看机器人的实时状态:
Vega 数据节点¶
在上述日志中请注意,机器人连接到了 Vega Protocol 的端点https://darling.network。这是向 Hummingbot 流式传输市场数据的 Vega 数据节点。
数据节点列表¶
Hummingbot 中的 Vega 连接器在vega_perpetual_constants.py文件中维护其使用的数据节点列表。默认情况下,Vega 连接器会尝试使用延迟最低的端点。
若要使用您自己的数据节点,请将该文件以下部分中的 URL 替换为您自己的数据节点 URL:
PERPETUAL_API_ENDPOINTS = [
    "https://darling.network/",
    "https://graphqlvega.gpvalidator.com/",
    "https://vega-data.bharvest.io/",
    "https://vega-data.nodes.guru:3008/",
    "https://vega-mainnet-data.commodum.io/",
    "https://vega-mainnet.anyvalid.com/",
    "https://vega.aurora-edge.com/",
    "https://vega.mainnet.stakingcabin.com:3008/",
]
PERPETUAL_GRPC_ENDPOINTS = [
    "darling.network:3007",
    "vega-data.bharvest.io:3007",
    "vega-data.nodes.guru:3007",
    "vega-mainnet.anyvalid.com:3007",
    "vega.mainnet.stakingcabin.com:3007",
]
运行数据节点¶
使用您自己的数据节点而非公共节点可能会带来显著的延迟优势,但成本可能成为一个问题。为了帮助用户决定是否运行自己的数据节点,请参阅运行 Vega 数据节点,了解使用 Hummingbot 运行 Vega 数据节点的性能对比和成本分析。
Vega 交易对¶
以下是 Mainnet 和 Vega 网络上的各种交易对以及如何在 Hummingbot 中输入它们:
| 主网交易对 | Hummingbot | 测试网交易对 | Hummingbot | |
|---|---|---|---|---|
| ETH/USDT-PERP | ETHUSDT-USDT | BTC/USDT-PERP | BTCUSDT-USDT | |
| LDO/USDT-PERP | LDOUSDT-USDT | BTCUSD.PYTH.PERP | BTCUSDTPYTHPERPNOI-USDNOI | |
| BTC/USDT-PERP | BTCUSDT-USDT | ETH/USDT-PERP | ETHUSDT-USDT | |
| INJ/USDT-PERP | INJUSDT-USDT | JUPUSDT.PYTH.PERP | JUPUSDTPYTHPERPNOI-USDNOI | |
| SNX/USDT-PERP | SNXUSDT-USDT | INJ/USDT-PERP | INJUSDT-USDT | |
| SOL/USDT-PERP | SOLUSDT-USDT | LDO/USDT-PERP | LDOUSDT-USDT | |
| SNX/USDT-PERP | SNXUSDT-USDT | 
常见问题¶
vega_perpetual 尚未就绪
2024-02-14 09:59:38,522 - 1423 - hummingbot.client.hummingbot_application - INFO - Creating the clock with tick size: 1.0
2024-02-14 09:59:38,525 - 1423 - hummingbot.client.hummingbot_application - INFO - start command initiated.
2024-02-14 09:59:39,001 - 1423 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 09:59:40,001 - 1423 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 09:59:41,001 - 1423 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 09:59:42,000 - 1423 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 09:59:42,954 - 1423 - hummingbot.connector.derivative.vega_perpetual.vega_perpetual_derivative.VegaPerpetualDerivative - INFO - Network status has changed to NetworkStatus.CONNECTED. Starting networking...
2024-02-14 09:59:43,001 - 1423 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 09:59:44,000 - 1423 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 09:59:45,001 - 1423 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 09:59:46,000 - 1423 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 09:59:47,000 - 1423 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 09:59:47,671 - 1423 - hummingbot.client.hummingbot_application - INFO - stop command initiated.
2024-02-14 09:59:49,273 - 1423 - hummingbot.core.rate_oracle.rate_oracle - INFO - Network status has changed to NetworkStatus.CONNECTED. Starting networking...
2024-02-14 09:59:53,933 - 1423 - hummingbot.client.hummingbot_application - ERROR - MQTT is already stopped!
2024-02-14 23:45:21,966 - 684 - hummingbot.client.hummingbot_application - INFO - Creating the clock with tick size: 1.0
2024-02-14 23:45:21,969 - 684 - hummingbot.client.hummingbot_application - INFO - start command initiated.
2024-02-14 23:45:22,000 - 684 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 23:45:23,001 - 684 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 23:45:24,001 - 684 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 23:45:24,159 - 684 - hummingbot.connector.derivative.vega_perpetual.vega_perpetual_derivative.VegaPerpetualDerivative - INFO - Network status has changed to NetworkStatus.CONNECTED. Starting networking...
2024-02-14 23:45:25,000 - 684 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 23:45:26,000 - 684 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 23:45:27,001 - 684 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 23:45:28,000 - 684 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 23:45:29,001 - 684 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 23:45:30,000 - 684 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 23:45:31,001 - 684 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 23:45:32,001 - 684 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 23:45:33,001 - 684 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 23:45:34,001 - 684 - hummingbot.strategy.script_strategy_base - WARNING - vega_perpetual is not ready. Please wait...
2024-02-14 23:45:34,460 - 684 - hummingbot.connector.derivative.vega_perpetual.vega_perpetual_derivative.VegaPerpetualDerivative - INFO - Connected to Vega Protocol endpoint: https://darling.network/
- 首次启动脚本时,日志面板可能会频繁显示上述消息,这是正常现象,因为机器人正在尝试连接到节点。请等待大约一分钟,让机器人完成连接。
提交买入订单失败
Traceback (most recent call last):  File "/home/hummingbot/hummingbot/connector/exchange_py_base.py", line 452, in _create_order  await self._place_order_and_process_update(order=order, **kwargs,)  File "/home/hummingbot/hummingbot/connector/derivative/vega_perpetual/vega_perpetual_derivative.py", line 456, in _place_order_and_process_update  exchange_order_id, update_timestamp = await self._place_order(  File "/home/hummingbot/hummingbot/connector/derivative/vega_perpetual/vega_perpetual_derivative.py", line 543, in _place_order  transaction = await self._auth.sign_payload(order_payload, "order_submission")  File "/home/hummingbot/hummingbot/connector/derivative/vega_perpetual/vega_perpetual_auth.py", line 78, in sign_payload  self._client: Client = Client(  File "/opt/conda/envs/hummingbot/lib/python3.10/site-packages/vega/client.py", line 54, in __init__  self._starting_block_height = self._core_data_client.LastBlockHeight(  File "/opt/conda/envs/hummingbot/lib/python3.10/site-packages/grpc/_channel.py", line 1160, in __call__  return _end_unary_response_blocking(state, call, False, None)  File "/opt/conda/envs/hummingbot/lib/python3.10/site-packages/grpc/_channel.py", line 1003, in _end_unary_response_blocking  raise _InactiveRpcError(state) # pytype: disable=not-instantiable grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:  status = StatusCode.UNAVAILABLE  details = "connection error: desc = "transport: Error while dialing: dial tcp 127.0.0.1:3002: connect: connection refused""  debug_error_string = "UNKNOWN:Error received from peer ipv4:54.180.211.130:3007 {created_time:"2024-02-06T12:25:12.356527762+00:00", grpc_status:14, grpc_message:"connection error: desc = \"transport: Error while dialing: dial tcp 127.0.0.1:3002: connect: connection refused\""}" > 2024-02-06 12:25:12,360 - 15 - hummingbot.connector.derivative.vega_perpetual.vega_perpetual_derivative.VegaPerpetualDerivative - WARNING - Failed to submit BUY order to Vega_perpetual. Check API key and network connection. - 使用公共节点时,可能会出现机器人尝试创建订单但失败的情况。这种失败可能是由于与节点的连接丢失所致。机器人会自动尝试重新连接,但如果重连失败,建议停止机器人并重新启动。
买入订单金额小于最小订单规模
2024-02-14 23:46:21,686 - 684 - hummingbot.connector.derivative.vega_perpetual.vega_perpetual_derivative.VegaPerpetualDerivative - WARNING - Buy order amount 0 is lower than the minimum order size 0.001. The order will not be created, increase the amount to be higher than the minimum order size.
2024-02-14 23:46:21,690 - 684 - hummingbot.core.event.event_reporter - EVENT_LOG - {"timestamp": 1707925581.0, "order_id": "VGHBBEPUT611596998f17a44a669251c", "order_type": "OrderType.MARKET", "event_name": "MarketOrderFailureEvent", "event_source": "vega_perpetual"}
2024-02-14 23:46:21,690 - 684 - hummingbot.strategy.script_strategy_base - INFO - Creating ETHUSDPERP-USDT buy order: price: NaN amount: 0.
2024-02-14 23:46:21,690 - 684 - hummingbot.smart_components.executors.position_executor.position_executor - INFO - Placing close order --> Filled amount: 0 | TP Partial execution: 0
2024-02-14 23:46:21,692 - 684 - hummingbot.connector.client_order_tracker - INFO - Order VGHBBEPUT611596998f17a44a669251c has failed. Order Update: OrderUpdate(trading_pair='ETHUSDPERP-USDT', update_timestamp=1707925581.0, new_state=<OrderState.FAILED: 6>, client_order_id='VGHBBEPUT611596998f17a44a669251c', exchange_order_id=None, misc_updates=None)
2024-02-14 23:46:21,692 - 684 - hummingbot.connector.derivative.vega_perpetual.vega_perpetual_derivative.VegaPerpetualDerivative - WARNING - Buy order amount 0 is lower than the minimum order size 0.001. The order will not be created, increase the amount to be higher than the minimum order size.
2024-02-14 23:46:21,763 - 684 - hummingbot.core.event.event_reporter - EVENT_LOG - {"timestamp": 1707925581.0, "order_id": "VGHBBEPUT61159699976cc44a669251c", "order_type": "OrderType.MARKET", "event_name": "MarketOrderFailureEvent", "event_source": "vega_perpetual"}
2024-02-14 23:46:21,764 - 684 - hummingbot.strategy.script_strategy_base - INFO - Creating ETHUSDPERP-USDT buy order: price: NaN amount: 0.
2024-02-14 23:46:21,764 - 684 - hummingbot.smart_components.executors.position_executor.position_executor - INFO - Placing close order --> Filled amount: 0 | TP Partial execution: 0
2024-02-14 23:46:21,766 - 684 - hummingbot.connector.client_order_tracker - INFO - Order VGHBBEPUT61159699976cc44a669251c has failed. Order Update: OrderUpdate(trading_pair='ETHUSDPERP-USDT', update_timestamp=1707925581.0, new_state=<OrderState.FAILED: 6>, client_order_id='VGHBBEPUT61159699976cc44a669251c', exchange_order_id=None, misc_updates=None)
2024-02-14 23:46:21,766 - 684 - hummingbot.connector.derivative.vega_perpetual.vega_perpetual_derivative.VegaPerpetualDerivative - WARNING - Buy order amount 0 is lower than the minimum order size 0.001. The order will not be created, increase the amount to be higher than the minimum order size.
2024-02-14 23:46:21,771 - 684 - hummingbot.core.event.event_reporter - EVENT_LOG - {"timestamp": 1707925581.0, "order_id": "VGHBBEPUT61159699a97aa44a669251c", "order_type": "OrderType.MARKET", "event_name": "MarketOrderFailureEvent", "event_source": "vega_perpetual"}
2024-02-14 23:46:21,771 - 684 - hummingbot.strategy.script_strategy_base - INFO - Creating ETHUSDPERP-USDT buy order: price: NaN amount: 0.
2024-02-14 23:46:21,772 - 684 - hummingbot.smart_components.executors.position_executor.position_executor - INFO - Placing close order --> Filled amount: 0 | TP Partial execution: 0
2024-02-14 23:46:21,773 - 684 - hummingbot.connector.client_order_tracker - INFO - Order VGHBBEPUT61159699a97aa44a669251c has failed. Order Update: OrderUpdate(trading_pair='ETHUSDPERP-USDT', update_timestamp=1707925581.0, new_state=<OrderState.FAILED: 6>, client_order_id='VGHBBEPUT61159699a97aa44a669251c', exchange_order_id=None, misc_updates=None)
2024-02-14 23:46:21,806 - 684 - hummingbot.connector.derivative.vega_perpetual.vega_perpetual_derivative.VegaPerpetualDerivative - WARNING - Buy order amount 0 is lower than the minimum order size 0.001. The order will not be created, increase the amount to be higher than the minimum order size.
2024-02-14 23:46:21,813 - 684 - hummingbot.core.event.event_reporter - EVENT_LOG - {"timestamp": 1707925581.0, "order_id": "VGHBBEPUT61159699ab4c344a669251c", "order_type": "OrderType.MARKET", "event_name": "MarketOrderFailureEvent", "event_source": "vega_perpetual"}
2024-02-14 23:46:21,814 - 684 - hummingbot.strategy.script_strategy_base - INFO - Creating ETHUSDPERP-USDT buy order: price: NaN amount: 0.
2024-02-14 23:46:21,814 - 684 - hummingbot.smart_components.executors.position_executor.position_executor - INFO - Placing close order --> Filled amount: 0 | TP Partial execution: 0
2024-02-14 23:46:21,816 - 684 - hummingbot.connector.client_order_tracker - INFO - Order VGHBBEPUT61159699ab4c344a669251c has failed. Order Update: OrderUpdate(trading_pair='ETHUSDPERP-USDT', update_timestamp=1707925581.0, new_state=<OrderState.FAILED: 6>, client_order_id='VGHBBEPUT61159699ab4c344a669251c', exchange_order_id=None, misc_updates=None)
2024-02-14 23:46:21,817 - 684 - hummingbot.connector.derivative.vega_perpetual.vega_perpetual_derivative.VegaPerpetualDerivative - WARNING - Buy order amount 0 is lower than the minimum order size 0.001. The order will not be created, increase the amount to be higher than the minimum order size.
2024-02-14 23:46:21,862 - 684 - hummingbot.core.event.event_reporter - EVENT_LOG - {"timestamp": 1707925581.0, "order_id": "VGHBBEPUT61159699b5bdf44a669251c", "order_type": "OrderType.MARKET", "event_name": "MarketOrderFailureEvent", "event_source": "vega_perpetual"}
2024-02-14 23:46:21,862 - 684 - hummingbot.strategy.script_strategy_base - INFO - Creating ETHUSDPERP-USDT buy order: price: NaN amount: 0.
2024-02-14 23:46:21,863 - 684 - hummingbot.smart_components.executors.position_executor.position_executor - INFO - Placing close order --> Filled amount: 0 | TP Partial execution: 0
- 这是一个已知问题,机器人尝试平仓但无法获取订单金额——预计很快会推出修复方案。
 
                 
                    











