Skip to content

WebSockets API

The WebSockets API provides data feeds providing the trader real-time information.

See the guide for examples on how to use the WebSockets API.

Common schemas

Interactions with the WebSockets endpoint is done using common base JSON schemas for all channels/feed types. For specific feeds, see the following subsections.

Subscribe

Use the following schema to subscribe to a channel.

JSON Schema

ParameterTypeDescription
typestringMessage type (subscribe).
channelstringFeed type identifier.
idstringSelector for channel-specific data. Only used in some channels.
batchedboolReduce incoming messages by batching contents.
Example
{ 
    "type": "subscribe", 
    "channel": "v4_trades",
    "id": "BTC-USD",
    "batched": false
}

Response

ParameterTypeDescription
typestringMessage type (subscribed).
connection_idstringString identifying the subscription.
message_idintMessage sequence number sent on the subscription.
idstringSelector for channel-specific data.
contentsvalueChannel-specific initial data.

Unsubscribe

Use the following schema to unsubscribe from a channel. Similar scheme to the subscribe schema, however with the unsubscribe type, and without the batched field.

JSON Schema

ParameterTypeDescription
typestringMessage type (unsubscribe).
channelstringFeed type identifier.
idstringSelector for channel-specific data.
Example
{
    "type": "unsubscribe",
    "channel": "v4_trades",
    "id": "BTC-USD"
}

Response

ParameterTypeDescription
typestringMessage type (unsubscribed).
connection_idstringString identifying the subscription.
channelstringFeed type identifier.
message_idintMessage sequence number sent on the subscription.
idstringSelector for channel-specific data. Only used in some channels.

Data

After subscription, the incoming messages will be serialized using the following schema.

JSON Schema

ParameterTypeDescription
connection_idstringString identifying the subscription.
channelstringFeed type identifier.
idstringSelector for channel-specific data. Only used in some channels.
message_idintMessage sequence number sent on the subscription.
versionstringProtocol identifier.
contentsvalueChannel-specific message data.

Updates arrive in the order they happened. With batched: true, contents is an array of updates, oldest first — the same order as the individual messages you would receive without batching. Apply the updates one by one, in that order, to the state from the initial subscribed message.

Channels

The available clients API is presented below. For each, the subscription and unsubscription functions are shown. Internally, these functions send messages serialized in the subscribe and unsubscribe JSON schemas above.

For each channel/feed type the sub-schemas employed in the contents field of the received Data (after subscription) are shown.