Subscribes/Unsubscribes to market ticker data.
Important Update: WebSocket Endpoint Migration
We are excited to announce an upgrade to our WebSocket service! To ensure that our users enjoy enhanced reliability and performance, we have migrated our WebSocket endpoint. Please update your applications to connect to the new endpoint as described here:
- ❌ Old Endpoint:
wss://ws.web3api.io/
- ✅ New Endpoint:
wss://ws.amberdata.com/spot
Action Required
Users are required to update the endpoint URL in their applications. The good news is that the response JSON schemas remain unchanged, so you can expect a seamless transition with minimal adjustments needed on your end.
Support
We understand that changes like these can raise questions. Our support team is here to assist with any issues or concerns you may have during this migration process. Please don’t hesitate to contact us for support at: [email protected].
We appreciate your prompt action to migrate to the new WebSocket endpoint.
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:tickers", { "pair": "btc_usdt", "exchange": "binance" } ]
}
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": "ac936208-0c53-4c0a-9bc4-63188a61eb7e",
"result": {
"exchange": "binance",
"pair": "btc_usdt",
"exchangeTimestamp": 1712238263524,
"exchangeTimestampNanoseconds": 780195,
"timestamp": 1712238263524,
"bid": 67427.98,
"ask": 67427.99,
"mid": 67427.985,
"last": null,
"sequence": 45375530797,
"lastVolume": null,
"bidVolume": 3.25905,
"askVolume": 2.17779,
"open24H": null,
"low24H": null,
"high24H": null
}
}
}
Field | Type | Description |
---|---|---|
exchange | string | The exchange. |
pair | string | The asset pair. |
exchangeTimestamp | number | The exchange provided timestamp at which the trade took place. |
exchangeTimestampNanoseconds | number | The exchange provided nano second part of the exchangeTimestamp (if available from the exchange). |
timestamp | number | The timestamp. |
bid | number | The bid of the pair. |
ask | number | The ask of the pair. |
mid | number | The mid of the pair. |
last | number | The last of the pair. |
sequence | number | The sequence number (equal to null if it is not provided by the exchange). |
lastVolume | number | The last volume. |
bidVolume | number | Best bid volume. |
askVolume | number | Best ask volume. |
open24H | number | The 24 hour open. |
low24H | number | The 24 hour low. |
high24H | number | The 24 hour high. |
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:tickers', {'pair': 'btc_usdt', 'exchange': 'binance'}],
id: 1,
}));
});
ws.on('message', data => {
console.log(JSON.stringify(JSON.parse(data), null, 2));
});