diff --git a/package.json b/package.json index 3d8cde2c..0236c70a 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,8 @@ "license": "MIT", "main": "src/index.js", "scripts": { - "test": "jest --testEnvironment=node --testRunner=jest-circus/runner --coverage", - "test:ci": "jest --testEnvironment=node --testRunner=jest-circus/runner --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" + "test": "jest --testEnvironment=node --testRunner=jest-circus/runner --coverage --testPathPattern=src\/.+\\.spec\\.js --maxWorkers=32", + "test:ci": "jest --testEnvironment=node --testRunner=jest-circus/runner --coverage --testPathPattern=src\/.+\\.spec\\.js --maxWorkers=32 && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" }, "repository": "altangent/ccxws", "dependencies": { diff --git a/src/exchanges/binance-client.spec.js b/src/exchanges/binance-client.spec.js index 9a866d63..ab441d88 100644 --- a/src/exchanges/binance-client.spec.js +++ b/src/exchanges/binance-client.spec.js @@ -9,69 +9,68 @@ let market = { quote: "BTC", }; -beforeAll(() => { - client = new Binance(); -}); +describe("BinanceClient", () => { + beforeAll(() => { + client = new Binance(); + }); -test("it should support tickers", () => { - expect(client.hasTickers).toBeTruthy(); -}); + test("it should support tickers", () => { + expect(client.hasTickers).toBeTruthy(); + }); -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeTruthy(); -}); + test("it should support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeTruthy(); + }); -test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeTruthy(); -}); + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeTruthy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); -test("it should not support level3 updates", () => { - expect(client.hasLevel3Updates).toBeFalsy(); -}); + test("it should not support level3 updates", () => { + expect(client.hasLevel3Updates).toBeFalsy(); + }); -test("should subscribe and emit ticker events", done => { - client.subscribeTicker(market); - client.on("ticker", ticker => { - expect(ticker.fullId).toMatch("Binance:ETH/BTC"); - expect(ticker.timestamp).toBeGreaterThan(1531677480465); - expect(typeof ticker.last).toBe("string"); - expect(typeof ticker.open).toBe("string"); - expect(typeof ticker.high).toBe("string"); - expect(typeof ticker.low).toBe("string"); - expect(typeof ticker.volume).toBe("string"); - expect(typeof ticker.change).toBe("string"); - expect(typeof ticker.changePercent).toBe("string"); - expect(typeof ticker.bid).toBe("string"); - expect(typeof ticker.bidVolume).toBe("string"); - expect(typeof ticker.ask).toBe("string"); - expect(typeof ticker.askVolume).toBe("string"); - expect(parseFloat(ticker.last)).toBeGreaterThan(0); - expect(parseFloat(ticker.open)).toBeGreaterThan(0); - expect(parseFloat(ticker.high)).toBeGreaterThan(0); - expect(parseFloat(ticker.low)).toBeGreaterThan(0); - expect(parseFloat(ticker.volume)).toBeGreaterThan(0); - expect(parseFloat(ticker.quoteVolume)).toBeGreaterThan(0); - expect(isNaN(parseFloat(ticker.change))).toBeFalsy(); - expect(isNaN(parseFloat(ticker.changePercent))).toBeFalsy(); - expect(parseFloat(ticker.bid)).toBeGreaterThan(0); - expect(parseFloat(ticker.bidVolume)).toBeGreaterThan(0); - expect(parseFloat(ticker.ask)).toBeGreaterThan(0); - expect(parseFloat(ticker.askVolume)).toBeGreaterThan(0); - done(); + test("should subscribe and emit ticker events", done => { + client.subscribeTicker(market); + client.on("ticker", ticker => { + expect(ticker.fullId).toMatch("Binance:ETH/BTC"); + expect(ticker.timestamp).toBeGreaterThan(1531677480465); + expect(typeof ticker.last).toBe("string"); + expect(typeof ticker.open).toBe("string"); + expect(typeof ticker.high).toBe("string"); + expect(typeof ticker.low).toBe("string"); + expect(typeof ticker.volume).toBe("string"); + expect(typeof ticker.change).toBe("string"); + expect(typeof ticker.changePercent).toBe("string"); + expect(typeof ticker.bid).toBe("string"); + expect(typeof ticker.bidVolume).toBe("string"); + expect(typeof ticker.ask).toBe("string"); + expect(typeof ticker.askVolume).toBe("string"); + expect(parseFloat(ticker.last)).toBeGreaterThan(0); + expect(parseFloat(ticker.open)).toBeGreaterThan(0); + expect(parseFloat(ticker.high)).toBeGreaterThan(0); + expect(parseFloat(ticker.low)).toBeGreaterThan(0); + expect(parseFloat(ticker.volume)).toBeGreaterThan(0); + expect(parseFloat(ticker.quoteVolume)).toBeGreaterThan(0); + expect(isNaN(parseFloat(ticker.change))).toBeFalsy(); + expect(isNaN(parseFloat(ticker.changePercent))).toBeFalsy(); + expect(parseFloat(ticker.bid)).toBeGreaterThan(0); + expect(parseFloat(ticker.bidVolume)).toBeGreaterThan(0); + expect(parseFloat(ticker.ask)).toBeGreaterThan(0); + expect(parseFloat(ticker.askVolume)).toBeGreaterThan(0); + done(); + }); }); -}); -test( - "should subscribe and emit trade events", - done => { + test("should subscribe and emit trade events", done => { client.subscribeTrades(market); client.on("trade", trade => { expect(trade.fullId).toMatch("Binance:ETH/BTC"); @@ -87,86 +86,85 @@ test( expect(parseFloat(trade.amount)).toBeGreaterThan(0); done(); }); - }, - 30000 -); - -test("should subscribe and emit level2 updates", done => { - let hasSnapshot = false; - let hasUpdates = false; - client.subscribeLevel2Updates(market); - client.on("l2snapshot", snapshot => { - hasSnapshot = true; - expect(snapshot.fullId).toMatch("Binance:ETH/BTC"); - expect(snapshot.exchange).toMatch("Binance"); - expect(snapshot.base).toMatch("ETH"); - expect(snapshot.quote).toMatch("BTC"); - expect(snapshot.sequenceId).toBeGreaterThan(0); - expect(snapshot.timestampMs).toBeUndefined(); - expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.asks[0].count).toBeUndefined(); - expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.bids[0].count).toBeUndefined(); - if (hasSnapshot && hasUpdates) done(); - }); - client.on("l2update", update => { - hasUpdates = true; - expect(update.fullId).toMatch("Binance:ETH/BTC"); - expect(update.exchange).toMatch("Binance"); - expect(update.base).toMatch("ETH"); - expect(update.quote).toMatch("BTC"); - expect(update.sequenceId).toBeGreaterThan(0); - expect(update.lastSequenceId).toBeGreaterThanOrEqual(update.sequenceId); - if (update.asks.length) { - expect(parseFloat(update.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(update.asks[0].size)).toBeGreaterThanOrEqual(0); - } - if (update.bids.length) { - expect(parseFloat(update.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(update.bids[0].size)).toBeGreaterThanOrEqual(0); - } - if (hasSnapshot && hasUpdates) done(); + }, 30000); + + test("should subscribe and emit level2 updates", done => { + let hasSnapshot = false; + let hasUpdates = false; + client.subscribeLevel2Updates(market); + client.on("l2snapshot", snapshot => { + hasSnapshot = true; + expect(snapshot.fullId).toMatch("Binance:ETH/BTC"); + expect(snapshot.exchange).toMatch("Binance"); + expect(snapshot.base).toMatch("ETH"); + expect(snapshot.quote).toMatch("BTC"); + expect(snapshot.sequenceId).toBeGreaterThan(0); + expect(snapshot.timestampMs).toBeUndefined(); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.asks[0].count).toBeUndefined(); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.bids[0].count).toBeUndefined(); + if (hasSnapshot && hasUpdates) done(); + }); + client.on("l2update", update => { + hasUpdates = true; + expect(update.fullId).toMatch("Binance:ETH/BTC"); + expect(update.exchange).toMatch("Binance"); + expect(update.base).toMatch("ETH"); + expect(update.quote).toMatch("BTC"); + expect(update.sequenceId).toBeGreaterThan(0); + expect(update.lastSequenceId).toBeGreaterThanOrEqual(update.sequenceId); + if (update.asks.length) { + expect(parseFloat(update.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(update.asks[0].size)).toBeGreaterThanOrEqual(0); + } + if (update.bids.length) { + expect(parseFloat(update.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(update.bids[0].size)).toBeGreaterThanOrEqual(0); + } + if (hasSnapshot && hasUpdates) done(); + }); }); -}); -test("should subscribe and emit level2 snapshots", done => { - client.subscribeLevel2Snapshots(market); - client.on("l2snapshot", snapshot => { - expect(snapshot.fullId).toMatch("Binance:ETH/BTC"); - expect(snapshot.exchange).toMatch("Binance"); - expect(snapshot.base).toMatch("ETH"); - expect(snapshot.quote).toMatch("BTC"); - expect(snapshot.sequenceId).toBeGreaterThan(0); - expect(snapshot.timestampMs).toBeUndefined(); - expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.asks[0].count).toBeUndefined(); - expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.bids[0].count).toBeUndefined(); - done(); + test("should subscribe and emit level2 snapshots", done => { + client.subscribeLevel2Snapshots(market); + client.on("l2snapshot", snapshot => { + expect(snapshot.fullId).toMatch("Binance:ETH/BTC"); + expect(snapshot.exchange).toMatch("Binance"); + expect(snapshot.base).toMatch("ETH"); + expect(snapshot.quote).toMatch("BTC"); + expect(snapshot.sequenceId).toBeGreaterThan(0); + expect(snapshot.timestampMs).toBeUndefined(); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.asks[0].count).toBeUndefined(); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.bids[0].count).toBeUndefined(); + done(); + }); }); -}); -test("should unsubscribe from tickers", () => { - client.unsubscribeTicker(market); -}); + test("should unsubscribe from tickers", () => { + client.unsubscribeTicker(market); + }); -test("should unsubscribe from trades", () => { - client.unsubscribeTrades(market); -}); + test("should unsubscribe from trades", () => { + client.unsubscribeTrades(market); + }); -test("should unsubscribe from level2 snapshots", () => { - client.unsubscribeLevel2Snapshots(market); -}); + test("should unsubscribe from level2 snapshots", () => { + client.unsubscribeLevel2Snapshots(market); + }); -test("should unsubscribe from level2 updates", () => { - client.unsubscribeLevel2Updates(market); -}); + test("should unsubscribe from level2 updates", () => { + client.unsubscribeLevel2Updates(market); + }); -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/bitfinex-client.spec.js b/src/exchanges/bitfinex-client.spec.js index e843da0b..3a149a36 100644 --- a/src/exchanges/bitfinex-client.spec.js +++ b/src/exchanges/bitfinex-client.spec.js @@ -9,69 +9,68 @@ let market = { quote: "USD", }; -beforeAll(() => { - client = new Bitfinex(); -}); +describe("BitfinexClient", () => { + beforeAll(() => { + client = new Bitfinex(); + }); -test("it should support tickers", () => { - expect(client.hasTickers).toBeTruthy(); -}); + test("it should support tickers", () => { + expect(client.hasTickers).toBeTruthy(); + }); -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should not support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeFalsy(); -}); + test("it should not support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeFalsy(); + }); -test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeTruthy(); -}); + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeTruthy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); -test("it should support level3 updates", () => { - expect(client.hasLevel3Updates).toBeTruthy(); -}); + test("it should support level3 updates", () => { + expect(client.hasLevel3Updates).toBeTruthy(); + }); -test("should subscribe and emit ticker events", done => { - client.subscribeTicker(market); - client.on("ticker", ticker => { - expect(ticker.fullId).toMatch("Bitfinex:BTC/USD"); - expect(ticker.timestamp).toBeGreaterThan(1531677480465); - expect(typeof ticker.last).toBe("string"); - expect(typeof ticker.open).toBe("string"); - expect(typeof ticker.high).toBe("string"); - expect(typeof ticker.low).toBe("string"); - expect(typeof ticker.volume).toBe("string"); - expect(typeof ticker.change).toBe("string"); - expect(typeof ticker.changePercent).toBe("string"); - expect(typeof ticker.bid).toBe("string"); - expect(typeof ticker.bidVolume).toBe("string"); - expect(typeof ticker.ask).toBe("string"); - expect(typeof ticker.askVolume).toBe("string"); - expect(parseFloat(ticker.last)).toBeGreaterThan(0); - expect(parseFloat(ticker.open)).toBeGreaterThan(0); - expect(parseFloat(ticker.high)).toBeGreaterThan(0); - expect(parseFloat(ticker.low)).toBeGreaterThan(0); - expect(parseFloat(ticker.volume)).toBeGreaterThan(0); - expect(ticker.quoteVolume).toBeUndefined(); - expect(isNaN(parseFloat(ticker.change))).toBeFalsy(); - expect(isNaN(parseFloat(ticker.changePercent))).toBeFalsy(); - expect(parseFloat(ticker.bid)).toBeGreaterThan(0); - expect(parseFloat(ticker.bidVolume)).toBeGreaterThan(0); - expect(parseFloat(ticker.ask)).toBeGreaterThan(0); - expect(parseFloat(ticker.askVolume)).toBeGreaterThan(0); - done(); + test("should subscribe and emit ticker events", done => { + client.subscribeTicker(market); + client.on("ticker", ticker => { + expect(ticker.fullId).toMatch("Bitfinex:BTC/USD"); + expect(ticker.timestamp).toBeGreaterThan(1531677480465); + expect(typeof ticker.last).toBe("string"); + expect(typeof ticker.open).toBe("string"); + expect(typeof ticker.high).toBe("string"); + expect(typeof ticker.low).toBe("string"); + expect(typeof ticker.volume).toBe("string"); + expect(typeof ticker.change).toBe("string"); + expect(typeof ticker.changePercent).toBe("string"); + expect(typeof ticker.bid).toBe("string"); + expect(typeof ticker.bidVolume).toBe("string"); + expect(typeof ticker.ask).toBe("string"); + expect(typeof ticker.askVolume).toBe("string"); + expect(parseFloat(ticker.last)).toBeGreaterThan(0); + expect(parseFloat(ticker.open)).toBeGreaterThan(0); + expect(parseFloat(ticker.high)).toBeGreaterThan(0); + expect(parseFloat(ticker.low)).toBeGreaterThan(0); + expect(parseFloat(ticker.volume)).toBeGreaterThan(0); + expect(ticker.quoteVolume).toBeUndefined(); + expect(isNaN(parseFloat(ticker.change))).toBeFalsy(); + expect(isNaN(parseFloat(ticker.changePercent))).toBeFalsy(); + expect(parseFloat(ticker.bid)).toBeGreaterThan(0); + expect(parseFloat(ticker.bidVolume)).toBeGreaterThan(0); + expect(parseFloat(ticker.ask)).toBeGreaterThan(0); + expect(parseFloat(ticker.askVolume)).toBeGreaterThan(0); + done(); + }); }); -}); -test( - "should subscribe and emit trade events", - done => { + test("should subscribe and emit trade events", done => { client.subscribeTrades(market); client.on("trade", trade => { expect(trade.fullId).toMatch("Bitfinex:BTC/USD"); @@ -87,95 +86,94 @@ test( expect(parseFloat(trade.amount)).toBeGreaterThan(0); done(); }); - }, - 30000 -); - -test("should subscribe and emit level2 snapshot and updates", done => { - let hasSnapshot = false; - client.subscribeLevel2Updates(market); - client.on("l2snapshot", snapshot => { - hasSnapshot = true; - expect(snapshot.fullId).toMatch("Bitfinex:BTC/USD"); - expect(snapshot.exchange).toMatch("Bitfinex"); - expect(snapshot.base).toMatch("BTC"); - expect(snapshot.quote).toMatch("USD"); - expect(snapshot.sequenceId).toBeUndefined(); - expect(snapshot.timestampMs).toBeUndefined(); - expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].count)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].count)).toBeGreaterThanOrEqual(0); - }); - client.on("l2update", update => { - expect(hasSnapshot).toBeTruthy(); - expect(update.fullId).toMatch("Bitfinex:BTC/USD"); - expect(update.exchange).toMatch("Bitfinex"); - expect(update.base).toMatch("BTC"); - expect(update.quote).toMatch("USD"); - expect(update.sequenceId).toBeUndefined(); - expect(update.timestampMs).toBeUndefined(); - let point = update.asks[0] || update.bids[0]; - expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.count)).toBeGreaterThanOrEqual(0); - done(); + }, 30000); + + test("should subscribe and emit level2 snapshot and updates", done => { + let hasSnapshot = false; + client.subscribeLevel2Updates(market); + client.on("l2snapshot", snapshot => { + hasSnapshot = true; + expect(snapshot.fullId).toMatch("Bitfinex:BTC/USD"); + expect(snapshot.exchange).toMatch("Bitfinex"); + expect(snapshot.base).toMatch("BTC"); + expect(snapshot.quote).toMatch("USD"); + expect(snapshot.sequenceId).toBeUndefined(); + expect(snapshot.timestampMs).toBeUndefined(); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].count)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].count)).toBeGreaterThanOrEqual(0); + }); + client.on("l2update", update => { + expect(hasSnapshot).toBeTruthy(); + expect(update.fullId).toMatch("Bitfinex:BTC/USD"); + expect(update.exchange).toMatch("Bitfinex"); + expect(update.base).toMatch("BTC"); + expect(update.quote).toMatch("USD"); + expect(update.sequenceId).toBeUndefined(); + expect(update.timestampMs).toBeUndefined(); + let point = update.asks[0] || update.bids[0]; + expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.count)).toBeGreaterThanOrEqual(0); + done(); + }); }); -}); -test("should subscribe and emit level3 snapshot and updates", done => { - let hasSnapshot = false; - client.subscribeLevel3Updates(market); - client.on("l3snapshot", snapshot => { - hasSnapshot = true; - expect(snapshot.fullId).toMatch("Bitfinex:BTC/USD"); - expect(snapshot.exchange).toMatch("Bitfinex"); - expect(snapshot.base).toMatch("BTC"); - expect(snapshot.quote).toMatch("USD"); - expect(snapshot.sequenceId).toBeUndefined(); - expect(snapshot.timestampMs).toBeUndefined(); - expect(snapshot.asks[0].orderId).toBeGreaterThan(0); - expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.bids[0].orderId).toBeGreaterThan(0); - expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); - }); - client.on("l3update", update => { - expect(hasSnapshot).toBeTruthy(); - expect(update.fullId).toMatch("Bitfinex:BTC/USD"); - expect(update.exchange).toMatch("Bitfinex"); - expect(update.base).toMatch("BTC"); - expect(update.quote).toMatch("USD"); - expect(update.sequenceId).toBeUndefined(); - expect(update.timestampMs).toBeUndefined(); - let point = update.asks[0] || update.bids[0]; - expect(point.orderId).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); - done(); + test("should subscribe and emit level3 snapshot and updates", done => { + let hasSnapshot = false; + client.subscribeLevel3Updates(market); + client.on("l3snapshot", snapshot => { + hasSnapshot = true; + expect(snapshot.fullId).toMatch("Bitfinex:BTC/USD"); + expect(snapshot.exchange).toMatch("Bitfinex"); + expect(snapshot.base).toMatch("BTC"); + expect(snapshot.quote).toMatch("USD"); + expect(snapshot.sequenceId).toBeUndefined(); + expect(snapshot.timestampMs).toBeUndefined(); + expect(snapshot.asks[0].orderId).toBeGreaterThan(0); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.bids[0].orderId).toBeGreaterThan(0); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + }); + client.on("l3update", update => { + expect(hasSnapshot).toBeTruthy(); + expect(update.fullId).toMatch("Bitfinex:BTC/USD"); + expect(update.exchange).toMatch("Bitfinex"); + expect(update.base).toMatch("BTC"); + expect(update.quote).toMatch("USD"); + expect(update.sequenceId).toBeUndefined(); + expect(update.timestampMs).toBeUndefined(); + let point = update.asks[0] || update.bids[0]; + expect(point.orderId).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); + done(); + }); }); -}); -test("should unsubscribe from tickers", () => { - client.unsubscribeTicker(market); -}); + test("should unsubscribe from tickers", () => { + client.unsubscribeTicker(market); + }); -test("should unsubscribe from trades", () => { - client.unsubscribeTrades(market); -}); + test("should unsubscribe from trades", () => { + client.unsubscribeTrades(market); + }); -test("should unsubscribe from level2 updates", () => { - client.unsubscribeLevel2Updates(market); -}); + test("should unsubscribe from level2 updates", () => { + client.unsubscribeLevel2Updates(market); + }); -test("should unsubscribe from level3 updates", () => { - client.unsubscribeLevel3Updates(market); -}); + test("should unsubscribe from level3 updates", () => { + client.unsubscribeLevel3Updates(market); + }); -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/bitflyer-client.spec.js b/src/exchanges/bitflyer-client.spec.js index b62f9bf0..f804decf 100644 --- a/src/exchanges/bitflyer-client.spec.js +++ b/src/exchanges/bitflyer-client.spec.js @@ -9,60 +9,59 @@ let market = { quote: "JPY", }; -beforeAll(() => { - client = new BitFlyerClient(); -}); +describe("BitflyerClient", () => { + beforeAll(() => { + client = new BitFlyerClient(); + }); -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should not support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeFalsy(); -}); + test("it should not support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeFalsy(); + }); -test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeTruthy(); -}); + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeTruthy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); -test("it should not support level3 updates", () => { - expect(client.hasLevel3Updates).toBeFalsy(); -}); + test("it should not support level3 updates", () => { + expect(client.hasLevel3Updates).toBeFalsy(); + }); -test("should subscribe and emit ticker events", done => { - client.subscribeTicker(market); - client.on("ticker", ticker => { - expect(ticker.fullId).toMatch("bitFlyer:BTC/JPY"); - expect(ticker.timestamp).toBeGreaterThan(1531677480465); - expect(typeof ticker.last).toBe("string"); - expect(typeof ticker.volume).toBe("string"); - expect(typeof ticker.bid).toBe("string"); - expect(typeof ticker.bidVolume).toBe("string"); - expect(typeof ticker.ask).toBe("string"); - expect(typeof ticker.askVolume).toBe("string"); - expect(parseFloat(ticker.last)).toBeGreaterThan(0); - expect(ticker.open).toBeUndefined(); - expect(ticker.high).toBeUndefined(); - expect(ticker.low).toBeUndefined(); - expect(parseFloat(ticker.volume)).toBeGreaterThan(0); - expect(parseFloat(ticker.quoteVolume)).toBeGreaterThan(0); - expect(ticker.change).toBeUndefined(); - expect(ticker.changePercent).toBeUndefined(); - expect(parseFloat(ticker.bid)).toBeGreaterThan(0); - expect(parseFloat(ticker.bidVolume)).toBeGreaterThan(0); - expect(parseFloat(ticker.ask)).toBeGreaterThan(0); - expect(parseFloat(ticker.askVolume)).toBeGreaterThan(0); - done(); + test("should subscribe and emit ticker events", done => { + client.subscribeTicker(market); + client.on("ticker", ticker => { + expect(ticker.fullId).toMatch("bitFlyer:BTC/JPY"); + expect(ticker.timestamp).toBeGreaterThan(1531677480465); + expect(typeof ticker.last).toBe("string"); + expect(typeof ticker.volume).toBe("string"); + expect(typeof ticker.bid).toBe("string"); + expect(typeof ticker.bidVolume).toBe("string"); + expect(typeof ticker.ask).toBe("string"); + expect(typeof ticker.askVolume).toBe("string"); + expect(parseFloat(ticker.last)).toBeGreaterThan(0); + expect(ticker.open).toBeUndefined(); + expect(ticker.high).toBeUndefined(); + expect(ticker.low).toBeUndefined(); + expect(parseFloat(ticker.volume)).toBeGreaterThan(0); + expect(parseFloat(ticker.quoteVolume)).toBeGreaterThan(0); + expect(ticker.change).toBeUndefined(); + expect(ticker.changePercent).toBeUndefined(); + expect(parseFloat(ticker.bid)).toBeGreaterThan(0); + expect(parseFloat(ticker.bidVolume)).toBeGreaterThan(0); + expect(parseFloat(ticker.ask)).toBeGreaterThan(0); + expect(parseFloat(ticker.askVolume)).toBeGreaterThan(0); + done(); + }); }); -}); -test( - "should subscribe and emit trade events", - done => { + test("should subscribe and emit trade events", done => { client.subscribeTrades(market); client.on("trade", trade => { expect(trade.fullId).toMatch("bitFlyer:BTC/JPY"); @@ -80,61 +79,60 @@ test( expect(parseFloat(trade.amount)).toBeGreaterThan(0); done(); }); - }, - 90000 -); + }, 90000); -test("should subscribe and emit level2 updates", done => { - let hasSnapshot = true; - let hasUpdate = true; - client.subscribeLevel2Updates(market); - client.on("l2snapshot", update => { - hasSnapshot = true; - expect(update.fullId).toMatch("bitFlyer:BTC/JPY"); - expect(update.exchange).toMatch("bitFlyer"); - expect(update.base).toMatch("BTC"); - expect(update.quote).toMatch("JPY"); - expect(update.sequenceId).toBeUndefined(); - expect(update.timestampMs).toBeUndefined(); - let point = update.asks[0] || update.bids[0]; - expect(typeof point.price).toBe("string"); - expect(typeof point.size).toBe("string"); - expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); - expect(point.count).toBeUndefined(); - if (hasSnapshot && hasUpdate) done(); - }); - client.on("l2update", update => { - hasUpdate = true; - expect(update.fullId).toMatch("bitFlyer:BTC/JPY"); - expect(update.exchange).toMatch("bitFlyer"); - expect(update.base).toMatch("BTC"); - expect(update.quote).toMatch("JPY"); - expect(update.sequenceId).toBeUndefined(); - expect(update.timestampMs).toBeUndefined(); - let point = update.asks[0] || update.bids[0]; - expect(typeof point.price).toBe("string"); - expect(typeof point.size).toBe("string"); - expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); - expect(point.count).toBeUndefined(); - if (hasSnapshot && hasUpdate) done(); + test("should subscribe and emit level2 updates", done => { + let hasSnapshot = true; + let hasUpdate = true; + client.subscribeLevel2Updates(market); + client.on("l2snapshot", update => { + hasSnapshot = true; + expect(update.fullId).toMatch("bitFlyer:BTC/JPY"); + expect(update.exchange).toMatch("bitFlyer"); + expect(update.base).toMatch("BTC"); + expect(update.quote).toMatch("JPY"); + expect(update.sequenceId).toBeUndefined(); + expect(update.timestampMs).toBeUndefined(); + let point = update.asks[0] || update.bids[0]; + expect(typeof point.price).toBe("string"); + expect(typeof point.size).toBe("string"); + expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); + expect(point.count).toBeUndefined(); + if (hasSnapshot && hasUpdate) done(); + }); + client.on("l2update", update => { + hasUpdate = true; + expect(update.fullId).toMatch("bitFlyer:BTC/JPY"); + expect(update.exchange).toMatch("bitFlyer"); + expect(update.base).toMatch("BTC"); + expect(update.quote).toMatch("JPY"); + expect(update.sequenceId).toBeUndefined(); + expect(update.timestampMs).toBeUndefined(); + let point = update.asks[0] || update.bids[0]; + expect(typeof point.price).toBe("string"); + expect(typeof point.size).toBe("string"); + expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); + expect(point.count).toBeUndefined(); + if (hasSnapshot && hasUpdate) done(); + }); }); -}); -test("should unsubscribe from tickers", () => { - client.unsubscribeTicker(market); -}); + test("should unsubscribe from tickers", () => { + client.unsubscribeTicker(market); + }); -test("should unsubscribe trades", () => { - client.unsubscribeTrades(market); -}); + test("should unsubscribe trades", () => { + client.unsubscribeTrades(market); + }); -test("should unsubscribe from level2orders", () => { - client.unsubscribeLevel2Updates(market); -}); + test("should unsubscribe from level2orders", () => { + client.unsubscribeLevel2Updates(market); + }); -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/bitmex-client.spec.js b/src/exchanges/bitmex-client.spec.js index 076de95e..051f8e52 100644 --- a/src/exchanges/bitmex-client.spec.js +++ b/src/exchanges/bitmex-client.spec.js @@ -9,15 +9,11 @@ let market = { quote: "USD", }; -describe("Bitmex Client", () => { +describe("BitmexClient", () => { beforeAll(() => { client = new BitmexClient(); }); - afterEach(() => { - client.removeAllListeners(); - }); - test("it should support trades", () => { expect(client.hasTrades).toBeTruthy(); }); diff --git a/src/exchanges/bitstamp-client.spec.js b/src/exchanges/bitstamp-client.spec.js index ed33e53b..8e1859e4 100644 --- a/src/exchanges/bitstamp-client.spec.js +++ b/src/exchanges/bitstamp-client.spec.js @@ -9,33 +9,32 @@ let market = { quote: "USD", }; -beforeAll(() => { - client = new Bitstamp(); -}); +describe("BitstampClient", () => { + beforeAll(() => { + client = new Bitstamp(); + }); -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeTruthy(); -}); + test("it should support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeTruthy(); + }); -test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeTruthy(); -}); + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeTruthy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); -test("it should support level3 updates", () => { - expect(client.hasLevel3Updates).toBeTruthy(); -}); + test("it should support level3 updates", () => { + expect(client.hasLevel3Updates).toBeTruthy(); + }); -test( - "should subscribe and emit trade events", - done => { + test("should subscribe and emit trade events", done => { client.subscribeTrades(market); client.on("trade", trade => { expect(trade.fullId).toMatch("Bitstamp:BTC/USD"); @@ -51,100 +50,99 @@ test( expect(parseFloat(trade.amount)).toBeGreaterThan(0); done(); }); - }, - 60000 -); - -test("should subscribe and emit level2 updates", done => { - let hasSnapshot = false; - let hasUpdate = false; - client.subscribeLevel2Updates(market); - client.on("l2snapshot", snapshot => { - hasSnapshot = true; - expect(snapshot.fullId).toMatch("Bitstamp:BTC/USD"); - expect(snapshot.exchange).toMatch("Bitstamp"); - expect(snapshot.base).toMatch("BTC"); - expect(snapshot.quote).toMatch("USD"); - expect(snapshot.sequenceId).toBeUndefined(); - expect(snapshot.timestampMs).toBeGreaterThan(0); - expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.asks[0].count).toBeUndefined(); - expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.bids[0].count).toBeUndefined(); - if (hasSnapshot && hasUpdate) done(); - }); - client.on("l2update", update => { - hasUpdate = true; - expect(update.fullId).toMatch("Bitstamp:BTC/USD"); - expect(update.exchange).toMatch("Bitstamp"); - expect(update.base).toMatch("BTC"); - expect(update.quote).toMatch("USD"); - expect(update.sequenceId).toBeUndefined(); - expect(update.timestampMs).toBeGreaterThan(0); - let point = update.asks[0] || update.bids[0]; - expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); - expect(point.count).toBeUndefined(); - if (hasSnapshot && hasUpdate) done(); + }, 60000); + + test("should subscribe and emit level2 updates", done => { + let hasSnapshot = false; + let hasUpdate = false; + client.subscribeLevel2Updates(market); + client.on("l2snapshot", snapshot => { + hasSnapshot = true; + expect(snapshot.fullId).toMatch("Bitstamp:BTC/USD"); + expect(snapshot.exchange).toMatch("Bitstamp"); + expect(snapshot.base).toMatch("BTC"); + expect(snapshot.quote).toMatch("USD"); + expect(snapshot.sequenceId).toBeUndefined(); + expect(snapshot.timestampMs).toBeGreaterThan(0); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.asks[0].count).toBeUndefined(); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.bids[0].count).toBeUndefined(); + if (hasSnapshot && hasUpdate) done(); + }); + client.on("l2update", update => { + hasUpdate = true; + expect(update.fullId).toMatch("Bitstamp:BTC/USD"); + expect(update.exchange).toMatch("Bitstamp"); + expect(update.base).toMatch("BTC"); + expect(update.quote).toMatch("USD"); + expect(update.sequenceId).toBeUndefined(); + expect(update.timestampMs).toBeGreaterThan(0); + let point = update.asks[0] || update.bids[0]; + expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); + expect(point.count).toBeUndefined(); + if (hasSnapshot && hasUpdate) done(); + }); }); -}); -test("should subscribe and emit level2 snapshots", done => { - client.subscribeLevel2Snapshots(market); - client.on("l2snapshot", snapshot => { - expect(snapshot.fullId).toMatch("Bitstamp:BTC/USD"); - expect(snapshot.exchange).toMatch("Bitstamp"); - expect(snapshot.base).toMatch("BTC"); - expect(snapshot.quote).toMatch("USD"); - expect(snapshot.sequenceId).toBeUndefined(); - expect(snapshot.timestampMs).toBeGreaterThan(0); - expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.asks[0].count).toBeUndefined(); - expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.bids[0].count).toBeUndefined(); - done(); + test("should subscribe and emit level2 snapshots", done => { + client.subscribeLevel2Snapshots(market); + client.on("l2snapshot", snapshot => { + expect(snapshot.fullId).toMatch("Bitstamp:BTC/USD"); + expect(snapshot.exchange).toMatch("Bitstamp"); + expect(snapshot.base).toMatch("BTC"); + expect(snapshot.quote).toMatch("USD"); + expect(snapshot.sequenceId).toBeUndefined(); + expect(snapshot.timestampMs).toBeGreaterThan(0); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.asks[0].count).toBeUndefined(); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.bids[0].count).toBeUndefined(); + done(); + }); }); -}); -test("should subscribe and emit level3 updates", done => { - client.subscribeLevel3Updates(market); - client.on("l3update", update => { - expect(update.fullId).toMatch("Bitstamp:BTC/USD"); - expect(update.exchange).toMatch("Bitstamp"); - expect(update.base).toMatch("BTC"); - expect(update.quote).toMatch("USD"); - expect(update.sequenceId).toBeUndefined(); - expect(update.timestampMs).toBeGreaterThan(0); - let point = update.asks[0] || update.bids[0]; - expect(point.orderId).toBeGreaterThan(0); - expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); - expect(point.meta.type).toMatch(/created|updated|deleted/); - done(); + test("should subscribe and emit level3 updates", done => { + client.subscribeLevel3Updates(market); + client.on("l3update", update => { + expect(update.fullId).toMatch("Bitstamp:BTC/USD"); + expect(update.exchange).toMatch("Bitstamp"); + expect(update.base).toMatch("BTC"); + expect(update.quote).toMatch("USD"); + expect(update.sequenceId).toBeUndefined(); + expect(update.timestampMs).toBeGreaterThan(0); + let point = update.asks[0] || update.bids[0]; + expect(point.orderId).toBeGreaterThan(0); + expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); + expect(point.meta.type).toMatch(/created|updated|deleted/); + done(); + }); }); -}); -test("should unsubscribe from trade events", () => { - client.unsubscribeTrades(market); -}); + test("should unsubscribe from trade events", () => { + client.unsubscribeTrades(market); + }); -test("should unsubscribe from level2 snapshot", () => { - client.unsubscribeLevel2Snapshots(market); -}); + test("should unsubscribe from level2 snapshot", () => { + client.unsubscribeLevel2Snapshots(market); + }); -test("should unsubscribe from level2 updates", () => { - client.unsubscribeLevel2Updates(market); -}); + test("should unsubscribe from level2 updates", () => { + client.unsubscribeLevel2Updates(market); + }); -test("should unsubscribe from level3 updates", () => { - client.unsubscribeLevel3Updates(market); -}); + test("should unsubscribe from level3 updates", () => { + client.unsubscribeLevel3Updates(market); + }); -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/bittrex-client.js b/src/exchanges/bittrex-client.js index a6027441..039b24fd 100644 --- a/src/exchanges/bittrex-client.js +++ b/src/exchanges/bittrex-client.js @@ -284,7 +284,7 @@ class BittrexClient extends EventEmitter { let market = this._tickerSubs.get(msg.MarketName); let { High, Low, Last, PrevDay, BaseVolume, Volume, TimeStamp, Bid, Ask } = msg; let change = Last - PrevDay; - let percentChange = (Last - PrevDay) / PrevDay * 100; + let percentChange = ((Last - PrevDay) / PrevDay) * 100; return new Ticker({ exchange: "Bittrex", base: market.base, @@ -325,7 +325,7 @@ class BittrexClient extends EventEmitter { // prettier-ignore _constructLevel2Snapshot(msg) { let market = this._level2UpdateSubs.get(msg.MarketName); - let sequenceId = msg.Nounce; + let sequenceId = msg.Nonce; let bids = msg.Buys.map(p => new Level2Point(p.Rate.toFixed(8), p.Quantity.toFixed(8), undefined, { type: p.Type })); let asks = msg.Sells.map(p => new Level2Point(p.Rate.toFixed(8), p.Quantity.toFixed(8), undefined, { type: p.Type })); return new Level2Snapshot({ @@ -341,7 +341,7 @@ class BittrexClient extends EventEmitter { // prettier-ignore _constructLevel2Update(msg) { let market = this._level2UpdateSubs.get(msg.MarketName); - let sequenceId = msg.Nounce; + let sequenceId = msg.Nonce; let bids = msg.Buys.map(p => new Level2Point(p.Rate.toFixed(8), p.Quantity.toFixed(8), undefined, { type: p.Type })); let asks = msg.Sells.map(p => new Level2Point(p.Rate.toFixed(8), p.Quantity.toFixed(8), undefined, { type: p.Type })); return new Level2Update({ diff --git a/src/exchanges/bittrex-client.spec.js b/src/exchanges/bittrex-client.spec.js index c9b7310a..3ad6583c 100644 --- a/src/exchanges/bittrex-client.spec.js +++ b/src/exchanges/bittrex-client.spec.js @@ -9,37 +9,48 @@ let market = { quote: "USDT", }; -beforeAll(() => { - client = new Bittrex(); -}); +let market2 = { + id: "BTC-ETH", + base: "ETH", + quote: "BTC", +}; -test("it should support tickers", () => { - expect(client.hasTickers).toBeTruthy(); -}); +let market3 = { + id: "BTC-LTC", + base: "LTC", + quote: "BTC", +}; -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); +describe("BittrexClient", () => { + beforeAll(() => { + client = new Bittrex(); + }); -test("it should not support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeFalsy(); -}); + test("it should support tickers", () => { + expect(client.hasTickers).toBeTruthy(); + }); -test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeTruthy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should not support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeFalsy(); + }); -test("it should not support level3 updates", () => { - expect(client.hasLevel3Updates).toBeFalsy(); -}); + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeTruthy(); + }); + + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); + + test("it should not support level3 updates", () => { + expect(client.hasLevel3Updates).toBeFalsy(); + }); -test( - "should subscribe and emit ticker events", - done => { + test("should subscribe and emit ticker events", done => { client.subscribeTicker(market); client.on("ticker", ticker => { expect(ticker.fullId).toMatch("Bittrex:BTC/USDT"); @@ -68,13 +79,9 @@ test( expect(ticker.askVolume).toBeUndefined(); done(); }); - }, - 90000 -); + }, 30000); -test( - "should subscribe and emit level2 snapshot and updates", - done => { + test("should subscribe and emit level2 snapshot and updates", done => { let hasSnapshot = false; client.subscribeLevel2Updates(market); client.on("l2snapshot", snapshot => { @@ -112,19 +119,17 @@ test( expect(point.meta.type).toBeGreaterThanOrEqual(0); if (hasSnapshot) done(); }); - }, - 90000 -); + }, 30000); -test( - "should subscribe and emit trade events", - done => { + test("should subscribe and emit trade events", done => { client.subscribeTrades(market); + client.subscribeTrades(market2); + client.subscribeTrades(market3); client.on("trade", trade => { - expect(trade.fullId).toMatch("Bittrex:BTC/USDT"); + expect(trade.fullId).toMatch(/Bittrex:BTC\/USDT|Bittrex:ETH\/BTC|Bittrex:LTC\/BTC/); expect(trade.exchange).toMatch("Bittrex"); - expect(trade.base).toMatch("BTC"); - expect(trade.quote).toMatch("USDT"); + expect(trade.base).toMatch(/BTC|ETH|LTC/); + expect(trade.quote).toMatch(/USDT|BTC/); expect(trade.tradeId).toMatch(/^[0-9a-f]{32,32}$/); expect(trade.unix).toBeGreaterThan(1522540800000); expect(trade.side).toMatch(/buy|sell/); @@ -134,23 +139,22 @@ test( expect(parseFloat(trade.amount)).toBeGreaterThan(0); done(); }); - }, - 90000 -); + }, 60000); -test("should unsubscribe from tickers", () => { - client.unsubscribeTicker(market); -}); + test("should unsubscribe from tickers", () => { + client.unsubscribeTicker(market); + }); -test("should unsubscribe from trade events", () => { - client.unsubscribeTrades(market); -}); + test("should unsubscribe from trade events", () => { + client.unsubscribeTrades(market); + }); -test("should unsubscribe from level2 updates", () => { - client.unsubscribeLevel2Updates(market); -}); + test("should unsubscribe from level2 updates", () => { + client.unsubscribeLevel2Updates(market); + }); -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/cex-client.spec.js b/src/exchanges/cex-client.spec.js index c9e822e0..2b645255 100644 --- a/src/exchanges/cex-client.spec.js +++ b/src/exchanges/cex-client.spec.js @@ -2,46 +2,48 @@ const CexClient = require("./cex-client"); jest.mock("winston", () => ({ info: jest.fn(), warn: jest.fn(), error: jest.fn() })); jest.retryTimes(3); -let client; -let market = { - id: "BTC-USD", - base: "BTC", - quote: "USD", -}; - -beforeAll(() => { - client = new CexClient(); -}); - -test("it should support tickers", () => { - expect(client.hasTickers).toBeTruthy(); -}); - -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); - -test("it should support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeTruthy(); -}); - -test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeFalsy(); -}); - -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); - -test("it should not support level3 updates", () => { - expect(client.hasLevel3Updates).toBeFalsy(); -}); - -test("should unsubscribe", () => { - client.unsubscribeTrades(market); -}); - -test("should close connections", done => { - client.on("closed", done); - client.close(); +describe("CexClient", () => { + let client; + let market = { + id: "BTC-USD", + base: "BTC", + quote: "USD", + }; + + beforeAll(() => { + client = new CexClient(); + }); + + test("it should support tickers", () => { + expect(client.hasTickers).toBeTruthy(); + }); + + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); + + test("it should support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeTruthy(); + }); + + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeFalsy(); + }); + + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); + + test("it should not support level3 updates", () => { + expect(client.hasLevel3Updates).toBeFalsy(); + }); + + test("should unsubscribe", () => { + client.unsubscribeTrades(market); + }); + + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/coinbasepro-client.spec.js b/src/exchanges/coinbasepro-client.spec.js index c0a00924..1047dfda 100644 --- a/src/exchanges/coinbasepro-client.spec.js +++ b/src/exchanges/coinbasepro-client.spec.js @@ -9,37 +9,36 @@ let market = { quote: "USD", }; -beforeAll(() => { - client = new Client(); -}); +describe("CoinbaseProClient", () => { + beforeAll(() => { + client = new Client(); + }); -test("it should support tickers", () => { - expect(client.hasTickers).toBeTruthy(); -}); + test("it should support tickers", () => { + expect(client.hasTickers).toBeTruthy(); + }); -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should not support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeFalsy(); -}); + test("it should not support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeFalsy(); + }); -test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeTruthy(); -}); + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeTruthy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); -test("it should support level3 updates", () => { - expect(client.hasLevel3Updates).toBeTruthy(); -}); + test("it should support level3 updates", () => { + expect(client.hasLevel3Updates).toBeTruthy(); + }); -test( - "should subscribe and emit ticker events", - done => { + test("should subscribe and emit ticker events", done => { client.subscribeTicker(market); client.on("ticker", ticker => { expect(ticker.fullId).toMatch("CoinbasePro:BTC/USD"); @@ -66,13 +65,9 @@ test( expect(ticker.askVolume).toBeUndefined(); done(); }); - }, - 10000 -); + }, 10000); -test( - "should subscribe and emit trade events", - done => { + test("should subscribe and emit trade events", done => { client.subscribeTrades(market); client.on("trade", trade => { expect(trade.fullId).toMatch("CoinbasePro:BTC/USD"); @@ -91,47 +86,43 @@ test( expect(trade.buyOrderId).not.toEqual(trade.sellOrderId); done(); }); - }, - 30000 -); - -test("should subscribe and emit level2 snapshot and updates", done => { - let hasSnapshot = false; - client.subscribeLevel2Updates(market); - client.on("l2snapshot", snapshot => { - hasSnapshot = true; - expect(snapshot.fullId).toMatch("CoinbasePro:BTC/USD"); - expect(snapshot.exchange).toMatch("CoinbasePro"); - expect(snapshot.base).toMatch("BTC"); - expect(snapshot.quote).toMatch("USD"); - expect(snapshot.sequenceId).toBeUndefined(); - expect(snapshot.timestampMs).toBeUndefined(); - expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.asks[0].count).toBeUndefined(); - expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.bids[0].count).toBeUndefined(); - }); - client.on("l2update", update => { - expect(hasSnapshot).toBeTruthy(); - expect(update.fullId).toMatch("CoinbasePro:BTC/USD"); - expect(update.exchange).toMatch("CoinbasePro"); - expect(update.base).toMatch("BTC"); - expect(update.quote).toMatch("USD"); - expect(update.sequenceId).toBeUndefined(); - expect(update.timestampMs).toBeUndefined(); - let point = update.asks[0] || update.bids[0]; - expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); - expect(point.count).toBeUndefined(); - done(); + }, 30000); + + test("should subscribe and emit level2 snapshot and updates", done => { + let hasSnapshot = false; + client.subscribeLevel2Updates(market); + client.on("l2snapshot", snapshot => { + hasSnapshot = true; + expect(snapshot.fullId).toMatch("CoinbasePro:BTC/USD"); + expect(snapshot.exchange).toMatch("CoinbasePro"); + expect(snapshot.base).toMatch("BTC"); + expect(snapshot.quote).toMatch("USD"); + expect(snapshot.sequenceId).toBeUndefined(); + expect(snapshot.timestampMs).toBeUndefined(); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.asks[0].count).toBeUndefined(); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.bids[0].count).toBeUndefined(); + }); + client.on("l2update", update => { + expect(hasSnapshot).toBeTruthy(); + expect(update.fullId).toMatch("CoinbasePro:BTC/USD"); + expect(update.exchange).toMatch("CoinbasePro"); + expect(update.base).toMatch("BTC"); + expect(update.quote).toMatch("USD"); + expect(update.sequenceId).toBeUndefined(); + expect(update.timestampMs).toBeUndefined(); + let point = update.asks[0] || update.bids[0]; + expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); + expect(point.count).toBeUndefined(); + done(); + }); }); -}); -test( - "should subscribe and emit level3 updates", - done => { + test("should subscribe and emit level3 updates", done => { let hasReceived, hasOpen, hasDone, hasMatch; let point; client.subscribeLevel3Updates(market); @@ -188,23 +179,22 @@ test( throw ex; } }); - }, - 30000 -); + }, 30000); -test("unsubscribe from trades", () => { - client.unsubscribeTrades(market); -}); + test("unsubscribe from trades", () => { + client.unsubscribeTrades(market); + }); -test("unsubscribe from level2 updates", () => { - client.unsubscribeLevel2Updates(market); -}); + test("unsubscribe from level2 updates", () => { + client.unsubscribeLevel2Updates(market); + }); -test("unsubscribe from level3 updates", () => { - client.unsubscribeLevel3Updates(market); -}); + test("unsubscribe from level3 updates", () => { + client.unsubscribeLevel3Updates(market); + }); -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/coinex-client.spec.js b/src/exchanges/coinex-client.spec.js index 64cc1e7f..1e8d7b48 100644 --- a/src/exchanges/coinex-client.spec.js +++ b/src/exchanges/coinex-client.spec.js @@ -15,37 +15,36 @@ let market2 = { quote: "BTC", }; -beforeAll(() => { - client = new Coinex(); -}); +describe("CoinexClient", () => { + beforeAll(() => { + client = new Coinex(); + }); -test("it should support tickers", () => { - expect(client.hasTickers).toBeTruthy(); -}); + test("it should support tickers", () => { + expect(client.hasTickers).toBeTruthy(); + }); -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should not support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeFalsy(); -}); + test("it should not support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeFalsy(); + }); -test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeTruthy(); -}); + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeTruthy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); -test("it should not support level3 updates", () => { - expect(client.hasLevel3Updates).toBeFalsy(); -}); + test("it should not support level3 updates", () => { + expect(client.hasLevel3Updates).toBeFalsy(); + }); -test( - "should subscribe and emit ticker events", - done => { + test("should subscribe and emit ticker events", done => { client.subscribeTicker(market1); client.on("ticker", function tickerHandler(ticker) { expect(ticker.fullId).toMatch("Coinex:BTC/USDT"); @@ -80,13 +79,9 @@ test( client.unsubscribeTicker(market1); done(); }); - }, - 30000 -); + }, 30000); -test( - "should subscribe and emit trade events", - done => { + test("should subscribe and emit trade events", done => { client.subscribeTrades(market1); client.on("trade", function tradeHandler(trade) { expect(trade.fullId).toMatch("Coinex:BTC/USDT"); @@ -105,13 +100,9 @@ test( client.unsubscribeTrades(market1); done(); }); - }, - 30000 -); + }, 30000); -test( - "should subscribe and emit level2 updates", - done => { + test("should subscribe and emit level2 updates", done => { client.subscribeLevel2Updates(market1); client.on("l2update", function level2UpdateHandler(update) { @@ -134,13 +125,9 @@ test( client.unsubscribeLevel2Updates(market1); done(); }); - }, - 30000 -); + }, 30000); -test( - "should subscribe and emit tickers for 2 markets", - done => { + test("should subscribe and emit tickers for 2 markets", done => { let receivedMarket1Update = false; let receivedMarket2Update = false; @@ -164,13 +151,9 @@ test( done(); } }); - }, - 30000 -); + }, 30000); -test( - "should subscribe and emit tickers for tickers, trades, and l2updates for the same market", - done => { + test("should subscribe and emit tickers for tickers, trades, and l2updates for the same market", done => { let receivedTickerUpdate = false; let receivedTradeUpdate = false; let receivedL2Update = false; @@ -197,11 +180,10 @@ test( receivedL2Update = true; check(); }); - }, - 90000 -); + }, 90000); -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/ethfinex-client.spec.js b/src/exchanges/ethfinex-client.spec.js index adfefefa..eea7e97a 100644 --- a/src/exchanges/ethfinex-client.spec.js +++ b/src/exchanges/ethfinex-client.spec.js @@ -9,69 +9,68 @@ let market = { quote: "USD", }; -beforeAll(() => { - client = new Ethfinex(); -}); +describe("EthfinexClient", () => { + beforeAll(() => { + client = new Ethfinex(); + }); -test("it should support tickers", () => { - expect(client.hasTickers).toBeTruthy(); -}); + test("it should support tickers", () => { + expect(client.hasTickers).toBeTruthy(); + }); -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should not support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeFalsy(); -}); + test("it should not support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeFalsy(); + }); -test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeTruthy(); -}); + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeTruthy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); -test("it should support level3 updates", () => { - expect(client.hasLevel3Updates).toBeTruthy(); -}); + test("it should support level3 updates", () => { + expect(client.hasLevel3Updates).toBeTruthy(); + }); -test("should subscribe and emit ticker events", done => { - client.subscribeTicker(market); - client.on("ticker", ticker => { - expect(ticker.fullId).toMatch("Ethfinex:BTC/USD"); - expect(ticker.timestamp).toBeGreaterThan(1531677480465); - expect(typeof ticker.last).toBe("string"); - expect(typeof ticker.open).toBe("string"); - expect(typeof ticker.high).toBe("string"); - expect(typeof ticker.low).toBe("string"); - expect(typeof ticker.volume).toBe("string"); - expect(typeof ticker.change).toBe("string"); - expect(typeof ticker.changePercent).toBe("string"); - expect(typeof ticker.bid).toBe("string"); - expect(typeof ticker.bidVolume).toBe("string"); - expect(typeof ticker.ask).toBe("string"); - expect(typeof ticker.askVolume).toBe("string"); - expect(parseFloat(ticker.last)).toBeGreaterThan(0); - expect(parseFloat(ticker.open)).toBeGreaterThan(0); - expect(parseFloat(ticker.high)).toBeGreaterThan(0); - expect(parseFloat(ticker.low)).toBeGreaterThan(0); - expect(parseFloat(ticker.volume)).toBeGreaterThan(0); - expect(ticker.quoteVolume).toBeUndefined(); - expect(isNaN(parseFloat(ticker.change))).toBeFalsy(); - expect(isNaN(parseFloat(ticker.changePercent))).toBeFalsy(); - expect(parseFloat(ticker.bid)).toBeGreaterThan(0); - expect(parseFloat(ticker.bidVolume)).toBeGreaterThan(0); - expect(parseFloat(ticker.ask)).toBeGreaterThan(0); - expect(parseFloat(ticker.askVolume)).toBeGreaterThan(0); - done(); + test("should subscribe and emit ticker events", done => { + client.subscribeTicker(market); + client.on("ticker", ticker => { + expect(ticker.fullId).toMatch("Ethfinex:BTC/USD"); + expect(ticker.timestamp).toBeGreaterThan(1531677480465); + expect(typeof ticker.last).toBe("string"); + expect(typeof ticker.open).toBe("string"); + expect(typeof ticker.high).toBe("string"); + expect(typeof ticker.low).toBe("string"); + expect(typeof ticker.volume).toBe("string"); + expect(typeof ticker.change).toBe("string"); + expect(typeof ticker.changePercent).toBe("string"); + expect(typeof ticker.bid).toBe("string"); + expect(typeof ticker.bidVolume).toBe("string"); + expect(typeof ticker.ask).toBe("string"); + expect(typeof ticker.askVolume).toBe("string"); + expect(parseFloat(ticker.last)).toBeGreaterThan(0); + expect(parseFloat(ticker.open)).toBeGreaterThan(0); + expect(parseFloat(ticker.high)).toBeGreaterThan(0); + expect(parseFloat(ticker.low)).toBeGreaterThan(0); + expect(parseFloat(ticker.volume)).toBeGreaterThan(0); + expect(ticker.quoteVolume).toBeUndefined(); + expect(isNaN(parseFloat(ticker.change))).toBeFalsy(); + expect(isNaN(parseFloat(ticker.changePercent))).toBeFalsy(); + expect(parseFloat(ticker.bid)).toBeGreaterThan(0); + expect(parseFloat(ticker.bidVolume)).toBeGreaterThan(0); + expect(parseFloat(ticker.ask)).toBeGreaterThan(0); + expect(parseFloat(ticker.askVolume)).toBeGreaterThan(0); + done(); + }); }); -}); -test( - "should subscribe and emit trade events", - done => { + test("should subscribe and emit trade events", done => { client.subscribeTrades(market); client.on("trade", trade => { expect(trade.fullId).toMatch("Ethfinex:BTC/USD"); @@ -87,95 +86,94 @@ test( expect(parseFloat(trade.amount)).toBeGreaterThan(0); done(); }); - }, - 30000 -); - -test("should subscribe and emit level2 snapshot and updates", done => { - let hasSnapshot = false; - client.subscribeLevel2Updates(market); - client.on("l2snapshot", snapshot => { - hasSnapshot = true; - expect(snapshot.fullId).toMatch("Ethfinex:BTC/USD"); - expect(snapshot.exchange).toMatch("Ethfinex"); - expect(snapshot.base).toMatch("BTC"); - expect(snapshot.quote).toMatch("USD"); - expect(snapshot.sequenceId).toBeUndefined(); - expect(snapshot.timestampMs).toBeUndefined(); - expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].count)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].count)).toBeGreaterThanOrEqual(0); - }); - client.on("l2update", update => { - expect(hasSnapshot).toBeTruthy(); - expect(update.fullId).toMatch("Ethfinex:BTC/USD"); - expect(update.exchange).toMatch("Ethfinex"); - expect(update.base).toMatch("BTC"); - expect(update.quote).toMatch("USD"); - expect(update.sequenceId).toBeUndefined(); - expect(update.timestampMs).toBeUndefined(); - let point = update.asks[0] || update.bids[0]; - expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.count)).toBeGreaterThanOrEqual(0); - done(); + }, 30000); + + test("should subscribe and emit level2 snapshot and updates", done => { + let hasSnapshot = false; + client.subscribeLevel2Updates(market); + client.on("l2snapshot", snapshot => { + hasSnapshot = true; + expect(snapshot.fullId).toMatch("Ethfinex:BTC/USD"); + expect(snapshot.exchange).toMatch("Ethfinex"); + expect(snapshot.base).toMatch("BTC"); + expect(snapshot.quote).toMatch("USD"); + expect(snapshot.sequenceId).toBeUndefined(); + expect(snapshot.timestampMs).toBeUndefined(); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].count)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].count)).toBeGreaterThanOrEqual(0); + }); + client.on("l2update", update => { + expect(hasSnapshot).toBeTruthy(); + expect(update.fullId).toMatch("Ethfinex:BTC/USD"); + expect(update.exchange).toMatch("Ethfinex"); + expect(update.base).toMatch("BTC"); + expect(update.quote).toMatch("USD"); + expect(update.sequenceId).toBeUndefined(); + expect(update.timestampMs).toBeUndefined(); + let point = update.asks[0] || update.bids[0]; + expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.count)).toBeGreaterThanOrEqual(0); + done(); + }); }); -}); -test("should subscribe and emit level3 snapshot and updates", done => { - let hasSnapshot = false; - client.subscribeLevel3Updates(market); - client.on("l3snapshot", snapshot => { - hasSnapshot = true; - expect(snapshot.fullId).toMatch("Ethfinex:BTC/USD"); - expect(snapshot.exchange).toMatch("Ethfinex"); - expect(snapshot.base).toMatch("BTC"); - expect(snapshot.quote).toMatch("USD"); - expect(snapshot.sequenceId).toBeUndefined(); - expect(snapshot.timestampMs).toBeUndefined(); - expect(snapshot.asks[0].orderId).toBeGreaterThan(0); - expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.bids[0].orderId).toBeGreaterThan(0); - expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); - }); - client.on("l3update", update => { - expect(hasSnapshot).toBeTruthy(); - expect(update.fullId).toMatch("Ethfinex:BTC/USD"); - expect(update.exchange).toMatch("Ethfinex"); - expect(update.base).toMatch("BTC"); - expect(update.quote).toMatch("USD"); - expect(update.sequenceId).toBeUndefined(); - expect(update.timestampMs).toBeUndefined(); - let point = update.asks[0] || update.bids[0]; - expect(point.orderId).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); - done(); + test("should subscribe and emit level3 snapshot and updates", done => { + let hasSnapshot = false; + client.subscribeLevel3Updates(market); + client.on("l3snapshot", snapshot => { + hasSnapshot = true; + expect(snapshot.fullId).toMatch("Ethfinex:BTC/USD"); + expect(snapshot.exchange).toMatch("Ethfinex"); + expect(snapshot.base).toMatch("BTC"); + expect(snapshot.quote).toMatch("USD"); + expect(snapshot.sequenceId).toBeUndefined(); + expect(snapshot.timestampMs).toBeUndefined(); + expect(snapshot.asks[0].orderId).toBeGreaterThan(0); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.bids[0].orderId).toBeGreaterThan(0); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + }); + client.on("l3update", update => { + expect(hasSnapshot).toBeTruthy(); + expect(update.fullId).toMatch("Ethfinex:BTC/USD"); + expect(update.exchange).toMatch("Ethfinex"); + expect(update.base).toMatch("BTC"); + expect(update.quote).toMatch("USD"); + expect(update.sequenceId).toBeUndefined(); + expect(update.timestampMs).toBeUndefined(); + let point = update.asks[0] || update.bids[0]; + expect(point.orderId).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); + done(); + }); }); -}); -test("should unsubscribe from tickers", () => { - client.unsubscribeTicker(market); -}); + test("should unsubscribe from tickers", () => { + client.unsubscribeTicker(market); + }); -test("should unsubscribe from trades", () => { - client.unsubscribeTrades(market); -}); + test("should unsubscribe from trades", () => { + client.unsubscribeTrades(market); + }); -test("should unsubscribe from level2 updates", () => { - client.unsubscribeLevel2Updates(market); -}); + test("should unsubscribe from level2 updates", () => { + client.unsubscribeLevel2Updates(market); + }); -test("should unsubscribe from level3 updates", () => { - client.unsubscribeLevel3Updates(market); -}); + test("should unsubscribe from level3 updates", () => { + client.unsubscribeLevel3Updates(market); + }); -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/gateio-client.spec.js b/src/exchanges/gateio-client.spec.js index 56b1fe3c..2999680b 100644 --- a/src/exchanges/gateio-client.spec.js +++ b/src/exchanges/gateio-client.spec.js @@ -10,42 +10,41 @@ let market1 = { }; let market2 = { - id: "ETH_USDT", + id: "ETH_BTC", base: "ETH", - quote: "USDT", + quote: "BTC", }; -beforeAll(() => { - client = new Gateio(); -}); +describe("GateioClient", () => { + beforeAll(() => { + client = new Gateio(); + }); -test("it should support tickers", () => { - expect(client.hasTickers).toBeTruthy(); -}); + test("it should support tickers", () => { + expect(client.hasTickers).toBeTruthy(); + }); -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should not support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeFalsy(); -}); + test("it should not support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeFalsy(); + }); -test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeTruthy(); -}); + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeTruthy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); -test("it should not support level3 updates", () => { - expect(client.hasLevel3Updates).toBeFalsy(); -}); + test("it should not support level3 updates", () => { + expect(client.hasLevel3Updates).toBeFalsy(); + }); -test( - "should subscribe and emit ticker events", - done => { + test("should subscribe and emit ticker events", done => { client.subscribeTicker(market1); client.on("ticker", function tickerHandler(ticker) { expect(ticker.fullId).toMatch("Gateio:BTC/USDT"); @@ -74,56 +73,56 @@ test( expect(parseFloat(ticker.bidVolume)).toBe(NaN); expect(parseFloat(ticker.ask)).toBe(NaN); expect(parseFloat(ticker.askVolume)).toBe(NaN); - - // Need to remove this listener, otherwise it is still running during subsequent tests - client.removeListener("ticker", tickerHandler); - client.unsubscribeTicker(market1); done(); }); - }, - 30000 -); + }, 30000); -test( - "should subscribe and emit trade events", - done => { + test("should unsubscribe from tickers", () => { + client.unsubscribeTicker(market1); + }); + + test("should subscribe and emit trade events", done => { client.subscribeTrades(market1); + client.subscribeTrades(market2); client.on("trade", function tradeHandler(trade) { - - expect(trade.fullId).toMatch("Gateio:BTC/USDT"); + expect(trade.fullId).toMatch(/Gateio:BTC\/USDT|Gateio:ETH\/BTC/); expect(trade.exchange).toMatch("Gateio"); - expect(trade.base).toMatch("BTC"); - expect(trade.quote).toMatch("USDT"); + expect(trade.base).toMatch(/BTC|ETH/); + expect(trade.quote).toMatch(/USDT|BTC/); expect(trade.tradeId).toBeGreaterThan(0); expect(trade.unix).toBeGreaterThan(1522540800000); expect(trade.side).toMatch(/buy|sell/); expect(typeof trade.price).toBe("string"); expect(typeof trade.amount).toBe("string"); expect(parseFloat(trade.price)).toBeGreaterThan(0); - - /* - if (trade.side === "buy") { - expect(parseFloat(trade.buyOrderId)).toBeGreaterThan(0); - expect(trade.sellOrderId).toBeNull(); - } else { - expect(trade.buyOrderId).toBeNull(); - expect(parseFloat(trade.sellOrderId)).toBeGreaterThan(0); - }*/ - - // Need to remove this listener, otherwise it is still running during subsequent tests - client.removeListener("trade", tradeHandler); - client.unsubscribeTrades(market1); + expect(parseFloat(trade.amount)).toBeGreaterThan(0); done(); }); - }, - 30000 -); + }, 30000); -test( - "should subscribe and emit level2 updates", - done => { - client.subscribeLevel2Updates(market1); + test("should unsubscribe from trades", () => { + client.unsubscribeTrades(market1); + }); + test("should subscribe and emit level2 updates", done => { + client.subscribeLevel2Updates(market1); + let hasSnapshot = true; + client.on("l2snapshot", snapshot => { + expect(snapshot.fullId).toMatch("Gateio:BTC/USDT"); + expect(snapshot.exchange).toMatch("Gateio"); + expect(snapshot.base).toMatch("BTC"); + expect(snapshot.quote).toMatch("USDT"); + expect(snapshot.sequenceId).toBeUndefined(); + expect(typeof snapshot.asks[0].price).toBe("string"); + expect(typeof snapshot.asks[0].size).toBe("string"); + expect(typeof snapshot.bids[0].price).toBe("string"); + expect(typeof snapshot.bids[0].size).toBe("string"); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + hasSnapshot = true; + }); client.on("l2update", function level2UpdateHandler(update) { expect(update.fullId).toMatch("Gateio:BTC/USDT"); expect(update.exchange).toMatch("Gateio"); @@ -139,96 +138,18 @@ test( expect(parseFloat(update.bids[0].size)).toBeGreaterThanOrEqual(0); } - // Need to remove this listener, otherwise it is still running during subsequent tests - client.removeListener("l2update", level2UpdateHandler); - client.unsubscribeLevel2Updates(market1); - done(); - }); - }, - 30000 -); - -test( - "should subscribe and emit tickers for 2 markets", - done => { - let receivedMarket1Update = false, - receivedMarket2Update = false; - - client.subscribeTicker(market1); - client.subscribeTicker(market2); - - client.on("ticker", function tickerHandler(t) { - expect(t.base + t.quote).toMatch(/ETHUSDT|BTCUSDT/); - - if (t.base + t.quote === "ETHUSDT") { - receivedMarket1Update = true; - } else if (t.base + t.quote === "BTCUSDT") { - receivedMarket2Update = true; - } - - if (receivedMarket1Update && receivedMarket2Update) { - // Need to remove this listener, otherwise it is still running during subsequent tests - client.removeListener("ticker", tickerHandler); - client.unsubscribeTicker(market1); - client.unsubscribeTicker(market2); + if (hasSnapshot) { done(); } }); - }, - 30000 -); - -test( - "should subscribe and emit tickers for tickers, trades, and l2updates for the same market", - done => { - let receivedTickerUpdate = false, - receivedTradeUpdate = false, - receivedL2Update = false, - receivedTickerUpdateAfterOtherUpdates = false, - receivedTradeUpdateAfterOtherUpdates = false, - receivedL2UpdateAfterOtherUpdates = false; - - client.subscribeTicker(market1); - client.subscribeTrades(market1); - client.subscribeLevel2Updates(market1); + }, 30000); - client.on("ticker", t => { - expect(t.base + t.quote).toMatch("BTCUSDT"); - receivedTickerUpdate = true; - if (receivedTradeUpdate && receivedL2Update) { - receivedTickerUpdateAfterOtherUpdates = true; - } - }); - client.on("trade", t => { - expect(t.base + t.quote).toMatch("BTCUSDT"); - receivedTradeUpdate = true; - if (receivedTickerUpdate && receivedL2Update) { - receivedTradeUpdateAfterOtherUpdates = true; - } - }); - client.on("l2update", t => { - expect(t.base + t.quote).toMatch("BTCUSDT"); - receivedL2Update = true; - if (receivedTickerUpdate && receivedTradeUpdate) { - receivedL2UpdateAfterOtherUpdates = true; - } - }); + it("should unsubscribe from level2 updates", () => { + client.unsubscribeLevel2Updates(market1); + }); - var checkInterval = setInterval(() => { - if ( - receivedTickerUpdateAfterOtherUpdates && - receivedTradeUpdateAfterOtherUpdates && - receivedL2UpdateAfterOtherUpdates - ) { - clearInterval(checkInterval); - done(); - } - }, 500); - }, - 30000 -); - -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/gemini-client.spec.js b/src/exchanges/gemini-client.spec.js index fce9e018..3b61c150 100644 --- a/src/exchanges/gemini-client.spec.js +++ b/src/exchanges/gemini-client.spec.js @@ -14,72 +14,71 @@ let market2 = { quote: "USD", }; -beforeAll(() => { - client = new Gemini(); -}); - -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); +describe("GeminiClient", () => { + beforeAll(() => { + client = new Gemini(); + }); -test("it should not support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeFalsy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeTruthy(); -}); + test("it should not support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeFalsy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeTruthy(); + }); -test("it should not support level3 updates", () => { - expect(client.hasLevel3Updates).toBeFalsy(); -}); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); -// run first so we can capture snapshot -test("should subscribe and emit level2 snapshot and updates", done => { - let hasSnapshot = false; - client.subscribeLevel2Updates(market1); - client.on("l2snapshot", snapshot => { - hasSnapshot = true; - expect(snapshot.fullId).toMatch("Gemini:BTC/USD"); - expect(snapshot.exchange).toMatch("Gemini"); - expect(snapshot.base).toMatch("BTC"); - expect(snapshot.quote).toMatch("USD"); - expect(snapshot.sequenceId).toBeGreaterThan(0); - expect(snapshot.timestampMs).toBeUndefined(); - expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.asks[0].count).toBeUndefined(); - expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.bids[0].count).toBeUndefined(); + test("it should not support level3 updates", () => { + expect(client.hasLevel3Updates).toBeFalsy(); }); - client.on("l2update", update => { - expect(hasSnapshot).toBeTruthy(); - expect(update.fullId).toMatch("Gemini:BTC/USD"); - expect(update.exchange).toMatch("Gemini"); - expect(update.base).toMatch("BTC"); - expect(update.quote).toMatch("USD"); - expect(update.sequenceId).toBeGreaterThan(0); - expect(update.timestampMs).toBeGreaterThan(1522540800000); - let point = update.asks[0] || update.bids[0]; - expect(typeof point.price).toBe("string"); - expect(typeof point.size).toBe("string"); - expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); - expect(point.count).toBeUndefined(); - expect(point.meta.reason).toMatch(/(place|trade|cancel)/); - expect(parseFloat(point.meta.delta)).toBeDefined(); - done(); + + // run first so we can capture snapshot + test("should subscribe and emit level2 snapshot and updates", done => { + let hasSnapshot = false; + client.subscribeLevel2Updates(market1); + client.on("l2snapshot", snapshot => { + hasSnapshot = true; + expect(snapshot.fullId).toMatch("Gemini:BTC/USD"); + expect(snapshot.exchange).toMatch("Gemini"); + expect(snapshot.base).toMatch("BTC"); + expect(snapshot.quote).toMatch("USD"); + expect(snapshot.sequenceId).toBeGreaterThan(0); + expect(snapshot.timestampMs).toBeUndefined(); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.asks[0].count).toBeUndefined(); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.bids[0].count).toBeUndefined(); + }); + client.on("l2update", update => { + expect(hasSnapshot).toBeTruthy(); + expect(update.fullId).toMatch("Gemini:BTC/USD"); + expect(update.exchange).toMatch("Gemini"); + expect(update.base).toMatch("BTC"); + expect(update.quote).toMatch("USD"); + expect(update.sequenceId).toBeGreaterThan(0); + expect(update.timestampMs).toBeGreaterThan(1522540800000); + let point = update.asks[0] || update.bids[0]; + expect(typeof point.price).toBe("string"); + expect(typeof point.size).toBe("string"); + expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); + expect(point.count).toBeUndefined(); + expect(point.meta.reason).toMatch(/(place|trade|cancel)/); + expect(parseFloat(point.meta.delta)).toBeDefined(); + done(); + }); }); -}); -test( - "should subscribe and emit trade events", - done => { + test("should subscribe and emit trade events", done => { client.subscribeTrades(market1); client.subscribeTrades(market2); client.on("trade", trade => { @@ -96,20 +95,19 @@ test( expect(parseFloat(trade.amount)).toBeGreaterThan(0); done(); }); - }, - 60000 -); + }, 60000); -test("should unsubscribe from trades", () => { - client.unsubscribeTrades(market1); - client.unsubscribeTrades(market2); -}); + test("should unsubscribe from trades", () => { + client.unsubscribeTrades(market1); + client.unsubscribeTrades(market2); + }); -test("should unsubscribe from level2orders", () => { - client.unsubscribeLevel2Updates(market1); -}); + test("should unsubscribe from level2orders", () => { + client.unsubscribeLevel2Updates(market1); + }); -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/hitbtc-client.spec.js b/src/exchanges/hitbtc-client.spec.js index 4c8a7d18..29f4e6f7 100644 --- a/src/exchanges/hitbtc-client.spec.js +++ b/src/exchanges/hitbtc-client.spec.js @@ -9,37 +9,36 @@ let market = { quote: "BTC", }; -beforeAll(() => { - client = new HitBTC(); -}); +describe("HitBTC", () => { + beforeAll(() => { + client = new HitBTC(); + }); -test("it should support tickers", () => { - expect(client.hasTickers).toBeTruthy(); -}); + test("it should support tickers", () => { + expect(client.hasTickers).toBeTruthy(); + }); -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should not support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeFalsy(); -}); + test("it should not support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeFalsy(); + }); -test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeTruthy(); -}); + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeTruthy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); -test("it should not support level3 updates", () => { - expect(client.hasLevel3Updates).toBeFalsy(); -}); + test("it should not support level3 updates", () => { + expect(client.hasLevel3Updates).toBeFalsy(); + }); -test( - "should subscribe and emit ticker events", - done => { + test("should subscribe and emit ticker events", done => { client.subscribeTicker(market); client.on("ticker", ticker => { expect(ticker.fullId).toMatch("HitBTC:ETH/BTC"); @@ -68,13 +67,9 @@ test( expect(ticker.askVolume).toBeUndefined(); done(); }); - }, - 10000 -); + }, 10000); -test( - "should subscribe and emit trade events", - done => { + test("should subscribe and emit trade events", done => { client.subscribeTrades(market); client.on("trade", trade => { expect(trade.fullId).toMatch("HitBTC:ETH/BTC"); @@ -90,57 +85,56 @@ test( expect(parseFloat(trade.amount)).toBeGreaterThan(0); done(); }); - }, - 30000 -); + }, 30000); -test("should subscribe and emit level2 snapshot and updates", done => { - let hasSnapshot = false; - client.subscribeLevel2Updates(market); - client.on("l2snapshot", snapshot => { - hasSnapshot = true; - expect(snapshot.fullId).toMatch("HitBTC:ETH/BTC"); - expect(snapshot.exchange).toMatch("HitBTC"); - expect(snapshot.base).toMatch("ETH"); - expect(snapshot.quote).toMatch("BTC"); - expect(snapshot.sequenceId).toBeGreaterThan(0); - expect(snapshot.timestampMs).toBeUndefined(); - expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.asks[0].count).toBeUndefined(); - expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.bids[0].count).toBeUndefined(); - }); - client.on("l2update", update => { - expect(hasSnapshot).toBeTruthy(); - expect(update.fullId).toMatch("HitBTC:ETH/BTC"); - expect(update.exchange).toMatch("HitBTC"); - expect(update.base).toMatch("ETH"); - expect(update.quote).toMatch("BTC"); - expect(update.sequenceId).toBeGreaterThan(0); - expect(update.timestampMs).toBeUndefined(); - let point = update.asks[0] || update.bids[0]; - expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); - expect(point.count).toBeUndefined(); - done(); + test("should subscribe and emit level2 snapshot and updates", done => { + let hasSnapshot = false; + client.subscribeLevel2Updates(market); + client.on("l2snapshot", snapshot => { + hasSnapshot = true; + expect(snapshot.fullId).toMatch("HitBTC:ETH/BTC"); + expect(snapshot.exchange).toMatch("HitBTC"); + expect(snapshot.base).toMatch("ETH"); + expect(snapshot.quote).toMatch("BTC"); + expect(snapshot.sequenceId).toBeGreaterThan(0); + expect(snapshot.timestampMs).toBeUndefined(); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.asks[0].count).toBeUndefined(); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.bids[0].count).toBeUndefined(); + }); + client.on("l2update", update => { + expect(hasSnapshot).toBeTruthy(); + expect(update.fullId).toMatch("HitBTC:ETH/BTC"); + expect(update.exchange).toMatch("HitBTC"); + expect(update.base).toMatch("ETH"); + expect(update.quote).toMatch("BTC"); + expect(update.sequenceId).toBeGreaterThan(0); + expect(update.timestampMs).toBeUndefined(); + let point = update.asks[0] || update.bids[0]; + expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); + expect(point.count).toBeUndefined(); + done(); + }); }); -}); -test("should unsubscribe from tickers", () => { - client.unsubscribeTicker(market); -}); + test("should unsubscribe from tickers", () => { + client.unsubscribeTicker(market); + }); -test("should unsubscribe from trades", () => { - client.unsubscribeTrades(market); -}); + test("should unsubscribe from trades", () => { + client.unsubscribeTrades(market); + }); -test("should unusbscribe from level2 updates", () => { - client.unsubscribeLevel2Updates(market); -}); + test("should unusbscribe from level2 updates", () => { + client.unsubscribeLevel2Updates(market); + }); -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/huobi-client.spec.js b/src/exchanges/huobi-client.spec.js index b2328b73..a42f7d8c 100644 --- a/src/exchanges/huobi-client.spec.js +++ b/src/exchanges/huobi-client.spec.js @@ -9,37 +9,36 @@ let market = { quote: "USDT", }; -beforeAll(() => { - client = new HuobiClient(); -}); +describe("HuobiClient", () => { + beforeAll(() => { + client = new HuobiClient(); + }); -test("it should support tickers", () => { - expect(client.hasTickers).toBeTruthy(); -}); + test("it should support tickers", () => { + expect(client.hasTickers).toBeTruthy(); + }); -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeTruthy(); -}); + test("it should support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeTruthy(); + }); -test("it should not support level2 updates", () => { - expect(client.hasLevel2Updates).toBeFalsy(); -}); + test("it should not support level2 updates", () => { + expect(client.hasLevel2Updates).toBeFalsy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); -test("it should not support level3 updates", () => { - expect(client.hasLevel3Updates).toBeFalsy(); -}); + test("it should not support level3 updates", () => { + expect(client.hasLevel3Updates).toBeFalsy(); + }); -test( - "should subscribe and emit ticker events", - done => { + test("should subscribe and emit ticker events", done => { client.subscribeTicker(market); client.on("ticker", ticker => { expect(ticker.fullId).toMatch("Huobi:BTC/USDT"); @@ -66,13 +65,9 @@ test( expect(ticker.askVolume).toBeUndefined(); done(); }); - }, - 10000 -); + }, 10000); -test( - "should subscribe and emit trade events", - done => { + test("should subscribe and emit trade events", done => { client.subscribeTrades(market); client.on("trade", trade => { expect(trade.fullId).toMatch("Huobi:BTC/USDT"); @@ -88,38 +83,37 @@ test( expect(parseFloat(trade.amount)).toBeGreaterThan(0); done(); }); - }, - 30000 -); + }, 30000); -test("should subscribe and emit level2 snapshots", done => { - client.subscribeLevel2Snapshots(market); - client.on("l2snapshot", snapshot => { - expect(snapshot.fullId).toMatch("Huobi:BTC/USDT"); - expect(snapshot.exchange).toMatch("Huobi"); - expect(snapshot.base).toMatch("BTC"); - expect(snapshot.quote).toMatch("USDT"); - expect(snapshot.sequenceId).toBeUndefined(); - expect(snapshot.timestampMs).toBeGreaterThan(0); - expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.asks[0].count).toBeUndefined(); - expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.bids[0].count).toBeUndefined(); - done(); + test("should subscribe and emit level2 snapshots", done => { + client.subscribeLevel2Snapshots(market); + client.on("l2snapshot", snapshot => { + expect(snapshot.fullId).toMatch("Huobi:BTC/USDT"); + expect(snapshot.exchange).toMatch("Huobi"); + expect(snapshot.base).toMatch("BTC"); + expect(snapshot.quote).toMatch("USDT"); + expect(snapshot.sequenceId).toBeUndefined(); + expect(snapshot.timestampMs).toBeGreaterThan(0); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.asks[0].count).toBeUndefined(); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.bids[0].count).toBeUndefined(); + done(); + }); }); -}); -test("should unsubscribe trades", () => { - client.unsubscribeTrades(market); -}); + test("should unsubscribe trades", () => { + client.unsubscribeTrades(market); + }); -test("should unsubscribe level2 snapshots", () => { - client.unsubscribeLevel2Snapshots(market); -}); + test("should unsubscribe level2 snapshots", () => { + client.unsubscribeLevel2Snapshots(market); + }); -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/kraken-client.spec.js b/src/exchanges/kraken-client.spec.js index 88db6a7b..1a80f3de 100644 --- a/src/exchanges/kraken-client.spec.js +++ b/src/exchanges/kraken-client.spec.js @@ -8,177 +8,179 @@ function wait(timeout = 1000) { }); } -describe("kraken-client", () => { - let client; - const market1 = { - id: "XXBTZEUR", - base: "BTC", - quote: "EUR", - }; - - describe("properties", () => { - beforeAll(() => { - client = new Kraken(); - }); - - test("it should support tickers", () => { - expect(client.hasTickers).toBeTruthy(); - }); +describe("KrakenClient", () => { + describe("kraken-client", () => { + let client; + const market1 = { + id: "XXBTZEUR", + base: "BTC", + quote: "EUR", + }; + + describe("properties", () => { + beforeAll(() => { + client = new Kraken(); + }); - test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); - }); + test("it should support tickers", () => { + expect(client.hasTickers).toBeTruthy(); + }); - test("it should not support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeFalsy(); - }); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); - test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeTruthy(); - }); + test("it should not support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeFalsy(); + }); - test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); - }); + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeTruthy(); + }); - test("it should not support level3 updates", () => { - expect(client.hasLevel3Updates).toBeFalsy(); - }); - }); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); - describe("integration", () => { - beforeAll(async () => { - client = new Kraken(); - await client.loadSymbolMaps(); + test("it should not support level3 updates", () => { + expect(client.hasLevel3Updates).toBeFalsy(); + }); }); - test("should subscribe and emit ticker events", done => { - client.subscribeTicker(market1); - client.on("ticker", ticker => { - expect(ticker.fullId).toMatch("Kraken:" + market1.base + "/" + market1.quote); - expect(ticker.timestamp).toBeGreaterThan(1531677480465); - expect(typeof ticker.last).toBe("string"); - expect(typeof ticker.open).toBe("string"); - expect(typeof ticker.high).toBe("string"); - expect(typeof ticker.low).toBe("string"); - expect(typeof ticker.volume).toBe("string"); - expect(typeof ticker.quoteVolume).toBe("string"); - expect(typeof ticker.change).toBe("string"); - expect(typeof ticker.changePercent).toBe("string"); - expect(typeof ticker.bid).toBe("string"); - expect(typeof ticker.bidVolume).toBe("string"); - expect(typeof ticker.ask).toBe("string"); - expect(typeof ticker.askVolume).toBe("string"); - expect(parseFloat(ticker.last)).toBeGreaterThan(0); - expect(parseFloat(ticker.open)).toBeGreaterThan(0); - expect(parseFloat(ticker.high)).toBeGreaterThan(0); - expect(parseFloat(ticker.low)).toBeGreaterThan(0); - expect(parseFloat(ticker.volume)).toBeGreaterThan(0); - expect(parseFloat(ticker.quoteVolume)).toBeGreaterThan(0); - expect(isNaN(parseFloat(ticker.change))).toBeFalsy(); - expect(isNaN(parseFloat(ticker.changePercent))).toBeFalsy(); - expect(parseFloat(ticker.bid)).toBeGreaterThan(0); - expect(parseFloat(ticker.bidVolume)).toBeGreaterThan(0); - expect(parseFloat(ticker.ask)).toBeGreaterThan(0); - expect(parseFloat(ticker.askVolume)).toBeGreaterThan(0); - done(); - }); - }, 30000); - - test("should unsubscribe from ticker events", async () => { - client.unsubscribeTicker(market1); - await wait(); - }, 30000); - - test("should subscribe and emit trade events", done => { - client.subscribeTrades(market1); - client.on("trade", trade => { - expect(trade.fullId).toMatch("Kraken:" + market1.base + "/" + market1.quote); - expect(trade.exchange).toMatch("Kraken"); - expect(trade.base).toMatch(market1.base); - expect(trade.quote).toMatch(market1.quote); - expect(trade.tradeId).toMatch(/\d{19,}/); - expect(trade.unix).toBeGreaterThan(1522540800000); - expect(trade.side).toMatch(/buy|sell/); - expect(typeof trade.price).toBe("string"); - expect(typeof trade.amount).toBe("string"); - expect(parseFloat(trade.price)).toBeGreaterThan(0); - expect(parseFloat(trade.amount)).toBeGreaterThan(0); - done(); + describe("integration", () => { + beforeAll(async () => { + client = new Kraken(); + await client.loadSymbolMaps(); }); - }, 30000); - test("should unsubscribe from trade events", async () => { - client.unsubscribeTrades(market1); - await wait(); - }, 30000); + test("should subscribe and emit ticker events", done => { + client.subscribeTicker(market1); + client.on("ticker", ticker => { + expect(ticker.fullId).toMatch("Kraken:" + market1.base + "/" + market1.quote); + expect(ticker.timestamp).toBeGreaterThan(1531677480465); + expect(typeof ticker.last).toBe("string"); + expect(typeof ticker.open).toBe("string"); + expect(typeof ticker.high).toBe("string"); + expect(typeof ticker.low).toBe("string"); + expect(typeof ticker.volume).toBe("string"); + expect(typeof ticker.quoteVolume).toBe("string"); + expect(typeof ticker.change).toBe("string"); + expect(typeof ticker.changePercent).toBe("string"); + expect(typeof ticker.bid).toBe("string"); + expect(typeof ticker.bidVolume).toBe("string"); + expect(typeof ticker.ask).toBe("string"); + expect(typeof ticker.askVolume).toBe("string"); + expect(parseFloat(ticker.last)).toBeGreaterThan(0); + expect(parseFloat(ticker.open)).toBeGreaterThan(0); + expect(parseFloat(ticker.high)).toBeGreaterThan(0); + expect(parseFloat(ticker.low)).toBeGreaterThan(0); + expect(parseFloat(ticker.volume)).toBeGreaterThan(0); + expect(parseFloat(ticker.quoteVolume)).toBeGreaterThan(0); + expect(isNaN(parseFloat(ticker.change))).toBeFalsy(); + expect(isNaN(parseFloat(ticker.changePercent))).toBeFalsy(); + expect(parseFloat(ticker.bid)).toBeGreaterThan(0); + expect(parseFloat(ticker.bidVolume)).toBeGreaterThan(0); + expect(parseFloat(ticker.ask)).toBeGreaterThan(0); + expect(parseFloat(ticker.askVolume)).toBeGreaterThan(0); + done(); + }); + }, 30000); + + test("should unsubscribe from ticker events", async () => { + client.unsubscribeTicker(market1); + await wait(); + }, 30000); + + test("should subscribe and emit trade events", done => { + client.subscribeTrades(market1); + client.on("trade", trade => { + expect(trade.fullId).toMatch("Kraken:" + market1.base + "/" + market1.quote); + expect(trade.exchange).toMatch("Kraken"); + expect(trade.base).toMatch(market1.base); + expect(trade.quote).toMatch(market1.quote); + expect(trade.tradeId).toMatch(/\d{19,}/); + expect(trade.unix).toBeGreaterThan(1522540800000); + expect(trade.side).toMatch(/buy|sell/); + expect(typeof trade.price).toBe("string"); + expect(typeof trade.amount).toBe("string"); + expect(parseFloat(trade.price)).toBeGreaterThan(0); + expect(parseFloat(trade.amount)).toBeGreaterThan(0); + done(); + }); + }, 30000); - test("should subscribe and emit l2orderbook snapshot and updates", done => { - let hasL2Snapshot = false; - let hasL2AskUpdate = false; - let hasL2BidUpdate = false; + test("should unsubscribe from trade events", async () => { + client.unsubscribeTrades(market1); + await wait(); + }, 30000); - client.subscribeLevel2Updates(market1); + test("should subscribe and emit l2orderbook snapshot and updates", done => { + let hasL2Snapshot = false; + let hasL2AskUpdate = false; + let hasL2BidUpdate = false; - function fin() { - if (hasL2Snapshot && hasL2AskUpdate && hasL2BidUpdate) { - done(); - } - } - - client.on("l2snapshot", s => { - expect(s.fullId).toBe("Kraken:BTC/EUR"); - expect(s.exchange).toBe("Kraken"); - expect(s.base).toBe("BTC"); - expect(s.quote).toBe("EUR"); - expect(s.timestampMs).toBeGreaterThan(1522540800000); - expect(s.asks.length).toBeGreaterThan(0); - expect(s.bids.length).toBeGreaterThan(0); - expect(typeof s.asks[0].price).toBe("string"); - expect(typeof s.asks[0].size).toBe("string"); - expect(typeof s.bids[0].price).toBe("string"); - expect(typeof s.bids[0].size).toBe("string"); - expect(parseFloat(s.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(s.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(parseFloat(s.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(s.bids[0].size)).toBeGreaterThanOrEqual(0); - hasL2Snapshot = true; - fin(); - }); - client.on("l2update", u => { - expect(u.fullId).toBe("Kraken:BTC/EUR"); - expect(u.exchange).toBe("Kraken"); - expect(u.base).toBe("BTC"); - expect(u.quote).toBe("EUR"); - expect(u.timestampMs).toBeGreaterThan(1522540800000); - expect(u.asks.length || u.bids.length).toBeGreaterThan(0); - if (u.asks.length) { - expect(typeof u.asks[0].price).toBe("string"); - expect(typeof u.asks[0].size).toBe("string"); - expect(parseFloat(u.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(u.asks[0].size)).toBeGreaterThanOrEqual(0); - hasL2AskUpdate = true; - } + client.subscribeLevel2Updates(market1); - if (u.bids.length) { - expect(typeof u.bids[0].price).toBe("string"); - expect(typeof u.bids[0].size).toBe("string"); - expect(parseFloat(u.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(u.bids[0].size)).toBeGreaterThanOrEqual(0); - hasL2BidUpdate = true; + function fin() { + if (hasL2Snapshot && hasL2AskUpdate && hasL2BidUpdate) { + done(); + } } - fin(); - }); - }, 30000); - - test("should unsubscribe from l2 orderbook events", async () => { - client.unsubscribeLevel2Updates(market1); - await wait(); - }, 30000); - test("should close connections", done => { - client.on("closed", done); - client.close(); + client.on("l2snapshot", s => { + expect(s.fullId).toBe("Kraken:BTC/EUR"); + expect(s.exchange).toBe("Kraken"); + expect(s.base).toBe("BTC"); + expect(s.quote).toBe("EUR"); + expect(s.timestampMs).toBeGreaterThan(1522540800000); + expect(s.asks.length).toBeGreaterThan(0); + expect(s.bids.length).toBeGreaterThan(0); + expect(typeof s.asks[0].price).toBe("string"); + expect(typeof s.asks[0].size).toBe("string"); + expect(typeof s.bids[0].price).toBe("string"); + expect(typeof s.bids[0].size).toBe("string"); + expect(parseFloat(s.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(s.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(parseFloat(s.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(s.bids[0].size)).toBeGreaterThanOrEqual(0); + hasL2Snapshot = true; + fin(); + }); + client.on("l2update", u => { + expect(u.fullId).toBe("Kraken:BTC/EUR"); + expect(u.exchange).toBe("Kraken"); + expect(u.base).toBe("BTC"); + expect(u.quote).toBe("EUR"); + expect(u.timestampMs).toBeGreaterThan(1522540800000); + expect(u.asks.length || u.bids.length).toBeGreaterThan(0); + if (u.asks.length) { + expect(typeof u.asks[0].price).toBe("string"); + expect(typeof u.asks[0].size).toBe("string"); + expect(parseFloat(u.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(u.asks[0].size)).toBeGreaterThanOrEqual(0); + hasL2AskUpdate = true; + } + + if (u.bids.length) { + expect(typeof u.bids[0].price).toBe("string"); + expect(typeof u.bids[0].size).toBe("string"); + expect(parseFloat(u.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(u.bids[0].size)).toBeGreaterThanOrEqual(0); + hasL2BidUpdate = true; + } + fin(); + }); + }, 30000); + + test("should unsubscribe from l2 orderbook events", async () => { + client.unsubscribeLevel2Updates(market1); + await wait(); + }, 30000); + + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); }); }); diff --git a/src/exchanges/okex-client.spec.js b/src/exchanges/okex-client.spec.js index a865252d..b1177ba9 100644 --- a/src/exchanges/okex-client.spec.js +++ b/src/exchanges/okex-client.spec.js @@ -9,37 +9,36 @@ let market = { quote: "USDT", }; -beforeAll(() => { - client = new OKEx(); -}); +describe("OkEXClient", () => { + beforeAll(() => { + client = new OKEx(); + }); -test("it should support tickers", () => { - expect(client.hasTickers).toBeTruthy(); -}); + test("it should support tickers", () => { + expect(client.hasTickers).toBeTruthy(); + }); -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeTruthy(); -}); + test("it should support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeTruthy(); + }); -test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeTruthy(); -}); + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeTruthy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); -test("it should not support level3 updates", () => { - expect(client.hasLevel3Updates).toBeFalsy(); -}); + test("it should not support level3 updates", () => { + expect(client.hasLevel3Updates).toBeFalsy(); + }); -test( - "should subscribe and emit ticker events", - done => { + test("should subscribe and emit ticker events", done => { client.subscribeTicker(market); client.on("ticker", ticker => { expect(ticker.fullId).toMatch("OKEx:BTC/USDT"); @@ -66,13 +65,9 @@ test( expect(ticker.askVolume).toBeUndefined(); done(); }); - }, - 10000 -); + }, 10000); -test( - "should subscribe and emit trade events", - done => { + test("should subscribe and emit trade events", done => { client.subscribeTrades(market); client.on("trade", trade => { expect(trade.fullId).toMatch("OKEx:BTC/USDT"); @@ -88,13 +83,9 @@ test( expect(parseFloat(trade.amount)).toBeGreaterThan(0); done(); }); - }, - 30000 -); + }, 30000); -test( - "should subscribe and emit level2 updates", - done => { + test("should subscribe and emit level2 updates", done => { let hasSnapshot = false; client.subscribeLevel2Updates(market); client.on("l2snapshot", snapshot => { @@ -126,13 +117,9 @@ test( expect(point.count).toBeUndefined(); done(); }); - }, - 30000 -); + }, 30000); -test( - "should subscribe and emit level2 snapshots", - done => { + test("should subscribe and emit level2 snapshots", done => { client.subscribeLevel2Snapshots(market); client.on("l2snapshot", snapshot => { expect(snapshot.fullId).toMatch("OKEx:BTC/USDT"); @@ -149,27 +136,26 @@ test( expect(snapshot.bids[0].count).toBeUndefined(); done(); }); - }, - 30000 -); + }, 30000); -test("should unsubscribe from tickers", () => { - client.unsubscribeTicker(market); -}); + test("should unsubscribe from tickers", () => { + client.unsubscribeTicker(market); + }); -test("should unsubscribe from trades", () => { - client.unsubscribeTrades(market); -}); + test("should unsubscribe from trades", () => { + client.unsubscribeTrades(market); + }); -test("should unsubscribe from level2 snapshots", () => { - client.unsubscribeLevel2Snapshots(market); -}); + test("should unsubscribe from level2 snapshots", () => { + client.unsubscribeLevel2Snapshots(market); + }); -test("should unsubscribe from level2 updates", () => { - client.unsubscribeLevel2Updates(market); -}); + test("should unsubscribe from level2 updates", () => { + client.unsubscribeLevel2Updates(market); + }); -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/poloniex-client.spec.js b/src/exchanges/poloniex-client.spec.js index 13dafdbc..9f4c6462 100644 --- a/src/exchanges/poloniex-client.spec.js +++ b/src/exchanges/poloniex-client.spec.js @@ -8,38 +8,42 @@ let market = { base: "BTC", quote: "USDT", }; +let market2 = { + id: "BTC_ETH", + base: "ETH", + quote: "USD", +}; -beforeAll(() => { - client = new Poloniex(); -}); +describe("PoloniexClient", () => { + beforeAll(() => { + client = new Poloniex(); + }); -test("it should support tickers", () => { - expect(client.hasTickers).toBeTruthy(); -}); + test("it should support tickers", () => { + expect(client.hasTickers).toBeTruthy(); + }); -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should not support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeFalsy(); -}); + test("it should not support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeFalsy(); + }); -test("it should support level2 updates", () => { - expect(client.hasLevel2Updates).toBeTruthy(); -}); + test("it should support level2 updates", () => { + expect(client.hasLevel2Updates).toBeTruthy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); -test("it should not support level3 updates", () => { - expect(client.hasLevel3Updates).toBeFalsy(); -}); + test("it should not support level3 updates", () => { + expect(client.hasLevel3Updates).toBeFalsy(); + }); -test( - "should subscribe and emit ticker events", - done => { + test("should subscribe and emit ticker events", done => { client.subscribeTicker(market); client.on("ticker", ticker => { expect(ticker.fullId).toMatch("Poloniex:BTC/USDT"); @@ -68,54 +72,51 @@ test( expect(ticker.askVolume).toBeUndefined(); done(); }); - }, - 90000 -); + }, 90000); -// run first so we can capture snapshot -test("should subscribe and emit level2 snapshot and updates", done => { - let hasSnapshot = false; - client.subscribeLevel2Updates(market); - client.on("l2snapshot", snapshot => { - hasSnapshot = true; - expect(snapshot.fullId).toMatch("Poloniex:BTC/USDT"); - expect(snapshot.exchange).toMatch("Poloniex"); - expect(snapshot.base).toMatch("BTC"); - expect(snapshot.quote).toMatch("USDT"); - expect(snapshot.sequenceId).toBeGreaterThan(0); - expect(snapshot.timestampMs).toBeUndefined(); - expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.asks[0].count).toBeUndefined(); - expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.bids[0].count).toBeUndefined(); - }); - client.on("l2update", update => { - expect(hasSnapshot).toBeTruthy(); - expect(update.fullId).toMatch("Poloniex:BTC/USDT"); - expect(update.exchange).toMatch("Poloniex"); - expect(update.base).toMatch("BTC"); - expect(update.quote).toMatch("USDT"); - expect(update.sequenceId).toBeGreaterThan(0); - expect(update.timestampMs).toBeUndefined(); - let point = update.asks[0] || update.bids[0]; - expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); - expect(point.count).toBeUndefined(); - done(); + // run first so we can capture snapshot + test("should subscribe and emit level2 snapshot and updates", done => { + let hasSnapshot = false; + client.subscribeLevel2Updates(market); + client.on("l2snapshot", snapshot => { + hasSnapshot = true; + expect(snapshot.fullId).toMatch("Poloniex:BTC/USDT"); + expect(snapshot.exchange).toMatch("Poloniex"); + expect(snapshot.base).toMatch("BTC"); + expect(snapshot.quote).toMatch("USDT"); + expect(snapshot.sequenceId).toBeGreaterThan(0); + expect(snapshot.timestampMs).toBeUndefined(); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.asks[0].count).toBeUndefined(); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.bids[0].count).toBeUndefined(); + }); + client.on("l2update", update => { + expect(hasSnapshot).toBeTruthy(); + expect(update.fullId).toMatch("Poloniex:BTC/USDT"); + expect(update.exchange).toMatch("Poloniex"); + expect(update.base).toMatch("BTC"); + expect(update.quote).toMatch("USDT"); + expect(update.sequenceId).toBeGreaterThan(0); + expect(update.timestampMs).toBeUndefined(); + let point = update.asks[0] || update.bids[0]; + expect(parseFloat(point.price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(point.size)).toBeGreaterThanOrEqual(0); + expect(point.count).toBeUndefined(); + done(); + }); }); -}); -test( - "should subscribe and emit trade events", - done => { + test("should subscribe and emit trade events", done => { client.subscribeTrades(market); + client.subscribeTrades(market2); client.on("trade", trade => { - expect(trade.fullId).toMatch("Poloniex:BTC/USDT"); + expect(trade.fullId).toMatch(/Poloniex:BTC\/USDT|Poloniex:ETH\/BTC/); expect(trade.exchange).toMatch("Poloniex"); - expect(trade.base).toMatch("BTC"); - expect(trade.quote).toMatch("USDT"); + expect(trade.base).toMatch(/BTC|ETH/); + expect(trade.quote).toMatch(/USDT|BTC/); expect(trade.tradeId).toBeGreaterThan(0); expect(trade.unix).toBeGreaterThan(1522540800000); expect(trade.side).toMatch(/buy|sell/); @@ -125,23 +126,22 @@ test( expect(parseFloat(trade.amount)).toBeGreaterThan(0); done(); }); - }, - 90000 -); + }, 90000); -test("should unsubscribe from tickers", () => { - client.unsubscribeTicker(market); -}); + test("should unsubscribe from tickers", () => { + client.unsubscribeTicker(market); + }); -test("should unsubscribe from trades", () => { - client.unsubscribeTrades(market); -}); + test("should unsubscribe from trades", () => { + client.unsubscribeTrades(market); + }); -test("should unsubscribe from level2 updates", () => { - client.unsubscribeLevel2Updates(market); -}); + test("should unsubscribe from level2 updates", () => { + client.unsubscribeLevel2Updates(market); + }); -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); }); diff --git a/src/exchanges/upbit-client.spec.js b/src/exchanges/upbit-client.spec.js index bbea6b74..b06359c5 100644 --- a/src/exchanges/upbit-client.spec.js +++ b/src/exchanges/upbit-client.spec.js @@ -8,7 +8,7 @@ function wait(timeout = 1000) { }); } -describe("upbit-client", () => { +describe("UpbitClient", () => { let client; const market1 = { id: "KRW-BTC", @@ -54,184 +54,152 @@ describe("upbit-client", () => { expect(client.hasLevel3Updates).toBeFalsy(); }); - test( - "should subscribe and emit ticker events", - done => { - client.subscribeTicker(market1); - client.on("ticker", ticker => { - expect(ticker.fullId).toMatch("Upbit:" + market1.base + "/" + market1.quote); - expect(ticker.timestamp).toBeGreaterThan(1531677480465); - expect(typeof ticker.last).toBe("string"); - expect(typeof ticker.open).toBe("string"); - expect(typeof ticker.high).toBe("string"); - expect(typeof ticker.low).toBe("string"); - expect(typeof ticker.volume).toBe("string"); - expect(typeof ticker.quoteVolume).toBe("string"); - expect(typeof ticker.change).toBe("string"); - expect(typeof ticker.changePercent).toBe("string"); - expect(typeof ticker.bid).toBe("undefined"); - expect(typeof ticker.bidVolume).toBe("undefined"); - expect(typeof ticker.ask).toBe("undefined"); - expect(typeof ticker.askVolume).toBe("undefined"); - expect(parseFloat(ticker.last)).toBeGreaterThan(0); - expect(parseFloat(ticker.open)).toBeGreaterThan(0); - expect(parseFloat(ticker.high)).toBeGreaterThan(0); - expect(parseFloat(ticker.low)).toBeGreaterThan(0); - expect(parseFloat(ticker.volume)).toBeGreaterThan(0); - expect(parseFloat(ticker.quoteVolume)).toBeGreaterThan(0); - expect(isNaN(parseFloat(ticker.change))).toBeFalsy(); - expect(isNaN(parseFloat(ticker.changePercent))).toBeFalsy(); - done(); - }); - }, - 30000 - ); - - test( - "should unsubscribe from ticker events", - async () => { - client = new Upbit(); - client.subscribeTicker(market1); - await wait(); - client.unsubscribeTicker(market1); - await wait(); - }, - 30000 - ); - - test( - "should subscribe and emit trade events", - done => { - client.subscribeTrades(market1); - client.on("trade", trade => { - expect(trade.fullId).toMatch("Upbit:" + market1.base + "/" + market1.quote); - expect(trade.exchange).toMatch("Upbit"); - expect(trade.base).toMatch(market1.base); - expect(trade.quote).toMatch(market1.quote); - expect(trade.unix).toBeGreaterThan(1522540800000); - expect(trade.side).toMatch(/buy|sell/); - expect(typeof trade.price).toBe("string"); - expect(typeof trade.amount).toBe("string"); - expect(typeof trade.tradeId).toBe("string"); - expect(parseFloat(trade.tradeId)).toBeGreaterThan(0); - expect(parseFloat(trade.price)).toBeGreaterThan(0); - expect(parseFloat(trade.amount)).toBeGreaterThan(0); - done(); - }); - }, - 30000 - ); - - test( - "should unsubscribe from trade events", - async () => { - client.subscribeTrades(market1); - await wait(); - client.unsubscribeTrades(market1); - await wait(); - }, - 30000 - ); - - test( - "should subscribe and emit level2 snapshots", - done => { - client.subscribeLevel2Snapshots(market1); - client.on("l2snapshot", update => { - expect(update.fullId).toMatch("Upbit:" + market1.base + "/" + market1.quote); - expect(update.exchange).toMatch("Upbit"); - expect(update.base).toMatch(market1.base); - expect(update.quote).toMatch(market1.quote); - expect(update.sequenceId).toBeUndefined(); - expect(update.timestampMs).toBeGreaterThan(1522540800000); - expect(update.asks.length).toBeGreaterThan(0); - expect(update.bids.length).toBeGreaterThan(0); - expect(typeof update.asks[0].price).toBe("string"); - expect(typeof update.asks[0].size).toBe("string"); - expect(typeof update.bids[0].price).toBe("string"); - expect(typeof update.bids[0].size).toBe("string"); - expect(parseFloat(update.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(update.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(parseFloat(update.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(update.bids[0].size)).toBeGreaterThanOrEqual(0); + test("should subscribe and emit ticker events", done => { + client.subscribeTicker(market1); + client.on("ticker", ticker => { + expect(ticker.fullId).toMatch("Upbit:" + market1.base + "/" + market1.quote); + expect(ticker.timestamp).toBeGreaterThan(1531677480465); + expect(typeof ticker.last).toBe("string"); + expect(typeof ticker.open).toBe("string"); + expect(typeof ticker.high).toBe("string"); + expect(typeof ticker.low).toBe("string"); + expect(typeof ticker.volume).toBe("string"); + expect(typeof ticker.quoteVolume).toBe("string"); + expect(typeof ticker.change).toBe("string"); + expect(typeof ticker.changePercent).toBe("string"); + expect(typeof ticker.bid).toBe("undefined"); + expect(typeof ticker.bidVolume).toBe("undefined"); + expect(typeof ticker.ask).toBe("undefined"); + expect(typeof ticker.askVolume).toBe("undefined"); + expect(parseFloat(ticker.last)).toBeGreaterThan(0); + expect(parseFloat(ticker.open)).toBeGreaterThan(0); + expect(parseFloat(ticker.high)).toBeGreaterThan(0); + expect(parseFloat(ticker.low)).toBeGreaterThan(0); + expect(parseFloat(ticker.volume)).toBeGreaterThan(0); + expect(parseFloat(ticker.quoteVolume)).toBeGreaterThan(0); + expect(isNaN(parseFloat(ticker.change))).toBeFalsy(); + expect(isNaN(parseFloat(ticker.changePercent))).toBeFalsy(); + done(); + }); + }, 30000); + + test("should unsubscribe from ticker events", async () => { + client = new Upbit(); + client.subscribeTicker(market1); + await wait(); + client.unsubscribeTicker(market1); + await wait(); + }, 30000); + + test("should subscribe and emit trade events", done => { + client.subscribeTrades(market1); + client.on("trade", trade => { + expect(trade.fullId).toMatch("Upbit:" + market1.base + "/" + market1.quote); + expect(trade.exchange).toMatch("Upbit"); + expect(trade.base).toMatch(market1.base); + expect(trade.quote).toMatch(market1.quote); + expect(trade.unix).toBeGreaterThan(1522540800000); + expect(trade.side).toMatch(/buy|sell/); + expect(typeof trade.price).toBe("string"); + expect(typeof trade.amount).toBe("string"); + expect(typeof trade.tradeId).toBe("string"); + expect(parseFloat(trade.tradeId)).toBeGreaterThan(0); + expect(parseFloat(trade.price)).toBeGreaterThan(0); + expect(parseFloat(trade.amount)).toBeGreaterThan(0); + done(); + }); + }, 30000); + + test("should unsubscribe from trade events", async () => { + client.subscribeTrades(market1); + await wait(); + client.unsubscribeTrades(market1); + await wait(); + }, 30000); + + test("should subscribe and emit level2 snapshots", done => { + client.subscribeLevel2Snapshots(market1); + client.on("l2snapshot", update => { + expect(update.fullId).toMatch("Upbit:" + market1.base + "/" + market1.quote); + expect(update.exchange).toMatch("Upbit"); + expect(update.base).toMatch(market1.base); + expect(update.quote).toMatch(market1.quote); + expect(update.sequenceId).toBeUndefined(); + expect(update.timestampMs).toBeGreaterThan(1522540800000); + expect(update.asks.length).toBeGreaterThan(0); + expect(update.bids.length).toBeGreaterThan(0); + expect(typeof update.asks[0].price).toBe("string"); + expect(typeof update.asks[0].size).toBe("string"); + expect(typeof update.bids[0].price).toBe("string"); + expect(typeof update.bids[0].size).toBe("string"); + expect(parseFloat(update.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(update.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(parseFloat(update.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(update.bids[0].size)).toBeGreaterThanOrEqual(0); + done(); + }); + }, 30000); + + test("should unsubscribe from l2 orderbook events", async () => { + client.subscribeLevel2Snapshots(market1); + await wait(); + client.unsubscribeLevel2Snapshots(market1); + await wait(); + }, 30000); + + test("should subscribe and emit tickers for tickers, trades, and l2orderbook for the same market", done => { + let hasTicker = false; + let hasTrade = false; + let hasL2Snap = false; + + client.subscribeTicker(market1); + client.subscribeTrades(market1); + client.subscribeLevel2Snapshots(market1); + + function fin() { + if (hasTrade && hasL2Snap && hasTicker) { done(); - }); - }, - 30000 - ); - - test( - "should unsubscribe from l2 orderbook events", - async () => { - client.subscribeLevel2Snapshots(market1); - await wait(); - client.unsubscribeLevel2Snapshots(market1); - await wait(); - }, - 30000 - ); - - test( - "should subscribe and emit tickers for tickers, trades, and l2orderbook for the same market", - done => { - let hasTicker = false; - let hasTrade = false; - let hasL2Snap = false; - - client.subscribeTicker(market1); - client.subscribeTrades(market1); - client.subscribeLevel2Snapshots(market1); - - function fin() { - if (hasTrade && hasL2Snap && hasTicker) { - done(); - } + } + } + + client.on("ticker", t => { + expect(t.base + t.quote).toMatch(/KRWBTT|KRWBTC/); + hasTicker = true; + fin(); + }); + client.on("trade", t => { + expect(t.base + t.quote).toMatch(/KRWBTT|KRWBTC/); + hasTrade = true; + fin(); + }); + client.on("l2snapshot", t => { + expect(t.base + t.quote).toMatch(/KRWBTT|KRWBTC/); + hasL2Snap = true; + fin(); + }); + }, 30000); + + test("should subscribe and emit trades for 2 markets", done => { + let hasMarket1 = false; + let hasMarket2 = false; + + client.subscribeTrades(market1); + client.subscribeTrades(market2); + + client.on("trade", trade => { + expect(trade.base + trade.quote).toMatch(/KRWBTT|KRWBTC/); + + if (trade.base + trade.quote === market1.base + market1.quote) { + hasMarket1 = true; + } else if (trade.base + trade.quote === market2.base + market2.quote) { + hasMarket2 = true; } - client.on("ticker", t => { - expect(t.base + t.quote).toMatch(/KRWBTT|KRWBTC/); - hasTicker = true; - fin(); - }); - client.on("trade", t => { - expect(t.base + t.quote).toMatch(/KRWBTT|KRWBTC/); - hasTrade = true; - fin(); - }); - client.on("l2snapshot", t => { - expect(t.base + t.quote).toMatch(/KRWBTT|KRWBTC/); - hasL2Snap = true; - fin(); - }); - }, - 30000 - ); - - test( - "should subscribe and emit trades for 2 markets", - done => { - let hasMarket1 = false; - let hasMarket2 = false; - - client.subscribeTrades(market1); - client.subscribeTrades(market2); - - client.on("trade", trade => { - expect(trade.base + trade.quote).toMatch(/KRWBTT|KRWBTC/); - - if (trade.base + trade.quote === market1.base + market1.quote) { - hasMarket1 = true; - } else if (trade.base + trade.quote === market2.base + market2.quote) { - hasMarket2 = true; - } - - if (hasMarket1 && hasMarket2) { - done(); - } - }); - }, - 60000 - ); + if (hasMarket1 && hasMarket2) { + done(); + } + }); + }, 60000); test("should close connections", done => { client.on("closed", done); diff --git a/src/exchanges/zb-client.spec.js b/src/exchanges/zb-client.spec.js index 023a90e2..66522fec 100644 --- a/src/exchanges/zb-client.spec.js +++ b/src/exchanges/zb-client.spec.js @@ -9,37 +9,36 @@ let market = { quote: "USDT", }; -beforeAll(() => { - client = new ZBClient(); -}); +describe("ZBClient", () => { + beforeAll(() => { + client = new ZBClient(); + }); -test("it should support tickers", () => { - expect(client.hasTickers).toBeTruthy(); -}); + test("it should support tickers", () => { + expect(client.hasTickers).toBeTruthy(); + }); -test("it should support trades", () => { - expect(client.hasTrades).toBeTruthy(); -}); + test("it should support trades", () => { + expect(client.hasTrades).toBeTruthy(); + }); -test("it should support level2 snapshots", () => { - expect(client.hasLevel2Snapshots).toBeTruthy(); -}); + test("it should support level2 snapshots", () => { + expect(client.hasLevel2Snapshots).toBeTruthy(); + }); -test("it should not support level2 updates", () => { - expect(client.hasLevel2Updates).toBeFalsy(); -}); + test("it should not support level2 updates", () => { + expect(client.hasLevel2Updates).toBeFalsy(); + }); -test("it should not support level3 snapshots", () => { - expect(client.hasLevel3Snapshots).toBeFalsy(); -}); + test("it should not support level3 snapshots", () => { + expect(client.hasLevel3Snapshots).toBeFalsy(); + }); -test("it should not support level3 updates", () => { - expect(client.hasLevel3Updates).toBeFalsy(); -}); + test("it should not support level3 updates", () => { + expect(client.hasLevel3Updates).toBeFalsy(); + }); -test( - "should subscribe and emit ticker events", - done => { + test("should subscribe and emit ticker events", done => { client.subscribeTicker(market); client.on("ticker", ticker => { expect(ticker.fullId).toMatch("ZB:BTC/USDT"); @@ -62,13 +61,9 @@ test( expect(parseFloat(ticker.ask)).toBeGreaterThan(0); done(); }); - }, - 10000 -); + }, 10000); -test( - "should subscribe and emit trade events", - done => { + test("should subscribe and emit trade events", done => { client.subscribeTrades(market); client.on("trade", trade => { expect(trade.fullId).toMatch("ZB:BTC/USDT"); @@ -84,42 +79,41 @@ test( expect(parseFloat(trade.amount)).toBeGreaterThan(0); done(); }); - }, - 30000 -); + }, 30000); -test("should subscribe and emit level2 snapshots", done => { - client.subscribeLevel2Snapshots(market); - client.on("l2snapshot", snapshot => { - expect(snapshot.fullId).toMatch("ZB:BTC/USDT"); - expect(snapshot.exchange).toMatch("ZB"); - expect(snapshot.base).toMatch("BTC"); - expect(snapshot.quote).toMatch("USDT"); - expect(snapshot.sequenceId).toBeUndefined(); - expect(snapshot.timestampMs).toBeGreaterThan(1522540800000); - expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.asks[0].count).toBeUndefined(); - expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); - expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); - expect(snapshot.bids[0].count).toBeUndefined(); - done(); + test("should subscribe and emit level2 snapshots", done => { + client.subscribeLevel2Snapshots(market); + client.on("l2snapshot", snapshot => { + expect(snapshot.fullId).toMatch("ZB:BTC/USDT"); + expect(snapshot.exchange).toMatch("ZB"); + expect(snapshot.base).toMatch("BTC"); + expect(snapshot.quote).toMatch("USDT"); + expect(snapshot.sequenceId).toBeUndefined(); + expect(snapshot.timestampMs).toBeGreaterThan(1522540800000); + expect(parseFloat(snapshot.asks[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.asks[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.asks[0].count).toBeUndefined(); + expect(parseFloat(snapshot.bids[0].price)).toBeGreaterThanOrEqual(0); + expect(parseFloat(snapshot.bids[0].size)).toBeGreaterThanOrEqual(0); + expect(snapshot.bids[0].count).toBeUndefined(); + done(); + }); }); -}); -test("should unsubscribe tickers", () => { - client.unsubscribeTicker(market); -}); + test("should unsubscribe tickers", () => { + client.unsubscribeTicker(market); + }); -test("should unsubscribe trades", () => { - client.unsubscribeTrades(market); -}); + test("should unsubscribe trades", () => { + client.unsubscribeTrades(market); + }); -test("should unsubscribe level2 snapshots", () => { - client.unsubscribeLevel2Snapshots(market); -}); + test("should unsubscribe level2 snapshots", () => { + client.unsubscribeLevel2Snapshots(market); + }); -test("should close connections", done => { - client.on("closed", done); - client.close(); + test("should close connections", done => { + client.on("closed", done); + client.close(); + }); });