Messages
Send A Message Over The WebSocket
Messages sent by the client to the server over a WebSocket follows the
JSON-RPC 2.0 Specification. The server then returns a response following
the same JSON-RPC 2.0 format. The id field sent by the client will be included in the response, allowing the
client to map the server's responses to the messages sent by the client. The client ensures the uniqueness of the
id field.
Find below the message types accepted by the WebSocket:
Subscribe To A Topic
Subscribe to receive a snapshot of your existing data and subsequently receive updates.
Two types of subscription:
- Subscribe by
<TOPIC> - Subscribe by
<TOPIC>and<SYMBOL>plus optional fields (if any)
Message fields:
<TOPIC>: subscription topic<SYMBOL>: market symbol<COMMAND_ID>: unique unsigned long value
The subscription message would be constructed like below:
Subscribe by <TOPIC>
{
"jsonrpc": "2.0",
"type": "command",
"method": "subscribe",
"params": {
"topic": "<TOPIC>"
},
"id": "<COMMAND_ID>"
}
Subscribe by <TOPIC> and <SYMBOL>
{
"jsonrpc": "2.0",
"type": "command",
"method": "subscribe",
"params": {
"topic": "<TOPIC>",
"symbol": "<SYMBOL>"
},
"id": "<COMMAND_ID>"
}
Sample subscription messages:
- Orders
{
"jsonrpc": "2.0",
"type": "command",
"method": "subscribe",
"params": {
"topic": "orders"
},
"id": "1611082473000"
}
- L1 Order Book
{
"jsonrpc": "2.0",
"type": "command",
"method": "subscribe",
"params": {
"topic": "l1Orderbook"
"symbol": "BTCUSD"
},
"id": "1611082473000"
}
Find below the available <TOPIC>:
- Multi-Order Book Data WebSocket
- Unified Anonymous Trades WebSocket
- Anonymous Market Data WebSocket
- Index Data WebSocket
- Private Data WebSocket
Unsubscribe To A Topic
Unsubscribe to stop receive updates.
One type of unsubscription for Day 1:
- Unsubscribe from one
<TOPIC>and<SYMBOL>
Find below the available <TOPIC> for Day 1:
Message fields:
<TOPIC>: subscription topic<SYMBOL>: market symbol<COMMAND_ID>: unique unsigned long value
The unsubscription message would be constructed like below:
Subscribe by <TOPIC> and <SYMBOL>
{
"jsonrpc": "2.0",
"type": "command",
"method": "unsubscribe",
"params": {
"topic": "<TOPIC>",
"symbol": "<SYMBOL>"
},
"id": "<COMMAND_ID>"
}
Sample subscription messages:
- unified anonymous trade subscription
{
"jsonrpc": "2.0",
"type": "command",
"method": "unsubscribe",
"params": {
"topic": "anonymousTrades",
"symbol": "BTCUSDC"
},
"id": "1611082473000"
}
Receive A Message From The WebSocket
JSON-RPC responses are of the following format:
Success responses
{
"jsonrpc": "2.0",
"id": "1650865877698",
"result": {
"responseCode": "200",
"responseCodeName": "OK",
"message": "Successfully subscribed"
}
}
Error responses
{
"jsonrpc": "2.0",
"id": "1650865877698",
"error": {
"code": "-32602",
"errorCode": "29013",
"errorCodeName": "INVALID_TOPIC_ERROR",
"message": "'a-random-topic' is not a valid topic"
}
}
code: JSON-RPC 2.0 error coderesponseCode/errorCode: unique id for response/error coderesponseCodeName/errorCodeName: unique name for response/error codemessage: textual description of theresponseCode/errorCode
Snapshot responses are of the following format:
{
"type": "snapshot",
"dataType": "<DATA_TYPE>",
"data": [ { <TOPIC_RESPONSE> } ]
}
Update responses are of the following format:
{
"type": "update",
"dataType": "<DATA_TYPE>",
"data": { <TOPIC_RESPONSE> }
}
Error responses are of the following format:
{
"type": "error",
"dataType": "V1TAErrorResponse",
"data": {
"errorCode": <ERROR_CODE>,
"errorCodeName": "<ERROR_CODE_NAME>"
}
}