market:spot:ohlcv

Subscribes/Unsubscribes to market OHLCV data.

Make sure you're connected to this subscription: wss://ws.amberdata.com/spot. Either the pair or exchange have to be specified - one needs to be specified, but both cannot be empty.

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

"result": {
  "exchange": "gdax",
  "pair": "btc_usd",
  "timestamp": 1552086720000,
   "open": 3937.9,
   "high": 3937.9,
   "low": 3937.9,
   "close": 3937.9,
   "volume": 1.77073469
}
FieldTypeDescription
exchangestringThe exchange.
timestampnumberThe time at which the trade took place.

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