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

Commit

Permalink
kucoin: convert to TS, disable L3updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bmancini55 committed Jun 16, 2021
1 parent 0b4bc14 commit 6fcf86c
Show file tree
Hide file tree
Showing 6 changed files with 1,032 additions and 985 deletions.
150 changes: 150 additions & 0 deletions __tests__/exchanges/KucoinClient.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import { expect } from "chai";
import { KucoinClient } from "../../src/exchanges/KucoinClient";
import { testClient } from "../TestRunner";

testClient({
clientFactory: () => new KucoinClient(),
clientName: "KucoinClient",
exchangeName: "KuCoin",
markets: [
{
id: "BTC-USDT",
base: "BTC",
quote: "USDT",
},
],

testConnectEvents: true,
testDisconnectEvents: true,
testReconnectionEvents: true,
testCloseEvents: true,

hasTickers: true,
hasTrades: true,
hasCandles: true,
hasLevel2Snapshots: false,
hasLevel2Updates: true,
hasLevel3Snapshots: false,
hasLevel3Updates: false,

ticker: {
hasTimestamp: true,
hasLast: true,
hasOpen: true,
hasHigh: true,
hasLow: true,
hasVolume: true,
hasQuoteVolume: false,
hasChange: true,
hasChangePercent: true,
hasAsk: true,
hasBid: true,
hasAskVolume: false,
hasBidVolume: false,
},

trade: {
hasTradeId: true,
tradeIdPattern: /\w{24,}/,
},

candle: {},

l2snapshot: {
hasTimestampMs: false,
hasSequenceId: true,
hasCount: false,
},

l2update: {
hasSnapshot: true,
hasTimestampMs: false,
hasSequenceId: true,
hasLastSequenceId: true,
hasCount: false,
},

l3update: {
hasSnapshot: true,
hasTimestampMs: true,
hasSequenceId: true,
orderIdPattern: /^[a-f0-9]{24,24}$/,
done: (spec, result, update) => {
const point = update.asks[0] || update.bids[0];

switch (point.meta.type) {
case "received":
if (!result.hasReceived) {
result.hasReceived = true;
expect(update.sequenceId).to.be.greaterThan(0);
expect(update.timestampMs).to.be.greaterThan(1597679523725);
expect(point.orderId).to.match(/^[a-f0-9]{24,24}/);
expect(point.price).to.equal("0");
expect(point.size).to.equal("0");
expect(point.meta.ts).to.match(/[0-9]{19,}/);
}
break;
case "open":
if (!result.hasOpen) {
result.hasOpen = true;
expect(update.sequenceId).to.be.greaterThan(0);
expect(update.timestampMs).to.be.greaterThan(1597679523725);
expect(point.orderId).to.match(/^[a-f0-9]{24,24}/);
expect(Number(point.price)).to.be.greaterThan(0);
expect(Number(point.size)).to.be.greaterThan(0);
expect(point.meta.ts).to.match(/[0-9]{19,}/);
expect(point.meta.orderTime).to.match(/[0-9]{19,}/);
}
break;
case "done":
if (!result.hasDone) {
result.hasDone = true;
expect(update.sequenceId).to.be.greaterThan(0);
expect(update.timestampMs).to.be.greaterThan(1597679523725);
expect(point.orderId).to.match(/^[a-f0-9]{24,24}/);
expect(point.price).to.equal("0");
expect(point.size).to.equal("0");
expect(point.meta.ts).to.match(/[0-9]{19,}/);
expect(point.meta.reason).to.match(/filled|canceled/);
}
break;
case "match":
if (!result.hasMatch) {
result.hasMatch = true;
expect(update.sequenceId).to.be.greaterThan(0);
expect(update.timestampMs).to.be.greaterThan(1597679523725);
expect(point.orderId).to.match(/^[a-f0-9]{24,24}/);
expect(point.price).to.equal("0");
expect(Number(point.size)).to.be.gte(0);
expect(point.meta.ts).to.match(/[0-9]{19,}/);
expect(point.meta.remainSize).to.not.be.undefined;
expect(point.meta.takerOrderId).to.not.be.undefined;
expect(point.meta.makerOrderId).to.not.be.undefined;
expect(point.meta.tradeId).to.not.be.undefined;
expect(Number((point as any).tradePrice)).to.be.gte(0);
expect(Number((point as any).tradeSize)).to.be.gte(0);
}

break;
case "update":
if (!result.hasUpdate) {
result.hasUpdate = true;
expect(update.sequenceId).to.be.gt(0);
expect(update.timestampMs).to.be.gt(1597679523725);
expect(point.orderId).to.match(/^[a-f0-9]{24,24}/);
expect(point.price).to.equal("0");
expect(Number(point.size)).to.be.gte(0);
expect(point.meta.ts).to.match(/[0-9]{19,}/);
}

break;
}
return result.hasReceived && result.hasOpen && result.hasDone && result.hasMatch;
},
},

l3snapshot: {
hasTimestampMs: true,
hasSequenceId: true,
},
});
150 changes: 0 additions & 150 deletions __tests__/exchanges/kucoin-client.spec.js

This file was deleted.

2 changes: 2 additions & 0 deletions src/Level2Update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export class Level2Update {
public base: string;
public quote: string;
public exchange: string;
public sequenceId: number;
public timestampMs: number;
public asks: Level2Point[];
public bids: Level2Point[];

Expand Down
2 changes: 2 additions & 0 deletions src/Level3Update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export class Level3Update {
public exchange: string;
public base: string;
public quote: string;
public sequenceId: number;
public timestampMs: number;
public asks: Level3Point[];
public bids: Level3Point[];

Expand Down
Loading

0 comments on commit 6fcf86c

Please sign in to comment.