Subscribes to market prices updates, optionally filtered by pair.
Make sure you're connected to this subscription: wss://ws.web3api.io.
Request
All pairs:
{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["market:spot:prices:updates"]}
Specific pair
or pair & exchange
:
{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["market:spot:prices:updates",{"pair":"btc_usdt"}]}
Param | Type | Description |
---|---|---|
pair | string | The asset pair by which to filter. |
Response
{
"jsonrpc": "2.0",
"method": "subscription",
"params": {
"result": {
"delistedPair": false,
"delta": "-4.8437252449679828865397170717",
"isNewPair": false,
"pair": "btc_usdt",
"previousPrice": "67289.46636745258833937719",
"previousTimestamp": 1712237940000,
"price": "67284.6226422076203564906502829283",
"timestamp": 1712238000000,
"unchangedPrice": false
},
"subscription": "a931528473328abe28708cbe90f4183bff898dd213fe0ef7c2e7747b71b5d615"
}
}
Field | Type | Description |
---|---|---|
delistedPair | bool | true if pair has been delisted. false otherwise. |
delta | The dollar value change in price since last update. | |
isNewPair | bool | true if pair is new. false otherwise. |
pair | string | The pair. |
previousPrice | The price at time of last update. | |
previousTimestamp | The time of the last update. | |
price | number | The quote price of the asset pair. |
timestamp | number | The time at which the price change took place. |
unchangedPrice | bool | true if price hasn't changed since last update. false otherwise. |
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:prices:updates",{ "pair": "ltc_usdt"}],
id: 1,
}));
});
ws.on('message', data => {
console.log(JSON.stringify(JSON.parse(data), null, 2));
});