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

Commit

Permalink
refactor: converting Bitmex to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
bmancini55 committed Jun 3, 2021
1 parent 1515104 commit 4be3321
Show file tree
Hide file tree
Showing 7 changed files with 671 additions and 641 deletions.
8 changes: 7 additions & 1 deletion __tests__/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,19 @@ export type TickerOptions = {
export type TradeOptions = {
hasTradeId?: boolean;
hasSequenceId?: boolean;
tests?: (spec: any, result: any) => void;
};

export type CandleOptions = {
hasSequenceId?: boolean;
tests?: (spec: any, result: any) => void;
};

export type L2SnapshotOptions = {
hasTimestampMs?: boolean;
hasSequenceId?: boolean;
hasCount?: boolean;
tests?: (spec: any, result: any) => void;
};

export type L2UpdateOptions = {
Expand All @@ -102,15 +105,18 @@ export type L2UpdateOptions = {
hasLastSequenceId?: boolean;
hasEventMs?: boolean;
hasCount?: boolean;
tests?: (spec: any, result: any) => void;
done?: (spec: any, result: any, update: Level2Update) => boolean;
};

export type L3UpdateOptions = {
//
tests?: (spec: any, result: any) => void;
};

export type L3SnapshotOptions = {
hasTimestampMs?: boolean;
hasSequenceId?: boolean;
tests?: (spec: any, result: any) => void;
};

export type TestRunnerState = {
Expand Down
87 changes: 87 additions & 0 deletions __tests__/exchanges/BitmexClient.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { expect } from "chai";
import { testClient } from "../TestRunner";
import { BitmexClient } from "../../src/exchanges/BitmexClient";

testClient({
clientFactory: () => new BitmexClient(),
clientName: "BitMEXClient",
exchangeName: "BitMEX",
markets: [
{
id: "XBTUSD",
base: "BTC",
quote: "USD",
},
],

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: false,
hasHigh: false,
hasLow: false,
hasVolume: false,
hasQuoteVolume: false,
hasChange: false,
hasChangePercent: false,
hasAsk: true,
hasBid: true,
hasAskVolume: true,
hasBidVolume: true,
},

trade: {
hasTradeId: true,
tests: (spec, result) => {
it("trade.tradeId should be 32 hex characters", () => {
expect(result.trade.tradeId).to.match(/^[a-f0-9]{32,32}$/);
});
},
},

candle: {},

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

l2update: {
hasSnapshot: true,
hasTimestampMs: false,
hasSequenceId: false,
hasCount: false,
done: (spec, result, update) => {
const point = update.bids[0] || update.asks[0];
if (point.meta.type === "update") result.hasUpdate = true;
if (point.meta.type === "insert") result.hasInsert = true;
if (point.meta.type === "delete") result.hasDelete = true;
return result.hasUpdate && result.hasInsert && result.hasDelete;
},
tests: (spec, result) => {
it("update.bid/ask should have meta.id", () => {
const point = result.update.bids[0] || result.update.asks[0];
expect(point.meta.id).to.be.greaterThan(0);
});

it("update.bid/ask should have meta.type", () => {
const point = result.update.bids[0] || result.update.asks[0];
expect(point.meta.type).to.be.match(/update|delete|insert/);
});
},
},
});
87 changes: 0 additions & 87 deletions __tests__/exchanges/bitmex-client.spec.js

This file was deleted.

4 changes: 4 additions & 0 deletions src/Level2Update.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */

import { Level2Point } from "./Level2Point";

export class Level2Update {
public base: string;
public quote: string;
public exchange: string;
public asks: Level2Point[];
public bids: Level2Point[];

constructor(props: any) {
for (const key in props) {
Expand Down
3 changes: 2 additions & 1 deletion src/Trade.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */

export class Trade {
Expand All @@ -13,7 +14,7 @@ export class Trade {
public buyOrderId: string;
public sellOrderId: string;

constructor(props: Partial<Trade>) {
constructor(props: Partial<Trade> | any) {
this.exchange = props.exchange;
this.quote = props.quote;
this.base = props.base;
Expand Down
Loading

0 comments on commit 4be3321

Please sign in to comment.