Subscribes/Unsubscribes to market options Trades data.
Make sure you're connected to this subscription: wss://ws.web3api.io/options. Either the instrument 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:options:trades",
{
"instrument": "BTC-16JUN23-26000-P",
"exchange": "deribit"
}
]
}
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": {
"result": {
"exchange": "deribit",
"instrument": "BTC-16JUN23-26000-P",
"exchangeTimestamp": 1686602949127,
"exchangeTimestampNanoseconds": 0,
"isBuySide": false,
"quoteSize": null,
"price": 0.022,
"size": 0.4,
"tradeId": "257857355",
"tradeSequence": 993,
"tickDirection": 1,
"markPrice": 0.02177816,
"iv": 51.3,
"indexPrice": 25857.92
},
"subscription": "0194dd438a74a7ee9ed3f6df6987318ee122895077f9a1fbb269aed46fed70bb"
}
}
Field | Type | Description |
---|---|---|
exchange | string | The exchange. |
instrument | string | |
exchangeTimestamp | number | Timestamp that the exchange returned. |
exchangeTimestampNanoseconds | number | Nanoseconds part of exchangeTimestamp . |
isBuySide | boolean | null | true if the trade is a buy, false otherwise. |
quoteSize | number | null | |
price | number | null | The price at which the instrument was traded. |
size | number | null | The total amount of the instrument that was traded. |
tradeId | string | null | The exchange provided id of the trade. |
tradeSequence | number | |
tickDirection | number | |
markPrice | number | |
iv | number | The implied volatility of the instrument. |
indexPrice | number | The price of the underlying asset. |
Example
const WebSocket = require('ws');
const ws = new WebSocket('wss://ws.web3api.io/options', {headers: {x-api-key:'<api_key>'}});
ws.on('open', () => {
ws.send(JSON.stringify({
jsonrpc: '2.0',
method: 'subscribe',
params: ['market:options:trades', {'instrument': 'BTC-16JUN23-26000-P', 'exchange': 'deribit'}],
id: 1,
}));
});
ws.on('message', data => {
console.log(JSON.stringify(JSON.parse(data), null, 2));
});