tardis-dev
Advanced tools
Comparing version 7.2.0 to 7.3.0
import { Exchange } from './types'; | ||
export declare function getApiKeyAccessInfo(apiKey?: string): Promise<{ | ||
exchange: "bitmex" | "deribit" | "binance" | "binance-futures" | "ftx" | "okex" | "huobi" | "huobi-dm" | "bitflyer" | "bitstamp" | "coinbase" | "cryptofacilities" | "gemini" | "kraken" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us"; | ||
exchange: "bitmex" | "deribit" | "binance" | "binance-futures" | "ftx" | "okex" | "huobi" | "huobi-dm" | "bitflyer" | "bitstamp" | "coinbase" | "cryptofacilities" | "gemini" | "kraken" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us" | "bybit"; | ||
from: string; | ||
@@ -5,0 +5,0 @@ to: string; |
@@ -1,2 +0,2 @@ | ||
export declare const EXCHANGES: readonly ["bitmex", "deribit", "binance", "binance-futures", "ftx", "okex", "huobi", "huobi-dm", "bitflyer", "bitstamp", "coinbase", "cryptofacilities", "gemini", "kraken", "bitfinex", "bitfinex-derivatives", "binance-dex", "binance-jersey", "binance-us", "huobi-us"]; | ||
export declare const EXCHANGES: readonly ["bitmex", "deribit", "binance", "binance-futures", "ftx", "okex", "huobi", "huobi-dm", "bitflyer", "bitstamp", "coinbase", "cryptofacilities", "gemini", "kraken", "bitfinex", "bitfinex-derivatives", "binance-dex", "binance-jersey", "binance-us", "huobi-us", "bybit"]; | ||
export declare const EXCHANGE_CHANNELS_INFO: { | ||
@@ -10,5 +10,5 @@ bitmex: readonly ["trade", "orderBookL2", "liquidation", "connected", "announcement", "chat", "publicNotifications", "instrument", "settlement", "funding", "insurance", "orderBookL2_25", "quote", "quoteBin1m", "quoteBin5m", "quoteBin1h", "quoteBin1d", "tradeBin1m", "tradeBin5m", "tradeBin1h", "tradeBin1d"]; | ||
okex: readonly ["spot/ticker", "spot/trade", "spot/depth", "swap/ticker", "swap/trade", "swap/depth", "swap/funding_rate", "swap/price_range", "swap/mark_price", "futures/ticker", "futures/trade", "futures/depth", "futures/price_range", "futures/mark_price", "futures/estimated_price", "index/ticker"]; | ||
binance: readonly ["trade", "ticker", "depth", "miniTicker", "depthSnapshot", "bookTicker"]; | ||
'binance-jersey': readonly ["trade", "ticker", "depth", "miniTicker", "depthSnapshot", "bookTicker"]; | ||
'binance-us': readonly ["trade", "ticker", "depth", "miniTicker", "depthSnapshot", "bookTicker"]; | ||
binance: readonly ["trade", "ticker", "depth", "depthSnapshot", "bookTicker"]; | ||
'binance-jersey': readonly ["trade", "ticker", "depth", "depthSnapshot", "bookTicker"]; | ||
'binance-us': readonly ["trade", "ticker", "depth", "depthSnapshot", "bookTicker"]; | ||
'binance-dex': readonly ["trades", "marketDiff", "depthSnapshot"]; | ||
@@ -19,3 +19,3 @@ bitfinex: readonly ["trades", "book"]; | ||
bitflyer: readonly ["lightning_board_snapshot", "lightning_board", "lightning_ticker", "lightning_executions"]; | ||
'binance-futures': readonly ["aggTrade", "ticker", "depth", "markPrice", "depthSnapshot"]; | ||
'binance-futures': readonly ["aggTrade", "ticker", "depth", "markPrice", "depthSnapshot", "bookTicker"]; | ||
'bitfinex-derivatives': readonly ["trades", "book", "status"]; | ||
@@ -25,3 +25,4 @@ huobi: readonly ["depth", "detail", "trade", "bbo"]; | ||
'huobi-us': readonly ["depth", "detail", "trade"]; | ||
bybit: readonly ["trade", "instrument_info", "orderBookL2_25", "insurance"]; | ||
}; | ||
//# sourceMappingURL=consts.d.ts.map |
@@ -23,5 +23,6 @@ "use strict"; | ||
'binance-us', | ||
'huobi-us' | ||
'huobi-us', | ||
'bybit' | ||
]; | ||
const BINANCE_CHANNELS = ['trade', 'ticker', 'depth', 'miniTicker', 'depthSnapshot', 'bookTicker']; | ||
const BINANCE_CHANNELS = ['trade', 'ticker', 'depth', 'depthSnapshot', 'bookTicker']; | ||
const BINANCE_DEX_CHANNELS = ['trades', 'marketDiff', 'depthSnapshot']; | ||
@@ -100,3 +101,3 @@ const BITFINEX_CHANNELS = ['trades', 'book']; | ||
const BITFLYER_CHANNELS = ['lightning_board_snapshot', 'lightning_board', 'lightning_ticker', 'lightning_executions']; | ||
const BINANCE_FUTURES_CHANNELS = ['aggTrade', 'ticker', 'depth', 'markPrice', 'depthSnapshot']; | ||
const BINANCE_FUTURES_CHANNELS = ['aggTrade', 'ticker', 'depth', 'markPrice', 'depthSnapshot', 'bookTicker']; | ||
const BITFINEX_DERIV_CHANNELS = ['trades', 'book', 'status']; | ||
@@ -106,2 +107,3 @@ const HUOBI_CHANNELS = ['depth', 'detail', 'trade', 'bbo']; | ||
const HUOBI_DM_CHANNELS = ['depth', 'detail', 'trade']; | ||
const BYBIT_CHANNELS = ['trade', 'instrument_info', 'orderBookL2_25', 'insurance']; | ||
exports.EXCHANGE_CHANNELS_INFO = { | ||
@@ -127,4 +129,5 @@ bitmex: BITMEX_CHANNELS, | ||
'huobi-dm': HUOBI_DM_CHANNELS, | ||
'huobi-us': HUOBI_US_CHANNELS | ||
'huobi-us': HUOBI_US_CHANNELS, | ||
bybit: BYBIT_CHANNELS | ||
}; | ||
//# sourceMappingURL=consts.js.map |
@@ -24,3 +24,3 @@ import { BookChange, Exchange, Trade } from '../types'; | ||
readonly symbol: string; | ||
readonly exchange: "bitmex" | "deribit" | "binance" | "binance-futures" | "ftx" | "okex" | "huobi" | "huobi-dm" | "bitflyer" | "bitstamp" | "coinbase" | "cryptofacilities" | "gemini" | "kraken" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us"; | ||
readonly exchange: "bitmex" | "deribit" | "binance" | "binance-futures" | "ftx" | "okex" | "huobi" | "huobi-dm" | "bitflyer" | "bitstamp" | "coinbase" | "cryptofacilities" | "gemini" | "kraken" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us" | "bybit"; | ||
readonly isSnapshot: boolean; | ||
@@ -41,3 +41,3 @@ readonly bids: { | ||
declare type HuobiDataMessage = { | ||
ch: 'string'; | ||
ch: string; | ||
}; | ||
@@ -44,0 +44,0 @@ declare type HuobiTradeDataMessage = HuobiDataMessage & { |
import { BookChange, DerivativeTicker, Trade } from '../types'; | ||
import { Mapper } from './mapper'; | ||
export * from './mapper'; | ||
export declare const normalizeTrades: <T extends "bitmex" | "deribit" | "binance" | "binance-futures" | "ftx" | "okex" | "huobi" | "huobi-dm" | "bitflyer" | "bitstamp" | "coinbase" | "cryptofacilities" | "gemini" | "kraken" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us">(exchange: T, _localTimestamp: Date) => Mapper<T, Trade>; | ||
export declare const normalizeBookChanges: <T extends "bitmex" | "deribit" | "binance" | "binance-futures" | "ftx" | "okex" | "huobi" | "huobi-dm" | "bitflyer" | "bitstamp" | "coinbase" | "cryptofacilities" | "gemini" | "kraken" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us">(exchange: T, _localTimestamp: Date) => Mapper<T, BookChange>; | ||
export declare const normalizeDerivativeTickers: <T extends "bitmex" | "deribit" | "binance-futures" | "okex" | "cryptofacilities" | "bitfinex-derivatives">(exchange: T, _localTimestamp: Date) => Mapper<T, DerivativeTicker>; | ||
export declare const normalizeTrades: <T extends "bitmex" | "deribit" | "binance" | "binance-futures" | "ftx" | "okex" | "huobi" | "huobi-dm" | "bitflyer" | "bitstamp" | "coinbase" | "cryptofacilities" | "gemini" | "kraken" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us" | "bybit">(exchange: T, _localTimestamp: Date) => Mapper<T, Trade>; | ||
export declare const normalizeBookChanges: <T extends "bitmex" | "deribit" | "binance" | "binance-futures" | "ftx" | "okex" | "huobi" | "huobi-dm" | "bitflyer" | "bitstamp" | "coinbase" | "cryptofacilities" | "gemini" | "kraken" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us" | "bybit">(exchange: T, _localTimestamp: Date) => Mapper<T, BookChange>; | ||
export declare const normalizeDerivativeTickers: <T extends "bitmex" | "deribit" | "binance-futures" | "okex" | "cryptofacilities" | "bitfinex-derivatives" | "bybit">(exchange: T, _localTimestamp: Date) => Mapper<T, DerivativeTicker>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -12,2 +12,3 @@ "use strict"; | ||
const bitstamp_1 = require("./bitstamp"); | ||
const bybit_1 = require("./bybit"); | ||
const coinbase_1 = require("./coinbase"); | ||
@@ -18,5 +19,5 @@ const cryptofacilities_1 = require("./cryptofacilities"); | ||
const gemini_1 = require("./gemini"); | ||
const huobi_1 = require("./huobi"); | ||
const kraken_1 = require("./kraken"); | ||
const okex_1 = require("./okex"); | ||
const huobi_1 = require("./huobi"); | ||
__export(require("./mapper")); | ||
@@ -43,3 +44,4 @@ const tradesMappers = { | ||
'huobi-dm': () => new huobi_1.HuobiTradesMapper('huobi-dm'), | ||
'huobi-us': () => new huobi_1.HuobiTradesMapper('huobi-us') | ||
'huobi-us': () => new huobi_1.HuobiTradesMapper('huobi-us'), | ||
bybit: () => new bybit_1.BybitTradesMapper('bybit') | ||
}; | ||
@@ -66,3 +68,4 @@ const bookChangeMappers = { | ||
'huobi-dm': () => new huobi_1.HuobiBookChangeMapper('huobi-dm'), | ||
'huobi-us': () => new huobi_1.HuobiBookChangeMapper('huobi-us') | ||
'huobi-us': () => new huobi_1.HuobiBookChangeMapper('huobi-us'), | ||
bybit: () => new bybit_1.BybitBookChangeMapper('bybit') | ||
}; | ||
@@ -75,3 +78,4 @@ const derivativeTickersMappers = { | ||
deribit: () => new deribit_1.DeribitDerivativeTickerMapper(), | ||
okex: () => new okex_1.OkexDerivativeTickerMapper() | ||
okex: () => new okex_1.OkexDerivativeTickerMapper(), | ||
bybit: () => new bybit_1.BybitDerivativeTickerMapper() | ||
}; | ||
@@ -78,0 +82,0 @@ exports.normalizeTrades = (exchange, _localTimestamp) => { |
@@ -26,5 +26,4 @@ import { Filter } from '../types'; | ||
protected httpURL: string; | ||
protected bookUpdateSpeed: string; | ||
} | ||
export {}; | ||
//# sourceMappingURL=binance.d.ts.map |
@@ -45,3 +45,7 @@ "use strict"; | ||
this.debug('requesting manual snapshot for: %s', symbol); | ||
const depthSnapshotResponse = await got_1.default.get(`${this.httpURL}/depth?symbol=${symbol.toUpperCase()}&limit=1000`).json(); | ||
let depthSnapshotResponse = (await got_1.default.get(`${this.httpURL}/depth?symbol=${symbol.toUpperCase()}&limit=1000`).json()); | ||
const snapshotIsStale = new Date(depthSnapshotResponse.T).getUTCSeconds() !== new Date(depthSnapshotResponse.E).getUTCSeconds(); | ||
if (snapshotIsStale) { | ||
depthSnapshotResponse = (await got_1.default.get(`${this.httpURL}/depth?symbol=${symbol.toUpperCase()}&limit=1000`).json()); | ||
} | ||
const snapshot = { | ||
@@ -86,3 +90,2 @@ stream: `${symbol}@depthSnapshot`, | ||
this.httpURL = 'https://fapi.binance.com/fapi/v1'; | ||
this.bookUpdateSpeed = ''; | ||
} | ||
@@ -89,0 +92,0 @@ } |
@@ -12,2 +12,3 @@ "use strict"; | ||
const bitstamp_1 = require("./bitstamp"); | ||
const bybit_1 = require("./bybit"); | ||
const coinbase_1 = require("./coinbase"); | ||
@@ -18,5 +19,5 @@ const cryptofacilities_1 = require("./cryptofacilities"); | ||
const gemini_1 = require("./gemini"); | ||
const huobi_1 = require("./huobi"); | ||
const kraken_1 = require("./kraken"); | ||
const okex_1 = require("./okex"); | ||
const huobi_1 = require("./huobi"); | ||
__export(require("./realtimefeed")); | ||
@@ -43,3 +44,4 @@ const realTimeFeedsMap = { | ||
'huobi-us': () => new huobi_1.HuobiUSRealTimeFeed('huobi-us'), | ||
huobi: () => new huobi_1.HuobiRealTimeFeed('huobi') | ||
huobi: () => new huobi_1.HuobiRealTimeFeed('huobi'), | ||
bybit: () => new bybit_1.BybitRealTimeDataFeed('bybit') | ||
}; | ||
@@ -46,0 +48,0 @@ function getRealTimeFeedFactory(exchange) { |
@@ -29,2 +29,10 @@ "use strict"; | ||
let receivedMessagesCount = 0; | ||
let symbolsCount = filters.reduce((prev, curr) => { | ||
if (curr.symbols !== undefined) { | ||
for (const symbol of curr.symbols) { | ||
prev.add(symbol); | ||
} | ||
} | ||
return prev; | ||
}, new Set()).size; | ||
ws.onopen = this._onConnectionOpen({ | ||
@@ -34,3 +42,6 @@ address, | ||
snapshotsToReturn, | ||
filters | ||
filters, | ||
connectionConfirmed: () => { | ||
return receivedMessagesCount > symbolsCount * 2; | ||
} | ||
}); | ||
@@ -106,3 +117,3 @@ if (this.timeoutIntervalMS !== undefined) { | ||
} | ||
_onConnectionOpen({ address, filters, snapshotsToReturn, subscribeMessages }) { | ||
_onConnectionOpen({ address, filters, snapshotsToReturn, subscribeMessages, connectionConfirmed }) { | ||
return async ({ target }) => { | ||
@@ -112,9 +123,17 @@ this.debug('estabilished connection to %s', address); | ||
for (const message of subscribeMessages) { | ||
this.debug('subscribing to %o', message); | ||
target.send(JSON.stringify(message)); | ||
} | ||
} | ||
this.debug('subscribed successfully'); | ||
this.onConnected(target); | ||
try { | ||
await handy_1.wait(2 * handy_1.ONE_SEC_IN_MS); | ||
//wait before fetching snapshots until we're sure we've got proper connection estabilished (received some messages) | ||
while (connectionConfirmed() == false) { | ||
await handy_1.wait(100); | ||
} | ||
// wait a second just in case before starting fetching the snapshots | ||
await handy_1.wait(1 * handy_1.ONE_SEC_IN_MS); | ||
if (target.readyState === ws_1.default.CLOSED) { | ||
return; | ||
} | ||
await this.provideManualSnapshots(filters, snapshotsToReturn, () => target.readyState === ws_1.default.CLOSED); | ||
@@ -124,2 +143,3 @@ } | ||
this.debug('providing manual snapshots error: %o, closing connection...', e); | ||
target.terminate(); | ||
} | ||
@@ -126,0 +146,0 @@ }; |
{ | ||
"name": "tardis-dev", | ||
"version": "7.2.0", | ||
"version": "7.3.0", | ||
"engines": { | ||
@@ -16,3 +16,3 @@ "node": ">=12" | ||
"precommit": "lint-staged", | ||
"test": "npm run build && jest --runInBand", | ||
"test": "npm run build && jest --runInBand --forceExit", | ||
"prepare": "npm run build", | ||
@@ -53,3 +53,3 @@ "release": "cross-var \"npm run test && npm run build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish --access=public\"" | ||
"fs-extra": "^8.1.0", | ||
"got": "^10.0.0-alpha.2", | ||
"got": "^10.0.0-alpha.3", | ||
"p-map": "^3.0.0", | ||
@@ -56,0 +56,0 @@ "sorted-btree": "^1.2.1", |
@@ -56,3 +56,3 @@ # tardis-dev | ||
- support for top cryptocurrency exchanges: BitMEX, Deribit, Binance, Binance Futures, FTX, OKEx, Huobi Global, Huobi DM, bitFlyer, Bitstamp, Coinbase Pro, Crypto Facilities, Gemini, Kraken, Bitfinex and Huobi US. | ||
- support for top cryptocurrency exchanges: BitMEX, Deribit, Binance, Binance Futures, FTX, OKEx, Huobi Global, Huobi DM, bitFlyer, Bitstamp, Coinbase Pro, Crypto Facilities, Gemini, Kraken, Bitfinex, Huobi US and Bybit. | ||
@@ -59,0 +59,0 @@ <br/> |
@@ -21,6 +21,7 @@ export const EXCHANGES = [ | ||
'binance-us', | ||
'huobi-us' | ||
'huobi-us', | ||
'bybit' | ||
] as const | ||
const BINANCE_CHANNELS = ['trade', 'ticker', 'depth', 'miniTicker', 'depthSnapshot', 'bookTicker'] as const | ||
const BINANCE_CHANNELS = ['trade', 'ticker', 'depth', 'depthSnapshot', 'bookTicker'] as const | ||
@@ -112,3 +113,3 @@ const BINANCE_DEX_CHANNELS = ['trades', 'marketDiff', 'depthSnapshot'] as const | ||
const BINANCE_FUTURES_CHANNELS = ['aggTrade', 'ticker', 'depth', 'markPrice', 'depthSnapshot'] as const | ||
const BINANCE_FUTURES_CHANNELS = ['aggTrade', 'ticker', 'depth', 'markPrice', 'depthSnapshot', 'bookTicker'] as const | ||
@@ -123,2 +124,4 @@ const BITFINEX_DERIV_CHANNELS = ['trades', 'book', 'status'] as const | ||
const BYBIT_CHANNELS = ['trade', 'instrument_info', 'orderBookL2_25', 'insurance'] as const | ||
export const EXCHANGE_CHANNELS_INFO = { | ||
@@ -144,3 +147,4 @@ bitmex: BITMEX_CHANNELS, | ||
'huobi-dm': HUOBI_DM_CHANNELS, | ||
'huobi-us': HUOBI_US_CHANNELS | ||
'huobi-us': HUOBI_US_CHANNELS, | ||
bybit: BYBIT_CHANNELS | ||
} |
@@ -105,3 +105,3 @@ import { BookChange, Exchange, Trade } from '../types' | ||
type HuobiDataMessage = { | ||
ch: 'string' | ||
ch: string | ||
} | ||
@@ -108,0 +108,0 @@ |
@@ -14,2 +14,3 @@ import { BookChange, DerivativeTicker, Trade } from '../types' | ||
import { BitstampBookChangeMapper, bitstampTradesMapper } from './bitstamp' | ||
import { BybitBookChangeMapper, BybitDerivativeTickerMapper, BybitTradesMapper } from './bybit' | ||
import { coinbaseBookChangMapper, coinbaseTradesMapper } from './coinbase' | ||
@@ -20,6 +21,6 @@ import { cryptofacilitiesBookChangeMapper, CryptofacilitiesDerivativeTickerMapper, cryptofacilitiesTradesMapper } from './cryptofacilities' | ||
import { geminiBookChangeMapper, geminiTradesMapper } from './gemini' | ||
import { HuobiBookChangeMapper, HuobiTradesMapper } from './huobi' | ||
import { krakenBookChangeMapper, krakenTradesMapper } from './kraken' | ||
import { Mapper } from './mapper' | ||
import { okexBookChangeMapper, OkexDerivativeTickerMapper, okexTradesMapper } from './okex' | ||
import { HuobiTradesMapper, HuobiBookChangeMapper } from './huobi' | ||
@@ -48,3 +49,4 @@ export * from './mapper' | ||
'huobi-dm': () => new HuobiTradesMapper('huobi-dm'), | ||
'huobi-us': () => new HuobiTradesMapper('huobi-us') | ||
'huobi-us': () => new HuobiTradesMapper('huobi-us'), | ||
bybit: () => new BybitTradesMapper('bybit') | ||
} | ||
@@ -72,3 +74,4 @@ | ||
'huobi-dm': () => new HuobiBookChangeMapper('huobi-dm'), | ||
'huobi-us': () => new HuobiBookChangeMapper('huobi-us') | ||
'huobi-us': () => new HuobiBookChangeMapper('huobi-us'), | ||
bybit: () => new BybitBookChangeMapper('bybit') | ||
} | ||
@@ -82,3 +85,4 @@ | ||
deribit: () => new DeribitDerivativeTickerMapper(), | ||
okex: () => new OkexDerivativeTickerMapper() | ||
okex: () => new OkexDerivativeTickerMapper(), | ||
bybit: () => new BybitDerivativeTickerMapper() | ||
} | ||
@@ -85,0 +89,0 @@ |
@@ -50,3 +50,7 @@ import got from 'got' | ||
const depthSnapshotResponse = await got.get(`${this.httpURL}/depth?symbol=${symbol.toUpperCase()}&limit=1000`).json() | ||
let depthSnapshotResponse = (await got.get(`${this.httpURL}/depth?symbol=${symbol.toUpperCase()}&limit=1000`).json()) as any | ||
const snapshotIsStale = new Date(depthSnapshotResponse.T).getUTCSeconds() !== new Date(depthSnapshotResponse.E).getUTCSeconds() | ||
if (snapshotIsStale) { | ||
depthSnapshotResponse = (await got.get(`${this.httpURL}/depth?symbol=${symbol.toUpperCase()}&limit=1000`).json()) as any | ||
} | ||
@@ -83,3 +87,2 @@ const snapshot = { | ||
protected httpURL = 'https://fapi.binance.com/fapi/v1' | ||
protected bookUpdateSpeed = '' | ||
} |
@@ -8,2 +8,3 @@ import { Exchange } from '../types' | ||
import { BitstampRealTimeFeed } from './bitstamp' | ||
import { BybitRealTimeDataFeed } from './bybit' | ||
import { CoinbaseRealTimeFeed } from './coinbase' | ||
@@ -14,6 +15,6 @@ import { CryptofacilitiesRealTimeFeed } from './cryptofacilities' | ||
import { GeminiRealTimeFeed } from './gemini' | ||
import { HuobiDMRealTimeFeed, HuobiRealTimeFeed, HuobiUSRealTimeFeed } from './huobi' | ||
import { KrakenRealTimeFeed } from './kraken' | ||
import { OkexRealTimeFeed } from './okex' | ||
import { RealTimeFeed } from './realtimefeed' | ||
import { HuobiRealTimeFeed, HuobiDMRealTimeFeed, HuobiUSRealTimeFeed } from './huobi' | ||
@@ -44,3 +45,4 @@ export * from './realtimefeed' | ||
'huobi-us': () => new HuobiUSRealTimeFeed('huobi-us'), | ||
huobi: () => new HuobiRealTimeFeed('huobi') | ||
huobi: () => new HuobiRealTimeFeed('huobi'), | ||
bybit: () => new BybitRealTimeDataFeed('bybit') | ||
} | ||
@@ -47,0 +49,0 @@ |
@@ -41,2 +41,11 @@ import dbg from 'debug' | ||
let symbolsCount = filters.reduce((prev, curr) => { | ||
if (curr.symbols !== undefined) { | ||
for (const symbol of curr.symbols) { | ||
prev.add(symbol) | ||
} | ||
} | ||
return prev | ||
}, new Set<string>()).size | ||
ws.onopen = this._onConnectionOpen({ | ||
@@ -46,3 +55,6 @@ address, | ||
snapshotsToReturn, | ||
filters | ||
filters, | ||
connectionConfirmed: () => { | ||
return receivedMessagesCount > symbolsCount * 2 | ||
} | ||
}) | ||
@@ -135,3 +147,4 @@ | ||
snapshotsToReturn, | ||
subscribeMessages | ||
subscribeMessages, | ||
connectionConfirmed | ||
}: { | ||
@@ -142,2 +155,3 @@ address: string | ||
snapshotsToReturn: any[] | ||
connectionConfirmed: () => boolean | ||
}) { | ||
@@ -149,3 +163,2 @@ return async ({ target }: WebSocket.OpenEvent) => { | ||
for (const message of subscribeMessages) { | ||
this.debug('subscribing to %o', message) | ||
target.send(JSON.stringify(message)) | ||
@@ -155,9 +168,22 @@ } | ||
this.debug('subscribed successfully') | ||
this.onConnected(target) | ||
try { | ||
await wait(2 * ONE_SEC_IN_MS) | ||
//wait before fetching snapshots until we're sure we've got proper connection estabilished (received some messages) | ||
while (connectionConfirmed() == false) { | ||
await wait(100) | ||
} | ||
// wait a second just in case before starting fetching the snapshots | ||
await wait(1 * ONE_SEC_IN_MS) | ||
if (target.readyState === WebSocket.CLOSED) { | ||
return | ||
} | ||
await this.provideManualSnapshots(filters, snapshotsToReturn, () => target.readyState === WebSocket.CLOSED) | ||
} catch (e) { | ||
this.debug('providing manual snapshots error: %o, closing connection...', e) | ||
target.terminate() | ||
} | ||
@@ -164,0 +190,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
567263
269
9900
Updatedgot@^10.0.0-alpha.3