Subscribes to reference quotes.
The calculation takes into account mid prices from every exchange, with a maximum lookback of 1 minute, meaning if a pair for an exchange has not been updated in the most recent 60 seconds, it is dropped and not used in the calculation of the current price.
The reference quote is calculated as the average of mid prices across all exchanges which support this pair.
Mid is defined as (bid + ask) / 2 (best bid and best ask).
This feed returns point-in-time data, meaning it returns real-time data, and is not retroactively changed after the fact due to some reconciliation phase or some delayed data for example.
Make sure you're connected to this subscription: wss://ws.web3api.io/quotes.
Specifying Select Exchanges
Use the sources parameter to include only specific exchanges in the calculation.
Request
Default feed:
{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["market:spot:reference-quote:1s",{"pair":"btc_usdt"}]}
Choose the exchanges participating in the price calculation:
{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["market:spot:reference-quote:1s",{"pair":"btc_usdt", "sources":"binance,huobi"}]}
Param | Type | Description |
---|---|---|
pair | string | The asset pair for which to retrieve the price feed. |
sources | array | Inclusion list - only exchanges in this list will be included in the calculation of the price |
includeSources | boolean | If true, the exchanges which participated in the calculation (ie the sources) are included in the response |
Response
{
"jsonrpc": "2.0",
"method": "subscription",
"params": {
"subscription": "o6nfltawcqheikl3yu7oc1t4cxtf7vyde7fwrs93q4n2wowgk7jsv6kko1bqyc5j",
"result": {
"timestamp": 1712238204794,
"timestampNanoseconds": 801060,
"pair": "btc_usdt",
"price": 67412.15166666669,
"sources": [
"mexc",
"kraken",
"gemini",
"poloniex",
"bitfinex",
"gdax",
"bitstamp",
"huobi",
"binanceus",
"okex",
"bybit",
"binance"
]
}
}
}
Field | Type | Description |
---|---|---|
pair | string | The pair. |
price | number | The quote price of the asset pair. |
timestamp | number | The time at which the price change took place. |
timestampNanoseconds | number | The nanosecond portion of the timestamp |
sources | array | List of exchanges which participated in the calculation of this price point. |
Example
const WebSocket = require('ws');
const ws = new WebSocket('wss://ws.web3api.io/quotes', {headers: {x-api-key:'<api_key>'}});
ws.on('open', () => {
ws.send(JSON.stringify({
jsonrpc: '2.0',
method: 'subscribe',
params: ["market:spot:reference-quote:1s", { "pair": "btc_usdt"}],
id: 1,
}));
});
ws.on('message', data => {
console.log(JSON.stringify(JSON.parse(data), null, 2));
});