Subscribes/Unsubscribes to market ticker data.
Make sure you're connected. Either the pair or exchange have to be specified - one needs to be specified, but both cannot be empty.
Note that there is a dedicated URL for this subscription: wss://ws.web3api.io/spot.
Request
{
"jsonrpc" : "2.0",
"id" : 1,
"method" : "subscribe",
"params" : [ "market:spot:tickers", { "pair": "eth_btc", "exchange": "gdax" } ]
}
Param | Type | Description |
---|---|---|
pair | string | The asset pair. |
exchange | string | The exchange for which to retrieve asset pairs. |
Response
"result": {
"exchange": "gdax",
"pair": "eth_btc",
"exchangeTimestamp": 1561495569991,
"exchangeTimestampNanoseconds": 0,
"timestamp": 1561495560000,
"bid": 0.02713,
"ask": 0.02715,
"mid": 0.02714,
"last": 0.02715,
"sequence": null
}
Field | Type | Description |
---|---|---|
exchange | string | The exchange. |
pair | string | The asset pair. |
exchangeTimestamp | number | The exchange provided timestamp at which the trade took place. |
exchangeTimestampNanoseconds | number | The exchange provided nano second part of the timestampMilliseconds (if available from exchange). |
timestamp | number | |
bid | number | The bid of the pair. |
ask | number | The ask of the pair. |
mid | number | The mid of the pair. |
last | number | The last of the pair. |
sequence | number | The sequence number (equal to null if it is not provided by the exchange). |
Example
const WebSocket = require('ws');
const ws = new WebSocket('wss://ws.web3api.io/spot', {headers: {x-api-key:'<api_key>'}});
ws.on('open', () => {
ws.send(JSON.stringify({
jsonrpc: '2.0',
method: 'subscribe',
params: ['market:spot:tickers', {'pair': 'eth_btc', 'exchange': 'gdax'}],
id: 1,
}));
});
ws.on('message', data => {
console.log(JSON.stringify(JSON.parse(data), null, 2));
});