Skip to content
This repository has been archived by the owner on Sep 9, 2023. It is now read-only.

Commit

Permalink
coinex: remove candles support
Browse files Browse the repository at this point in the history
Subscription event was removed from the API. This commit removes the
functionality from the CCXWS client.
  • Loading branch information
bmancini55 committed Oct 6, 2021
1 parent aff3a29 commit 95bc98a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 70 deletions.
4 changes: 1 addition & 3 deletions __tests__/exchanges/CoinexClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ testClient({

hasTickers: true,
hasTrades: true,
hasCandles: true,
hasCandles: false,
hasLevel2Snapshots: false,
hasLevel2Updates: true,
hasLevel3Snapshots: false,
Expand All @@ -60,8 +60,6 @@ testClient({
hasTradeId: true,
},

candle: {},

l2snapshot: {
hasTimestampMs: false,
hasSequenceId: false,
Expand Down
71 changes: 4 additions & 67 deletions src/exchanges/CoinexClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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 });
Expand All @@ -207,6 +187,8 @@ export class CoinexSingleClient extends BasicClient {
);
}

protected _sendSubCandles = NotImplementedFn;
protected _sendUnsubCandles = NotImplementedFn;
protected _sendSubLevel2Snapshots = NotImplementedFn;
protected _sendUnsubLevel2Snapshots = NotImplementedFn;
protected _sendSubLevel3Snapshots = NotImplementedFn;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)) : [],
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 95bc98a

Please sign in to comment.