Subscribes to new market prices, 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"]}
Specific pair
or pair & exchange
:
{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["market:spot:prices",{ "pair": "ltc_usdt"}]}
Param | Type | Description |
---|---|---|
pair | string | The asset pair by which to filter. |
Response
{
"jsonrpc": "2.0",
"method": "subscription",
"params": {
"result": {
"pair": "akt_eur",
"price": "3.93400000000000000000",
"timestamp": 1712237820000
},
"subscription": "ed372faab21477c26eeedec5980c1e2a318ff2c58d0e0926dde94b6afa7e8e27"
}
}
Field | Type | Description |
---|---|---|
pair | string | The pair. |
price | number | The quote price of the asset pair. |
timestamp | number | The time at which the price change took place. |
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",{ "pair": "ltc_usdt"}],
id: 1,
}));
});
ws.on('message', data => {
console.log(JSON.stringify(JSON.parse(data), null, 2));
});