market:swaps:trades

Subscribes/Unsubscribes to market swaps Trades data.

Make sure you're connected to this subscription: wss://ws.web3api.io/swaps. 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:swaps:trades",
		{
			"instrument": "BTC-USDT-SWAP",
			"exchange": "okex"
		}
	]
}
ParamTypeDescription
instrumentstringThe asset instrument.
exchangestringThe exchange for which to retrieve asset instruments.

Response

{
	"jsonrpc": "2.0",
	"method": "subscription",
	"params": {
		"result": {
			"exchange": "okex",
			"instrument": "BTC-USDT-SWAP",
			"exchangeTimestamp": 1686603878414,
			"exchangeTimestampNanoseconds": 0,
			"isBuySide": false,
			"quoteSize": null,
			"price": 25886.7,
			"size": 52,
			"tradeId": 571629883
		},
		"subscription": "843d9baca24d3563b62295de0c47a992e25589bc1717903eac3b40c640a20184"
	}
}
FieldTypeDescription
exchangestringThe exchange.
instrumentstring
exchangeTimestampnumberTimestamp that the exchange returned.
exchangeTimestampNanosecondsnumberNanoseconds part of exchangeTimestamp.
isBuySideboolean | nulltrue if the trade is a buy, false otherwise.
quoteSizenumber | null
pricenumber | nullThe price at which the instrument was traded.
sizenumber | nullThe total amount of the instrument that was traded.
tradeIdnumber | nullThe exchange provided id of the trade.

Example

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

ws.on('open', () => {
  ws.send(JSON.stringify({
      jsonrpc: '2.0',
      method: 'subscribe',
      params: ['market:swaps:trades', {'instrument': 'BTC-USDT-SWAP', 'exchange': 'okex'}],
      id: 1,
    }));
});

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