Subscribes/Unsubscribes to market futures OHLCV data.
Once you're connected to this subscription: wss://ws.amberdata.com/futures, 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:futures:ohlcv", { "instrument": "XRPUSDT", "exchange": "binance"} ]
}
Param | Type | Description |
---|---|---|
instrument | string | The asset instrument. |
exchange | string | The exchange for which to retrieve asset instruments. |
Response
{
"jsonrpc": "2.0",
"method": "subscription",
"params": {
"subscription": "c17c567a-6bd0-4335-85ed-61197c845f3f",
"result": {
"exchange": "binance",
"instrument": "ADAUSD_PERP",
"timestamp": 1711570860000,
"open": 0.6478,
"high": 0.6478,
"low": 0.6476,
"close": 0.6476,
"volume": 4075.73706105
}
}
}
Field | Type | Description |
---|---|---|
exchange | string | The exchange name. |
instrument | 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/futures', {headers: {x-api-key:'<api_key>'}});
ws.on('open', () => {
ws.send(JSON.stringify({
jsonrpc: '2.0',
method: 'subscribe',
params: ['market:futures:ohlcv', {'instrument': 'XRPUSDT', 'exchange': 'binance'}],
id: 1,
}));
});
ws.on('message', data => {
console.log(JSON.stringify(JSON.parse(data), null, 2));
});