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

Commit

Permalink
okex: convert to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
bmancini55 committed Jun 16, 2021
1 parent 4ca52b1 commit ba1e2b8
Show file tree
Hide file tree
Showing 5 changed files with 746 additions and 722 deletions.
130 changes: 130 additions & 0 deletions __tests__/exchanges/OKExClient.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { testClient } from "../TestRunner";
import { OKExClient } from "../../src/exchanges/OKExClient";
import { get } from "../../src/Https";

const assertions = {
hasTickers: true,
hasTrades: true,
hasCandles: true,
hasLevel2Snapshots: true,
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: true,
hasBidVolume: true,
},

trade: {
hasTradeId: true,
},

candle: {},

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

l2update: {
hasSnapshot: true,
hasTimestampMs: true,
hasSequenceId: false,
hasCount: true,
hasChecksum: true,
},
};

testClient({
clientFactory: () => new OKExClient(),
exchangeName: "OKEx",
clientName: "OKExClient - Spot",
markets: [
{
id: "BTC-USDT",
base: "BTC",
quote: "USDT",
},
{
id: "ETH-BTC",
base: "ETH",
quote: "BTC",
},
],

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

...assertions,
});

testClient({
clientFactory: () => new OKExClient(),
exchangeName: "OKEx",
clientName: "OKExClient - Futures",
fetchMarkets: async () => {
const results: any = await get("https://www.okex.com/api/futures/v3/instruments");
return results
.filter(p => p.base_currency === "BTC")
.map(p => ({
id: p.instrument_id,
base: p.base_currency,
quote: p.quote_currency,
type: "futures",
}));
},
...assertions,
});

testClient({
clientFactory: () => new OKExClient(),
exchangeName: "OKEx",
clientName: "OKExClient - Swap",
fetchMarkets: async () => {
const results: any = await get("https://www.okex.com/api/swap/v3/instruments");
return results
.filter(p => ["BTC", "ETH", "LTC"].includes(p.base_currency))
.map(p => ({
id: p.instrument_id,
base: p.base_currency,
quote: p.quote_currency,
type: "swap",
}));
},
...assertions,
});

testClient({
clientFactory: () => new OKExClient(),
exchangeName: "OKEx",
clientName: "OKExClient - Options",
fetchMarkets: async () => {
const results: any = await get("https://www.okex.com/api/option/v3/instruments/BTC-USD");
return results
.map(p => ({
id: p.instrument_id,
base: p.base_currency,
quote: p.quote_currency,
type: "option",
}))
.filter(p => p.id.endsWith("-C"))
.slice(0, 20);
},
...assertions,
});
130 changes: 0 additions & 130 deletions __tests__/exchanges/okex-client.spec.js

This file was deleted.

1 change: 1 addition & 0 deletions src/Market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export type Market = {
id: string;
base: string;
quote: string;
type?: string;
};
Loading

0 comments on commit ba1e2b8

Please sign in to comment.