Home Platform Algorithms Charts Pricing Documentation Register Account

Order Book order-book.*

Order book snapshots and deltas. The topic is in the form "order-book.<instrumentId>". Instrument IDs are in the form "<symbol>:<broker>".

Request Snapshot

Responds with the existing order book state.

Send

message array ["request", "order-book.*", requestId?]
instruction string = "request"
Specify that message is a request for data.
topic string
The topic in the form `order-book.<instrumentId>`.
requestId string
(Optional) Any string to correlate the response.

Example:

socket.send('["request", "order-book.BTCUSDT:Binance"]')

Receive

The response will take the form:

message array [topic, book]
topic string
The topic in the form `order-book.<instrumentId>`.
book object
A snapshot of the order book
sequence number
The sequence number is to ensure subsequent deltas are incremental.
bids array [level, ...]
An array of bid levels, descending by price.
level array [price, quantity]
price number
quantity number
asks array [level, ...]
An array of ask levels, ascending by price.
level array [price, quantity]
price number
quantity number

Example:

[
    "order-book.XBTUSD:BitMEX",
    {
        sequence: 99999998,
        bids: [
            [10002, 179],
            [10001.5, 532],
            [10000.5, 3000],
            ...
        ],
        asks: [
            [10002.5, 5909],
            [10003, 1294],
            [10003.5, 640],
            ...
        ]
    }
]

Subscribe to Deltas

Streams order book deltas to apply to previous state.

Send

Send subscriptions at the same time as requesting a snapshot and ignore updates that arrive before the snapshot has returned or that don't have a sequence number equal to the previous sequence number plus 1.

If there is a gap in the sequence numbers request another snapshot as above.

message array ["subscribe", "order-book.*"]
instruction string = "subscribe"
Specify that message is an instruction to begin streaming data
topic string
The topic in the form `order-book.<instrumentId>`.

Example:

socket.send('["subscribe", "order-book.BTCUSDT:Binance"]')

Receive

message array [topic, update]
topic string
The topic in the form `order-book.<instrumentId>`.
update object
sequence number
The sequence number is to ensure deltas are incremental.
deltas array [delta, ...]
An array or order book deltas.
delta object {action, data}
See below for delta types.

Example:

[
    "order-book.XBTUSD:BitMEX",
    {
        sequence: 99999999,
        deltas: [
            {action: "insert", side: "bids", data: [10021.5, 50]},
            {action: "update", side: "bids", data: [10016, 149]},
            {action: "delete", side: "bids", data: {price: 9989.5}},
            ...
        ]
    }
];

Insert Delta

Insert deltas must be inserted into the order book in price sort order, ascending for asks and descending for bids (top of books are first in array).

delta object
action string = "insert"
side string
The side of the order book to apply the delta to. `"bid"` or `"ask"`.
data array [price, quantity]
The level to insert.

Update Delta

Update deltas will match an existing price level in the array. Replace this with the delta values. If no existing price level is found, request a new snapshot.

delta object
action string = "update"
side string
The side of the order book to apply the delta to. `"bid"` or `"ask"`.
data array [price, quantity]
The level to update.

Delete Delta

Delete deltas will match an existing price level in the array to be removed. If no existing price level is found, request a new snapshot.

delta object
action string = "delete"
side string
The side of the order book to apply the delta to. `"bid"` or `"ask"`.
data number
The price of the level to delete.

Refresh Delta

If a refresh delta is received, replace the entire order book with the delta contents.

delta object
action string = "refresh"
data object
bids array [level, ...]
level array [price, quantity]
price number
quantity number
asks array [level, ...]
level array [price, quantity]
price number
quantity number

Example:

[
    "order-book.XBTUSD:BitMEX",
    {
        sequence: 100000000,
        deltas: [
            {
                action: "refresh",
                data: {
                    bids: [
                        [10029.5, 2926],
                        [10026.5, 26],
                        [10021, 26],
                        ...
                    ],
                    asks: [
                        [10030, 244],
                        [10030.5, 1562],
                        [10031, 487],
                        ...
                    ]
                }
            }
        ]
    }
];

Was this page useful? If you find any errors or have any questions please get in touch at support@cloud9trader.com.