update okex oracle to api v5

This commit is contained in:
Maximilian Schneider 2022-03-21 23:02:28 +00:00
parent 207a51a150
commit 8d69dcf08a
1 changed files with 25 additions and 30 deletions

View File

@ -56,7 +56,7 @@ export abstract class PriceFeed {
}) })
conn.addEventListener("error", (e) => { conn.addEventListener("error", (e) => {
notify(`socket ${this.baseurl}: error=${e}`) notify(`socket ${this.baseurl}: error=${e} msg=${e.message}`)
}) })
conn.addEventListener("message", (msg) => { conn.addEventListener("message", (msg) => {
@ -305,53 +305,48 @@ export class Binance extends PriceFeed {
export class OKEx extends PriceFeed { export class OKEx extends PriceFeed {
protected log = log.child({ class: OKEx.name }) protected log = log.child({ class: OKEx.name })
protected baseurl = "wss://real.okex.com:8443/ws/v3" protected baseurl = "wss://ws.okx.com:8443/ws/v5/public"
parseMessage(data) { parseMessage(data) {
const message = pako.inflate(data, { raw: true, to: 'string' }); const message = JSON.parse(data);
const payload = JSON.parse(message); if (message.event) return;
// { // {
// "table":"spot/ticker", // arg: { channel: 'tickers', instId: 'BTC-USDC' },
// "data": [ // data: [
// { // {
// "last":"2819.04", // instType: 'SPOT',
// "open_24h":"2447.02", // instId: 'BTC-USDC',
// "best_bid":"2818.82", // last: '41183',
// "high_24h":"2909.68", // lastSz: '0.00015707',
// "low_24h":"2380.95", // askPx: '41194.6',
// "open_utc0":"2704.92", // askSz: '0.05353483',
// "open_utc8":"2610.12", // bidPx: '41178.1',
// "base_volume_24h":"215048.740665", // bidSz: '0.04893421',
// "quote_volume_24h":"578231392.9501", // open24h: '41323.1',
// "best_ask":"2818.83", // high24h: '41531.6',
// "instrument_id":"ETH-USDT", // low24h: '40514.1',
// "timestamp":"2021-05-26T11:46:11.826Z", // sodUtc0: '41278.8',
// "best_bid_size":"0.104506", // sodUtc8: '41236.9',
// "best_ask_size":"21.524559", // volCcy24h: '24303460.305757',
// "last_qty":"0.210619" // vol24h: '591.34824992',
// ts: '1647903202672'
// } // }
// ] // ]
// } // }
if (payload.table != "spot/ticker") { const pair = message.data[0].instId as string;
return
}
const pair = payload.data[0].instrument_id as string;
const price: IPrice = { const price: IPrice = {
source: OKEx.name, source: OKEx.name,
pair, pair,
decimals: 0, decimals: 0,
value: payload.data[0].last, value: message.data[0].last,
} }
return price return price
} }
async handleSubscribe(pair: string) { async handleSubscribe(pair: string) {
const targetPair = `spot/ticker:${pair}` const targetPair = { "channel": "tickers", "instId": `${pair}` }
this.conn.send( this.conn.send(
JSON.stringify({ JSON.stringify({
"op": "subscribe", "op": "subscribe",