用于订阅全部或指定部分类型 (例如快速买卖 / 限价单等) 的交易结果(Plus / Pro / Enterprise可用)
Free | Plus | Pro | Enterprise | 积分消耗 |
---|---|---|---|---|
❌ | ✅ | ✅ | ✅ | 0 |
URL
wss://api-bot-v1.dbotx.com/trade/ws/
说明
为保证WebSocket连接的可用性和稳定性,需要至少每1分钟(建议每30-55秒)进行一次心跳订阅,否则系统会自动断开超时链接
请求示例
{
"method": "subscribeTradeResults", // 当前固定为“subscribeTradeResults”
"tradeTypeFilter": [ // 需要订阅的交易类型,空数组[]表示订阅所有交易类型,包括所有后续新增的
"swap_buy_success", // 订阅快速买入成功通知
"swap_buy_fail", // 订阅快速买入失败通知
"swap_sell_success", // 订阅快速卖出成功通知
"swap_sell_fail", // 订阅快速卖出失败通知
"limit_buy_success", // 订阅限价买入成功通知
"limit_buy_fail", // 订阅限价买入失败通知
"limit_sell_success", // 订阅限价卖出成功通知
"limit_sell_fail", // 订阅限价卖出失败通知
"swap_take_profit_success", // 订阅快速买卖止盈卖出成功通知
"swap_take_profit_fail", // 订阅快速买卖止盈卖出失败通知
"swap_stop_loss_success", // 订阅快速买卖止损卖出成功通知
"swap_stop_loss_fail", // 订阅快速买卖止损卖出失败通知
"swap_trailing_stop_success", // 订阅快速买卖移动止盈止损卖出成功通知
"swap_trailing_stop_fail", // 订阅快速买卖移动止盈止损卖出失败通知
,"follow_take_profit_success", // 订阅跟单止盈卖出成功通知
"follow_take_profit_fail", // 订阅跟单止盈卖出失败通知
"follow_stop_loss_success", // 订阅跟单止损卖出成功通知
"follow_stop_loss_fail", // 订阅跟单止损卖出失败通知
"follow_trailing_stop_success", // 订阅跟单移动止盈止损卖出成功通知
"follow_trailing_stop_fail", // 订阅跟单移动止盈止损卖出失败通知
"follow_buy_success", // 订阅跟单买入成功通知
"follow_buy_fail", // 订阅跟单买入失败通知
"follow_sell_success", // 订阅跟单卖出成功通知
"follow_sell_fail", // 订阅跟单卖出失败通知
]
}
响应数据
{
"method": "subscribeResponse", // 当前固定为“subscribeTradeResults”
"result": {
"message": "Connected and subscribed"
}
}
以NodeJS为例
const WebSocket = require('ws')
function main() {
const ws = new WebSocket('wss://api-bot-v1.dbotx.com/trade/ws/', {
headers: {
'x-api-key': 'YOUR_API_KEY',
},
})
ws.on('open', () => {
ws.send(
JSON.stringify({
method: 'subscribeTradeResults',
tradeTypeFilter: [
'swap_buy_success',
'swap_buy_fail',
'swap_sell_success',
'swap_sell_fail',
],
},
})
)
setInterval(() => {
ws.ping()
}, 30000)
})
ws.on('message', res => {
console.log('res:', res.toString('utf-8'))
})
}
main()
以Python为例
import asyncio
import websockets
import json
async def main():
uri = "wss://api-bot-v1.dbotx.com/trade/ws/"
headers = {"x-api-key": "YOUR_API_KEY"}
msg = {
"method": "subscribeTradeResults",
"tradeTypeFilter": ["swap_buy_success", "swap_buy_fail", "swap_sell_success", "swap_sell_fail"]
}
async with websockets.connect(uri, additional_headers=headers) as ws:
await ws.send(json.dumps(msg))
async def keep_alive():
while True:
await ws.ping()
await asyncio.sleep(30)
async def listen():
async for message in ws:
print("res:", message)
await asyncio.gather(keep_alive(), listen())
if __name__ == "__main__":
asyncio.run(main())