Subscribes/Unsubscribes to market order book snapshot data.
Make sure you're connected to this subscription: wss://ws.web3api.io.
Request
All exchanges:
{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["market:spot:order:snapshots",{"pair":"btc_usd"}]}
Specific exchange:
{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["market:spot:order:snapshots",{"pair":"btc_usd","exchange":"gdax"}]}
Param | Type | Description |
---|---|---|
pair* | string | The asset pair. |
exchange | string | The exchange for which to retrieve asset pairs. |
*required
Note: Subscription response will include a field metadata
which includes the names of the columns in the order in which they appeared in the event notification response.
Response
{
"jsonrpc": "2.0",
"method": "subscription",
"params": {
"result": [
{
"exchange": "lmax",
"instrument": "btc_usd",
"timestamp": 1707246720000,
"exchangeTimestamp": 1707246721000,
"isBid": false,
"data": [
[
43147.807,
0.11,
null
],
[
43148,
1.97,
null
],
[
43149,
1.3,
null
]
],
"sequence": null
},
{
"exchange": "lmax",
"instrument": "btc_usd",
"timestamp": 1707246720000,
"exchangeTimestamp": 1707246721000,
"isBid": true,
"data": [
[
43135,
2.97,
null
],
[
43131.211,
0.11,
null
],
[
43130.5,
2,
null
]
],
"sequence": null
}
],
"subscription": "3528e070f41a7539ec0c2de2ebaaca5f5c277de149ea71cdcaafe03f273533f3"
}
}
Field | Type | Description |
---|---|---|
exchange | string | The exchange. |
instrument | string | The pair |
timestamp | number | The time at which the trade took place. |
exchangeTimestamp | number | The timestamp from the exchange. |
isBid | bool | Indicates if it is a bid or ask order: true for a bid and false for an ask. |
data.price | number | The quote price of the asset pair. |
data.volume | number | The number of assets traded in a specific asset pair within a given period of time. |
data.sequence | number | The sequence |
Example
const WebSocket = require('ws');
const ws = new WebSocket('wss://ws.web3api.io', {headers: {'x-api-key':'<api_key>'}});
ws.on('open', () => {
ws.send(JSON.stringify({
jsonrpc: '2.0',
method: 'subscribe',
params: ["market:spot:order:snapshots", {"pair": "btc_usd", "exchange": "gdax"}],
id: 1,
}));
});
ws.on('message', data => {
console.log(JSON.stringify(JSON.parse(data), null, 2));
});