Subscribe to trade results (WS)
Subscribe to trade results
URL
Header: X-API-KEY
(Please do not disclose your API Key to anyone. If you are at risk of losing it, please refresh it.)
Notes
1. X-API-KEY can be obtained in your "Dashboard", go to check: Dashboard
2. To ensure the availability and stability of the WebSocket connection, a heartbeat subscription must be sent at least once every minute (recommended every 30β55 seconds), otherwise the system will automatically disconnect the timeout link
3. Example in 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()
}, 50000)
})
ws.on('message', res =>{
console.log('res:', res)
})
}
main()
Example in 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(50)
async def listen():
async for message in ws:
print(">>", message)
await asyncio.gather(keep_alive(), listen())
if name == "main":
asyncio.run(main())
Request Example
{
"method": "subscribeTradeResults",
"tradeTypeFilter": [
"swap_buy_success",
"swap_buy_fail",
"swap_sell_success",
"swap_sell_fail"
]
}
Request Response
{
"method": "subscribeResponse",
"result": {
"message": "Connected and subscribed"
}
}
Request Parameters
Last updated