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