Subscribe to trade results (WS)

Subscribe to trade results

Used to subscribe to all or specific types (e.g., fast buy / sell, limit orders, etc.) of trade results (available for Plus / Pro / Enterprise

URL

wss://api-bot-v1.dbotx.com/trade/ws/

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()
  1. 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

  • method: Currently fixed as "subscribeTradeResults"

  • tradeTypeFilter: Trade types to subscribe: An empty array [] subscribes to all trade types, including any added in the future, "swap_buy_success" indicates a successful fast buy, "swap_buy_fail" indicates a failed fast buy, "swap_sell_success" indicates a successful fast sell, "swap_sell_fail" indicates a failed fast sell

Last updated