Subscribes/Unsubscribes to market OHLCV data.
Once you're connected to this subscription: wss://ws.amberdata.com/spot, you must provide either the instrument or exchange - one needs to be specified, both cannot be empty.
Request
{
"jsonrpc" : "2.0",
"id" : 1,
"method" : "subscribe",
"params" : [ "market:spot:ohlcv", { "pair": "btc_usd", "exchange": "gdax" } ]
}
Param | Type | Description |
---|---|---|
pair | string | The asset pair. |
exchange | string | The 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
}
}
}
Field | Type | Description |
---|---|---|
exchange | string | The exchange name. |
pair | string | The instrument name. |
timestamp | number | The timestamp associated with this record in UTC. |
open | number | The price at which the first trade occurred during the specified period. |
high | number | The highest price at which a trade took place during the period. |
low | number | The lowest price at which a trade occurred during the period. |
close | number | The price at which the last trade occurred during the specified period. |
volume | number | The 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));
});