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": "4b6x8eeho7wwpsefxed3kmly9hn276sng10ij17ob0abi65y81milof55kl71h4k",
        "result": {
            "exchange": "gdax",
            "pair": "btc_usd",
            "exchangeTimestamp": 1707247330521,
            "exchangeTimestampNanoseconds": 38000,
            "timestamp": 1707247330521,
            "bid": 43183.69,
            "ask": 43185.46,
            "mid": 43184.575,
            "last": 43185.46,
            "sequence": 72635499945,
            "lastVolume": 0.00222358,
            "bidVolume": null,
            "askVolume": null,
            "open24H": 42717.53,
            "low24H": 42270.0,
            "high24H": 43372.79
        }
    }
}
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).
timestampnumberThe timestamp.
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).
lastVolumenumberThe last volume.
bidVolumenumberBest bid volume.
askVolumenumberBest ask volume.
open24HnumberThe 24 hour open.
low24HnumberThe 24 hour low.
high24HnumberThe 24 hour high.

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));
});