market:spot:tickers

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": "btc_usdt", "exchange": "binance" } ]
}
ParamTypeDescription
pairstringThe asset pair.
exchangestringThe exchange for which to retrieve asset pairs.

Response

{
    "jsonrpc": "2.0",
    "method": "subscription",
    "params": {
        "subscription": "yy8wou3kv210an2e8aj1lnxfrq9dh2zbgbm2m1u9820qk6c45edb45qvfyzg0gki",
        "result": {
            "exchange": "binance",
            "pair": "btc_usdt",
            "exchangeTimestamp": 1690222428490,
            "exchangeTimestampNanoseconds": 3174,
            "timestamp": 1690222428490,
            "bid": 29045.97,
            "ask": 29045.98,
            "mid": 29045.975,
            "last": null,
            "sequence": 38045596942,
            "lastVolume": null,
            "bidVolume": 20.45066,
            "askVolume": 0.70154,
            "open24H": null,
            "low24H": null,
            "high24H": null
        }
    }
}
FieldTypeDescription
exchangestringThe exchange.
pairstringThe asset pair.
exchangeTimestampnumberThe exchange provided timestamp at which the trade took place.
exchangeTimestampNanosecondsnumberThe exchange provided nano second part of the exchangeTimestamp (if available from the exchange).
timestampnumber
bidnumberThe bid of the pair.
asknumberThe ask of the pair.
midnumberThe mid of the pair.
lastnumberThe last of the pair.
sequencenumberThe sequence number (equal to null if it is not provided by the exchange).
lastVolumenumber
bidVolumenumberBest bid volume.
askVolumenumberBest ask volume.

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': 'btc_usdt', 'exchange': 'binance'}],
      id: 1,
    }));
});

ws.on('message', data => {
  console.log(JSON.stringify(JSON.parse(data), null, 2));
});