From 95bc98a116701a0728c53217b938aa97b8259cb7 Mon Sep 17 00:00:00 2001 From: bmancini55 Date: Wed, 6 Oct 2021 16:14:08 -0400 Subject: [PATCH] coinex: remove candles support Subscription event was removed from the API. This commit removes the functionality from the CCXWS client. --- __tests__/exchanges/CoinexClient.spec.ts | 4 +- src/exchanges/CoinexClient.ts | 71 ++---------------------- 2 files changed, 5 insertions(+), 70 deletions(-) diff --git a/__tests__/exchanges/CoinexClient.spec.ts b/__tests__/exchanges/CoinexClient.spec.ts index bb51120e..5aeadc8b 100644 --- a/__tests__/exchanges/CoinexClient.spec.ts +++ b/__tests__/exchanges/CoinexClient.spec.ts @@ -34,7 +34,7 @@ testClient({ hasTickers: true, hasTrades: true, - hasCandles: true, + hasCandles: false, hasLevel2Snapshots: false, hasLevel2Updates: true, hasLevel3Snapshots: false, @@ -60,8 +60,6 @@ testClient({ hasTradeId: true, }, - candle: {}, - l2snapshot: { hasTimestampMs: false, hasSequenceId: false, diff --git a/src/exchanges/CoinexClient.ts b/src/exchanges/CoinexClient.ts index 90f27a6c..3f36de13 100644 --- a/src/exchanges/CoinexClient.ts +++ b/src/exchanges/CoinexClient.ts @@ -31,7 +31,7 @@ export class CoinexClient extends BasicMultiClient { this.options = options; this.hasTickers = true; this.hasTrades = true; - this.hasCandles = true; + this.hasCandles = false; this.hasLevel2Updates = true; this.candlePeriod = CandlePeriod._1m; } @@ -53,7 +53,7 @@ export class CoinexSingleClient extends BasicClient { super(wssPath, "Coinex", undefined, watcherMs); this.hasTickers = true; this.hasTrades = true; - this.hasCandles = true; + this.hasCandles = false; this.hasLevel2Updates = true; this.retryErrorTimeout = 15000; this._id = 0; @@ -167,26 +167,6 @@ export class CoinexSingleClient extends BasicClient { ); } - protected _sendSubCandles(remote_id) { - const id = this._id++; - this._idSubMap.set(id, { remote_id, type: SubscriptionType.trade }); - this._wss.send( - JSON.stringify({ - method: "kline.subscribe", - params: [remote_id, candlePeriod(this.candlePeriod)], - id, - }), - ); - } - - protected _sendUnsubCandles() { - this._wss.send( - JSON.stringify({ - method: "kline.unsubscribe", - }), - ); - } - protected _sendSubLevel2Updates(remote_id) { const id = this._id++; this._idSubMap.set(id, { remote_id, type: SubscriptionType.level2update }); @@ -207,6 +187,8 @@ export class CoinexSingleClient extends BasicClient { ); } + protected _sendSubCandles = NotImplementedFn; + protected _sendUnsubCandles = NotImplementedFn; protected _sendSubLevel2Snapshots = NotImplementedFn; protected _sendUnsubLevel2Snapshots = NotImplementedFn; protected _sendSubLevel3Snapshots = NotImplementedFn; @@ -252,18 +234,6 @@ export class CoinexSingleClient extends BasicClient { return; } - if (method === "kline.update") { - for (const d of params) { - const marketId = d[7]; - const market = this._candleSubs.get(marketId); - if (!market) continue; - - const candle = this._constructCandle(d); - this.emit("candle", candle, market); - } - return; - } - if (method === "depth.update") { const marketId = params[2]; const market = this._level2UpdateSubs.get(marketId); @@ -321,10 +291,6 @@ export class CoinexSingleClient extends BasicClient { }); } - protected _constructCandle(data) { - return new Candle(data[0] * 1000, data[1], data[3], data[4], data[2], data[5]); - } - protected _constructLevel2Snapshot(rawUpdate, market) { let { bids, asks } = rawUpdate, structuredBids = bids ? bids.map(([price, size]) => new Level2Point(price, size)) : [], @@ -353,32 +319,3 @@ export class CoinexSingleClient extends BasicClient { }); } } - -function candlePeriod(period) { - switch (period) { - case CandlePeriod._1m: - return 60; - case CandlePeriod._3m: - return 180; - case CandlePeriod._5m: - return 300; - case CandlePeriod._15m: - return 900; - case CandlePeriod._30m: - return 1800; - case CandlePeriod._1h: - return 3600; - case CandlePeriod._2h: - return 7200; - case CandlePeriod._4h: - return 14400; - case CandlePeriod._12h: - return 43200; - case CandlePeriod._1d: - return 86400; - case CandlePeriod._3d: - return 259200; - case CandlePeriod._1w: - return 604800; - } -}