Subscribes to Decentralized exchange market prices, optionally filtered by exchange or pair.
Make sure you're connected.
Request
All pairs:
{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["market:dex:prices"]}
Specific pair or exchange:
{
"jsonrpc":"2.0",
"id":1,
"method":"subscribe",
"params":[
"market:dex:prices",
{"exchange":"0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f"}
]
}
Param | Type | Description |
---|---|---|
exchangeid | string | The exchange address to filter by. (OPTIONAL) |
pair | string | The asset pair by which to filter. DEX pairs are most accurate using pair contract address rather than symbols (OPTIONAL) |
Response
"result": {
"delta":"-0.00608075655281506397",
"delistedPair":false,
"isNewPair":false,
"pair":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2_0xfa5047c9c78b8877af97bdcb85db743fd7313d4a",
"previousPrice":"3.57799516690081739647",
"previousTimestamp":"2021-01-29T00:35:00.000Z",
"price":"3.5719144103480023325",
"timestamp":"2021-01-29T00:38:00.000Z",
"unchangedPrice":false
}
Field | Type | Description |
---|---|---|
delistedPair | bool | true if pair has been delisted. false otherwise. |
delta | number | The dollar value change in price since last update. |
isNewPair | bool | true if pair is new. false otherwise. |
pair | string | The pair, using both base addresses of the pair underlying assets. |
previousPrice | timestamp | The price at time of last update. |
previousTimestamp | timestamp | The time of the last update. |
price | number | The quote price of the asset pair. |
timestamp | number | The time at which the price change took place. |
unchangedPrice | bool | true if price hasn't changed since last update. false otherwise. |
Example
const WebSocket = require('ws');
const ws = new WebSocket('wss://ws.web3api.io', {headers: {x-api-key:'<api_key>'}});
ws.on('open', () => {
ws.send(JSON.stringify({
jsonrpc: '2.0',
method: 'subscribe',
params: ["market:dex:prices"],
id: 1,
}));
});
ws.on('message', data => {
console.log(JSON.stringify(JSON.parse(data), null, 2));
});