market:spot:ohlcv

Subscribes/Unsubscribes to market OHLCV data.

Once you're connected to this subscription: wss://ws.amberdata.com/spot, every subscription message must include an explicit pair. This is mandatory across all market types.

  • You must always specify the pair.
  • For Futures and Options, you must also include the exchange field.
  • For Spot, specifying just the pair (without the exchange) is allowed — this will return data across all exchanges that support that instrument.

See here for more details and examples.

Request

{
  "jsonrpc" : "2.0",
  "id"      : 1,
  "method"  : "subscribe",
  "params"  : [ "market:spot:ohlcv", { "pair": "btc_usd", "exchange": "gdax" } ]
}
ParamTypeDescription
pairstringThe asset pair.
exchangestringThe exchange for which to retrieve asset pairs.

Response

{
    "jsonrpc": "2.0",
    "method": "subscription",
    "params": {
        "subscription": "bff1a804-1cd6-48c7-ac7f-9e7242a3cdf3",
        "result": {
            "exchange": "gdax",
            "pair": "btc_usd",
            "timestamp": 1711570440000,
            "open": 68892.28,
            "high": 68925.5,
            "low": 68878.72,
            "close": 68904.59,
            "volume": 6.97651585
        }
    }
}
FieldTypeDescription
exchangestringThe exchange name.
pairstringThe instrument name.
timestampnumberThe timestamp associated with this record in UTC.
opennumberThe price at which the first trade occurred during the specified period.
highnumberThe highest price at which a trade took place during the period.
lownumberThe lowest price at which a trade occurred during the period.
closenumberThe price at which the last trade occurred during the specified period.
volumenumberThe total quantity traded during the period.

Example

const WebSocket = require('ws');
const ws = new WebSocket('wss://ws.amberdata.com/spot', {headers: {x-api-key:'<api_key>'}});

ws.on('open', () => {
  ws.send(JSON.stringify({
      jsonrpc: '2.0',
      method: 'subscribe',
      params: ['market:spot:ohlcv', {'pair': 'btc_usd', 'exchange': 'gdax'}],
      id: 1,
    }));
});

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