Subscribes to Decentralized exchange market VWAP, optionally filtered by exchange or pair.
Make sure you're connected.
Request
All pairs:
{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["market:dex:vwap"]}
Specific pair or exchange:
{
"jsonrpc":"2.0",
"id":1,
"method":"subscribe",
"params":[
"market:dex:vwap",
{"exchange":"0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f"}
]
}
Param | Type | Description |
---|---|---|
exchange | 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":"9.40940773086296676040",
"delistedPair":false,
"isNewPair":false,
"pair":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2_0xdac17f958d2ee523a2206206994597c13d831ec7",
"previousPrice":"3730.87599831862126944094",
"previousTimestamp":"2021-12-30T21:51:00.000Z",
"price":"3740.28540604948423620134",
"vwap":"3737.07857648767941608106314093",
"timestamp":"2021-12-30T21:52: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. |
vwap | number | The VWAP value. |
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:vwap"],
id: 1,
}));
});
ws.on('message', data => {
console.log(JSON.stringify(JSON.parse(data), null, 2));
});