Messages

Fields

WebSocket messages are JSON objects with the following fields:

FieldDescriptionFormat
ttopic
eeventpossible values: tdx:subscribe, tdx:unsubscribe, tdx:order_create, tdx:order_cancel
ddataJSON
aauthenticationJWT token

Topics

Interactions are performed on topics:

TopicDescriptionTypeFormat
<pair>@tradesstream to receive trade updatespublic^[a-zA-Z0-9\-]{1,10}\/[a-zA-Z0-9\-]{1,10}@trades$
<pair>@depthstream to receive order book updates.

A level can be specified by appending it to the topic:
<pair>@depth10
<pair>@depth50
<pair>@depth100
<pair>@depth500

A refresh speed can be specified by appending it to the topic:
<pair>@depth@100ms
<pair>@depth@500ms
<pair>@depth@1000ms
<pair>@depth@5000ms

level and speed can be combined:
<pair>@depth10@100ms
public^[a-zA-Z0-9\-]{1,10}\/[a-zA-Z0-9\-]{1,10}@(depth(10|50|100|500)?(@(100|500|1000|5000)ms)?)$
<subAccountId>@@subaccount-ordersstream to create orders and receive updatesprivate^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}@subaccount-orders$

Subscribing to a topic

First one needs to subscribe to a topic, by sending a message with an event tdx:subscribe. For example, to subscribe to the topic streaming the trades of the BTC/CHF pair, the following message will be sent:

{
  "t": "BTC/CHF@trades",
  "e": "tdx:subscribe"
}
{
  "t": "BTC/CHF@trades",
  "e": "tdx:subscription_received"
}

Unsubscribing from a topic

{
  "t": "BTC/CHF@trades",
  "e": "tdx:unsubscribe"
}
{
  "t": "BTC/CHF@trades",
  "e": "tdx:unsubscription_succeeded"
}

Trades stream

  1. Subscribe
{
  "t": "BTC/CHF@trades",
  "e": "tdx:unsubscribe"
}
  1. Receive confirmation and a stream of trade updates:
{
  "t": "BTC/CHF@trades",
  "e": "tdx:subscription_received"
}
{
  "t": "BTC/CHF@trades",
  "d": {
    "d": 1640760718833000000,
    "p": "10000",
    "q": "2",
    "i": "SWHMAzEePHsGJ9BbqdL3IxpJLgi/5ujG8VezfLnauqg="
  },
  "e": "trade"
}
{
  "t": "BTC/CHF@trades",
  "d": {
    "d": 1640760847376000000,
    "p": "10000",
    "q": "1",
    "i": "iWoKtJn5Zf8XbB3cG2m/7JcTwRmWnXuxjTPKI+wp/tU="
  },
  "e": "trade"
}

Trade data

FieldDescription
dDate
pPrice
qQuantity
iID

Order book stream

  1. Subscribe
{
  "e": "tdx:subscribe",
  "t": "ACETO/USD@depth@100ms"
}
  1. Receive confirmation, the order book and a stream of order book updates:
{
  "t": "ACETO/USD@depth@100ms",
  "e": "tdx:subscription_received"
}
{
  "t": "ACETO/USD@depth@100ms",
  "d": {
    "u": 124,
    "b": [
      [
        "120",
        "2"
      ],
      [
        "114",
        "14"
      ],
      [
        "113",
        "13"
      ],
      [
        "112",
        "12"
      ],
      [
        "111",
        "11"
      ],
      [
        "110",
        "10000"
      ],
      [
        "103",
        "3"
      ],
      [
        "100",
        "11303"
      ],
      [
        "99",
        "1"
      ],
      [
        "98",
        "1"
      ],
      [
        "97",
        "3"
      ],
      [
        "88",
        "8"
      ],
      [
        "80",
        "20"
      ],
      [
        "70",
        "23"
      ],
      [
        "65",
        "16"
      ],
      [
        "64",
        "4"
      ],
      [
        "63",
        "3"
      ],
      [
        "62",
        "2"
      ],
      [
        "61",
        "1"
      ],
      [
        "60",
        "15"
      ],
      [
        "50",
        "1"
      ],
      [
        "2",
        "1"
      ]
    ],
    "a": [
      [
        "130",
        "9"
      ]
    ]
  },
  "e": "orderbook"
}

Order Book data

FieldDescription
uUpdate ID
bBids: an array of BookEntry
aAsks: an array of BookEntry

A BookEntry is an array with 2 values: a price and a quantity. For example: ["130","9"]