MarketDataSnapshotRequest
MarketDataSnapshotRequest subscribes to real-time market depth updates for a specified trading symbol.
Code example for subscribing to market data:
def subscribe_marketdata(ws, symbol, receiver, accountId=None, subaccountId=None):
payload = {
"type": "subscribe",
"symbol": symbol,
"reqId": str(uuid.uuid4())
}
if accountId is not None:
payload["accountId"] = accountId
if subaccountId is not None:
payload["subaccountId"] = subaccountId
msg = json.dumps({
"messageType": "MarketDataSnapshotRequest",
"timestamp": datetime.now().isoformat(),
"payload": payload
})
ws.send(msg)
while True:
resp = json.loads(ws.recv())
receiver(resp)
{
"messageType": "MarketDataSnapshotRequest",
"timestamp": "2023-02-08T14:19:43.901696",
"payload": {
"type": "subscribe",
"symbol": "BTC-USD",
"reqId": "e07b9683-af27-481a-b4db-1c492114e930"
}
}
{
"messageType": "MarketDataSnapshot",
"timestamp": "2023-02-08T14:19:44Z",
"version": "1.0",
"seqNum": 9,
"sessionId": "fcd5d616-8208-401a-9001-d299bcc9a8c6",
"payload": {
"asks": [
{ "price": "23083.25076763", "size": "1" },
{ "price": "23084.28705625", "size": "4" },
{ "price": "23084.78", "size": "5" },
{ "price": "23089.14", "size": "40" },
{ "price": "23094.57", "size": "50" }
],
"bids": [
{ "price": "23081.96", "size": "1" },
{ "price": "23080.96918517", "size": "4" },
{ "price": "23080.61566563", "size": "5" },
{ "price": "23074.06841953", "size": "40" },
{ "price": "23068.87", "size": "50" }
],
"reqId": "e07b9683-af27-481a-b4db-1c492114e930",
"symbol": "BTC-USD"
}
}
Subscription parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
messageType | string | "MarketDataSnapshotRequest" | |
symbol | string | Trading pair to subscribe to, e.g. BTC-USD | |
reqId | string (UUID) | Unique request ID for this subscription | |
accountId | string (UUID) | Scopes the feed to a specific account. Use either accountId or subaccountId, not both. | |
subaccountId | string (UUID) | Scopes the feed to a specific subaccount. Use either accountId or subaccountId, not both. |
Response parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
messageType | string | Identifies the message as a market data snapshot response | |
symbol | string | Trading pair for this snapshot, e.g. BTC-USD | |
asks | object[] | Full list of asks | |
⤷ price | string | Limit price of the level | |
⤷ size | string | Size of this level | |
bids | object[] | Full list of bids | |
⤷ price | string | Limit price of the level | |
⤷ size | string | Size of this level |