tardis-dev
Advanced tools
Comparing version 7.7.10 to 8.0.0
@@ -1,2 +0,2 @@ | ||
export declare const EXCHANGES: readonly ["bitmex", "deribit", "binance", "binance-futures", "ftx", "okex", "huobi", "huobi-dm", "bitflyer", "bitstamp", "coinbase", "cryptofacilities", "kraken", "gemini", "bitfinex", "bitfinex-derivatives", "binance-dex", "binance-jersey", "binance-us", "huobi-us", "bybit", "okcoin", "hitbtc"]; | ||
export declare const EXCHANGES: readonly ["bitmex", "deribit", "binance", "binance-futures", "ftx", "okex", "okex-futures", "okex-swap", "huobi", "huobi-dm", "bitflyer", "bitstamp", "coinbase", "cryptofacilities", "kraken", "gemini", "bitfinex", "bitfinex-derivatives", "binance-dex", "binance-jersey", "binance-us", "huobi-us", "bybit", "okcoin", "hitbtc"]; | ||
export declare const EXCHANGE_CHANNELS_INFO: { | ||
@@ -9,7 +9,9 @@ bitmex: readonly ["trade", "orderBookL2", "liquidation", "connected", "announcement", "chat", "publicNotifications", "instrument", "settlement", "funding", "insurance", "orderBookL2_25", "quote", "quoteBin1m", "quoteBin5m", "quoteBin1h", "quoteBin1d", "tradeBin1m", "tradeBin5m", "tradeBin1h", "tradeBin1d"]; | ||
kraken: readonly ["ticker", "trade", "book", "spread"]; | ||
okex: readonly ["spot/trade", "spot/ticker", "spot/depth", "swap/trade", "swap/ticker", "swap/depth", "swap/funding_rate", "swap/price_range", "swap/mark_price", "futures/trade", "futures/ticker", "futures/depth", "futures/depth_l2_tbt", "futures/price_range", "futures/mark_price", "futures/estimated_price", "index/ticker"]; | ||
okex: readonly ["spot/trade", "spot/depth", "spot/ticker"]; | ||
'okex-swap': string[]; | ||
'okex-futures': string[]; | ||
binance: readonly ["trade", "aggTrade", "ticker", "depth", "depthSnapshot", "bookTicker"]; | ||
'binance-jersey': readonly ["trade", "aggTrade", "ticker", "depth", "depthSnapshot", "bookTicker"]; | ||
'binance-dex': readonly ["trades", "marketDiff", "depthSnapshot"]; | ||
'binance-us': readonly ["trade", "aggTrade", "ticker", "depth", "depthSnapshot", "bookTicker"]; | ||
'binance-dex': readonly ["trades", "marketDiff", "depthSnapshot"]; | ||
bitfinex: readonly ["trades", "book"]; | ||
@@ -16,0 +18,0 @@ ftx: readonly ["orderbook", "trades"]; |
@@ -10,2 +10,4 @@ "use strict"; | ||
'okex', | ||
'okex-futures', | ||
'okex-swap', | ||
'huobi', | ||
@@ -81,16 +83,9 @@ 'huobi-dm', | ||
const KRAKEN_CHANNELS = ['ticker', 'trade', 'book', 'spread']; | ||
const OKEX_CHANNELS = [ | ||
'spot/trade', | ||
'spot/ticker', | ||
'spot/depth', | ||
'swap/trade', | ||
'swap/ticker', | ||
'swap/depth', | ||
'swap/funding_rate', | ||
'swap/price_range', | ||
'swap/mark_price', | ||
const OKEX_CHANNELS = ['spot/trade', 'spot/depth', 'spot/ticker']; | ||
const OKCOIN_CHANNELS = ['spot/trade', 'spot/depth', 'spot/ticker']; | ||
const OKEX_FUTURES_CHANNELS = [ | ||
'futures/trade', | ||
'futures/ticker', | ||
'futures/depth', | ||
'futures/depth_l2_tbt', | ||
'futures/ticker', | ||
'futures/price_range', | ||
@@ -101,2 +96,11 @@ 'futures/mark_price', | ||
]; | ||
const OKEX_SWAP_CHANNELS = [ | ||
'swap/trade', | ||
'swap/depth', | ||
'swap/ticker', | ||
'swap/funding_rate', | ||
'swap/price_range', | ||
'swap/mark_price', | ||
'index/ticker' | ||
]; | ||
const CRYPTOFACILITIES_CHANNELS = ['trade', 'trade_snapshot', 'book', 'book_snapshot', 'ticker', 'heartbeat']; | ||
@@ -106,3 +110,3 @@ const FTX_CHANNELS = ['orderbook', 'trades']; | ||
const BITFLYER_CHANNELS = ['lightning_board_snapshot', 'lightning_board', 'lightning_ticker', 'lightning_executions']; | ||
const BINANCE_FUTURES_CHANNELS = ['trade', 'aggTrade', 'ticker', 'depth', 'markPrice', 'depthSnapshot', 'bookTicker']; | ||
const BINANCE_FUTURES_CHANNELS = ['trade', 'aggTrade', 'ticker', 'depth', 'markPrice', 'depthSnapshot', 'bookTicker', 'forceOrder']; | ||
const BITFINEX_DERIV_CHANNELS = ['trades', 'book', 'status']; | ||
@@ -113,3 +117,2 @@ const HUOBI_CHANNELS = ['depth', 'detail', 'trade', 'bbo']; | ||
const BYBIT_CHANNELS = ['trade', 'instrument_info', 'orderBookL2_25', 'insurance']; | ||
const OKCOIN_CHANNELS = ['spot/trade', 'spot/depth', 'spot/ticker']; | ||
const HITBTC_CHANNELS = ['snapshotTrades', 'updateTrades', 'snapshotOrderbook', 'updateOrderbook']; | ||
@@ -124,6 +127,8 @@ exports.EXCHANGE_CHANNELS_INFO = { | ||
okex: OKEX_CHANNELS, | ||
'okex-swap': OKEX_SWAP_CHANNELS, | ||
'okex-futures': OKEX_FUTURES_CHANNELS, | ||
binance: BINANCE_CHANNELS, | ||
'binance-jersey': BINANCE_CHANNELS, | ||
'binance-dex': BINANCE_DEX_CHANNELS, | ||
'binance-us': BINANCE_CHANNELS, | ||
'binance-dex': BINANCE_DEX_CHANNELS, | ||
bitfinex: BITFINEX_CHANNELS, | ||
@@ -130,0 +135,0 @@ ftx: FTX_CHANNELS, |
@@ -24,3 +24,3 @@ import { BookChange, DerivativeTicker, Exchange, Trade } from '../types'; | ||
readonly symbol: string; | ||
readonly exchange: "bitmex" | "deribit" | "binance" | "binance-futures" | "ftx" | "okex" | "huobi" | "huobi-dm" | "bitflyer" | "bitstamp" | "coinbase" | "cryptofacilities" | "kraken" | "gemini" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us" | "bybit" | "okcoin" | "hitbtc"; | ||
readonly exchange: "bitmex" | "deribit" | "binance" | "binance-futures" | "ftx" | "okex" | "okex-futures" | "okex-swap" | "huobi" | "huobi-dm" | "bitflyer" | "bitstamp" | "coinbase" | "cryptofacilities" | "kraken" | "gemini" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us" | "bybit" | "okcoin" | "hitbtc"; | ||
readonly isSnapshot: boolean; | ||
@@ -27,0 +27,0 @@ readonly bids: { |
@@ -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" | "kraken" | "gemini" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us" | "bybit" | "okcoin" | "hitbtc"; | ||
readonly exchange: "bitmex" | "deribit" | "binance" | "binance-futures" | "ftx" | "okex" | "okex-futures" | "okex-swap" | "huobi" | "huobi-dm" | "bitflyer" | "bitstamp" | "coinbase" | "cryptofacilities" | "kraken" | "gemini" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us" | "bybit" | "okcoin" | "hitbtc"; | ||
readonly isSnapshot: boolean; | ||
@@ -27,0 +27,0 @@ readonly bids: { |
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" | "kraken" | "gemini" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us" | "bybit" | "okcoin" | "hitbtc">(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" | "kraken" | "gemini" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us" | "bybit" | "okcoin" | "hitbtc">(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>; | ||
export declare const normalizeTrades: <T extends "bitmex" | "deribit" | "binance" | "binance-futures" | "ftx" | "okex" | "okex-futures" | "okex-swap" | "huobi" | "huobi-dm" | "bitflyer" | "bitstamp" | "coinbase" | "cryptofacilities" | "kraken" | "gemini" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us" | "bybit" | "okcoin" | "hitbtc">(exchange: T, _localTimestamp: Date) => Mapper<T, Trade>; | ||
export declare const normalizeBookChanges: <T extends "bitmex" | "deribit" | "binance" | "binance-futures" | "ftx" | "okex" | "okex-futures" | "okex-swap" | "huobi" | "huobi-dm" | "bitflyer" | "bitstamp" | "coinbase" | "cryptofacilities" | "kraken" | "gemini" | "bitfinex" | "bitfinex-derivatives" | "binance-dex" | "binance-jersey" | "binance-us" | "huobi-us" | "bybit" | "okcoin" | "hitbtc">(exchange: T, localTimestamp: Date) => Mapper<T, BookChange>; | ||
export declare const normalizeDerivativeTickers: <T extends "bitmex" | "deribit" | "binance-futures" | "okex-futures" | "okex-swap" | "cryptofacilities" | "bitfinex-derivatives" | "bybit">(exchange: T, _localTimestamp: Date) => Mapper<T, DerivativeTicker>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -40,3 +40,5 @@ "use strict"; | ||
kraken: () => kraken_1.krakenTradesMapper, | ||
okex: () => new okex_1.OkexTradesMapper('okex'), | ||
okex: () => new okex_1.OkexTradesMapper('okex', 'spot'), | ||
'okex-futures': () => new okex_1.OkexTradesMapper('okex-futures', 'futures'), | ||
'okex-swap': () => new okex_1.OkexTradesMapper('okex-swap', 'swap'), | ||
huobi: () => new huobi_1.HuobiTradesMapper('huobi'), | ||
@@ -46,6 +48,6 @@ 'huobi-dm': () => new huobi_1.HuobiTradesMapper('huobi-dm'), | ||
bybit: () => new bybit_1.BybitTradesMapper('bybit'), | ||
okcoin: () => new okex_1.OkexTradesMapper('okcoin'), | ||
okcoin: () => new okex_1.OkexTradesMapper('okcoin', 'spot'), | ||
hitbtc: () => hitbtc_1.hitBtcTradesMapper | ||
}; | ||
const OKEX_TICK_BY_TICK_CHANNEL_AVAILABILITY_TIMESTAMP = new Date('2019-12-04').valueOf(); | ||
const OKEX_TICK_BY_TICK_CHANNEL_AVAILABILITY_TIMESTAMP = new Date('2019-12-05').valueOf(); | ||
const bookChangeMappers = { | ||
@@ -68,3 +70,5 @@ bitmex: () => new bitmex_1.BitmexBookChangeMapper(), | ||
kraken: () => kraken_1.krakenBookChangeMapper, | ||
okex: (localTimestamp) => new okex_1.OkexBookChangeMapper('okex', localTimestamp.valueOf() >= OKEX_TICK_BY_TICK_CHANNEL_AVAILABILITY_TIMESTAMP), | ||
okex: () => new okex_1.OkexBookChangeMapper('okex', 'spot', false), | ||
'okex-futures': (localTimestamp) => new okex_1.OkexBookChangeMapper('okex-futures', 'futures', localTimestamp.valueOf() >= OKEX_TICK_BY_TICK_CHANNEL_AVAILABILITY_TIMESTAMP), | ||
'okex-swap': () => new okex_1.OkexBookChangeMapper('okex-swap', 'swap', false), | ||
huobi: () => new huobi_1.HuobiBookChangeMapper('huobi'), | ||
@@ -74,3 +78,3 @@ 'huobi-dm': () => new huobi_1.HuobiBookChangeMapper('huobi-dm'), | ||
bybit: () => new bybit_1.BybitBookChangeMapper('bybit'), | ||
okcoin: () => new okex_1.OkexBookChangeMapper('okcoin', false), | ||
okcoin: () => new okex_1.OkexBookChangeMapper('okcoin', 'spot', false), | ||
hitbtc: () => hitbtc_1.hitBtcBookChangeMapper | ||
@@ -84,3 +88,4 @@ }; | ||
deribit: () => new deribit_1.DeribitDerivativeTickerMapper(), | ||
okex: () => new okex_1.OkexDerivativeTickerMapper(), | ||
'okex-futures': () => new okex_1.OkexDerivativeTickerMapper('okex-futures'), | ||
'okex-swap': () => new okex_1.OkexDerivativeTickerMapper('okex-swap'), | ||
bybit: () => new bybit_1.BybitDerivativeTickerMapper() | ||
@@ -87,0 +92,0 @@ }; |
import { BookChange, DerivativeTicker, Exchange, FilterForExchange, Trade } from '../types'; | ||
import { Mapper } from './mapper'; | ||
export declare class OkexTradesMapper implements Mapper<'okex' | 'okcoin', Trade> { | ||
export declare class OkexTradesMapper implements Mapper<OKEX_EXCHANGES, Trade> { | ||
private readonly _exchange; | ||
constructor(_exchange: Exchange); | ||
private readonly _market; | ||
constructor(_exchange: Exchange, _market: OKEX_MARKETS); | ||
canHandle(message: OkexDataMessage): boolean; | ||
getFilters(symbols?: string[]): import("../types").Filter<"spot/trade" | "spot/ticker" | "spot/depth" | "swap/trade" | "swap/ticker" | "swap/depth" | "swap/funding_rate" | "swap/price_range" | "swap/mark_price" | "futures/trade" | "futures/ticker" | "futures/depth" | "futures/depth_l2_tbt" | "futures/price_range" | "futures/mark_price" | "futures/estimated_price" | "index/ticker">[]; | ||
getFilters(symbols?: string[]): { | ||
channel: string; | ||
symbols: string[] | undefined; | ||
}[]; | ||
map(okexTradesMessage: OKexTradesDataMessage, localTimestamp: Date): IterableIterator<Trade>; | ||
} | ||
export declare class OkexBookChangeMapper implements Mapper<'okex' | 'okcoin', BookChange> { | ||
export declare class OkexBookChangeMapper implements Mapper<OKEX_EXCHANGES, BookChange> { | ||
private readonly _exchange; | ||
private readonly _channels; | ||
constructor(_exchange: Exchange, useTickByTickChannel: boolean); | ||
private readonly _market; | ||
private readonly _useTickByTickChannel; | ||
constructor(_exchange: Exchange, _market: OKEX_MARKETS, _useTickByTickChannel: boolean); | ||
canHandle(message: OkexDataMessage): boolean; | ||
getFilters(symbols?: string[]): import("../types").Filter<"spot/trade" | "spot/ticker" | "spot/depth" | "swap/trade" | "swap/ticker" | "swap/depth" | "swap/funding_rate" | "swap/price_range" | "swap/mark_price" | "futures/trade" | "futures/ticker" | "futures/depth" | "futures/depth_l2_tbt" | "futures/price_range" | "futures/mark_price" | "futures/estimated_price" | "index/ticker">[]; | ||
getFilters(symbols?: string[]): { | ||
channel: string; | ||
symbols: string[] | undefined; | ||
}[]; | ||
map(okexDepthDataMessage: OkexDepthDataMessage, localTimestamp: Date): IterableIterator<BookChange>; | ||
} | ||
export declare class OkexDerivativeTickerMapper implements Mapper<'okex', DerivativeTicker> { | ||
export declare class OkexDerivativeTickerMapper implements Mapper<'okex-futures' | 'okex-swap', DerivativeTicker> { | ||
private readonly _exchange; | ||
private readonly pendingTickerInfoHelper; | ||
private _futuresChannels; | ||
private _swapChannels; | ||
constructor(_exchange: Exchange); | ||
canHandle(message: OkexDataMessage): boolean; | ||
getFilters(symbols?: string[]): import("../types").Filter<"spot/trade" | "spot/ticker" | "spot/depth" | "swap/trade" | "swap/ticker" | "swap/depth" | "swap/funding_rate" | "swap/price_range" | "swap/mark_price" | "futures/trade" | "futures/ticker" | "futures/depth" | "futures/depth_l2_tbt" | "futures/price_range" | "futures/mark_price" | "futures/estimated_price" | "index/ticker">[]; | ||
getFilters(symbols?: string[]): { | ||
channel: string; | ||
symbols: string[] | undefined; | ||
}[]; | ||
map(message: OkexTickersMessage | OkexFundingRateMessage | OkexMarkPriceMessage, localTimestamp: Date): IterableIterator<DerivativeTicker>; | ||
@@ -72,3 +87,5 @@ } | ||
declare type OkexBookLevel = [number | string, number | string, number | string, number | string]; | ||
declare type OKEX_EXCHANGES = 'okex' | 'okcoin' | 'okex-futures' | 'okex-swap'; | ||
declare type OKEX_MARKETS = 'spot' | 'swap' | 'futures'; | ||
export {}; | ||
//# sourceMappingURL=okex.d.ts.map |
@@ -5,67 +5,17 @@ "use strict"; | ||
// https://www.okex.com/docs/en/#ws_swap-README | ||
const tradeChannels = ['spot/trade', 'futures/trade', 'swap/trade']; | ||
const bookChangeChannels = ['spot/depth', 'futures/depth', 'swap/depth']; | ||
const bookChangeChannelsWithTickByTickSource = ['spot/depth', 'futures/depth_l2_tbt', 'swap/depth']; | ||
const derivativeTickerChannels = [ | ||
'spot/ticker', | ||
'futures/ticker', | ||
'swap/ticker', | ||
'futures/mark_price', | ||
'swap/mark_price', | ||
'swap/funding_rate' | ||
]; | ||
const mapToFilters = (mapping, symbols) => { | ||
// depending if symbols is for spot/swap/futures it needs different underlying channel | ||
// for ticker symbol we also need data for funding_rate and mark_price when applicable | ||
if (symbols === undefined) { | ||
return mapping.map(channel => { | ||
return { | ||
channel | ||
}; | ||
}); | ||
} | ||
return symbols | ||
.map(symbol => { | ||
const isSwap = symbol.endsWith('-SWAP'); | ||
const isFuture = symbol.match(/[0-9]$/); | ||
let prefix; | ||
if (isSwap) { | ||
prefix = 'swap'; | ||
} | ||
else if (isFuture) { | ||
prefix = 'futures'; | ||
} | ||
else { | ||
prefix = 'spot'; | ||
} | ||
return mapping | ||
.filter(c => c.startsWith(prefix)) | ||
.map(channel => { | ||
return { | ||
channel, | ||
symbols: [symbol] | ||
}; | ||
}); | ||
}) | ||
.flatMap(c => c) | ||
.reduce((prev, current) => { | ||
const matchingExisting = prev.find(c => c.channel === current.channel); | ||
if (matchingExisting !== undefined) { | ||
matchingExisting.symbols.push(current.symbols[0]); | ||
} | ||
else { | ||
prev.push(current); | ||
} | ||
return prev; | ||
}, []); | ||
}; | ||
class OkexTradesMapper { | ||
constructor(_exchange) { | ||
constructor(_exchange, _market) { | ||
this._exchange = _exchange; | ||
this._market = _market; | ||
} | ||
canHandle(message) { | ||
return tradeChannels.includes(message.table); | ||
return message.table === `${this._market}/trade`; | ||
} | ||
getFilters(symbols) { | ||
return mapToFilters(tradeChannels, symbols); | ||
return [ | ||
{ | ||
channel: `${this._market}/trade`, | ||
symbols | ||
} | ||
]; | ||
} | ||
@@ -95,11 +45,19 @@ *map(okexTradesMessage, localTimestamp) { | ||
class OkexBookChangeMapper { | ||
constructor(_exchange, useTickByTickChannel) { | ||
constructor(_exchange, _market, _useTickByTickChannel) { | ||
this._exchange = _exchange; | ||
this._channels = useTickByTickChannel ? bookChangeChannelsWithTickByTickSource : bookChangeChannels; | ||
this._market = _market; | ||
this._useTickByTickChannel = _useTickByTickChannel; | ||
} | ||
canHandle(message) { | ||
return this._channels.includes(message.table); | ||
const channelSuffix = this._useTickByTickChannel ? 'depth_l2_tbt' : 'depth'; | ||
return message.table === `${this._market}/${channelSuffix}`; | ||
} | ||
getFilters(symbols) { | ||
return mapToFilters(this._channels, symbols); | ||
const channelSuffix = this._useTickByTickChannel ? 'depth_l2_tbt' : 'depth'; | ||
return [ | ||
{ | ||
channel: `${this._market}/${channelSuffix}`, | ||
symbols | ||
} | ||
]; | ||
} | ||
@@ -123,14 +81,24 @@ *map(okexDepthDataMessage, localTimestamp) { | ||
class OkexDerivativeTickerMapper { | ||
constructor() { | ||
constructor(_exchange) { | ||
this._exchange = _exchange; | ||
this.pendingTickerInfoHelper = new mapper_1.PendingTickerInfoHelper(); | ||
this._futuresChannels = ['futures/ticker', 'futures/mark_price']; | ||
this._swapChannels = ['swap/ticker', 'swap/mark_price', 'swap/funding_rate']; | ||
} | ||
canHandle(message) { | ||
return derivativeTickerChannels.includes(message.table); | ||
const channels = this._exchange === 'okex-futures' ? this._futuresChannels : this._swapChannels; | ||
return channels.includes(message.table); | ||
} | ||
getFilters(symbols) { | ||
return mapToFilters(derivativeTickerChannels, symbols); | ||
const channels = this._exchange === 'okex-futures' ? this._futuresChannels : this._swapChannels; | ||
return channels.map(channel => { | ||
return { | ||
channel, | ||
symbols | ||
}; | ||
}); | ||
} | ||
*map(message, localTimestamp) { | ||
for (const okexMessage of message.data) { | ||
const pendingTickerInfo = this.pendingTickerInfoHelper.getPendingTickerInfo(okexMessage.instrument_id, 'okex'); | ||
const pendingTickerInfo = this.pendingTickerInfoHelper.getPendingTickerInfo(okexMessage.instrument_id, this._exchange); | ||
if ('funding_rate' in okexMessage) { | ||
@@ -137,0 +105,0 @@ pendingTickerInfo.updateFundingRate(Number(okexMessage.funding_rate)); |
@@ -41,2 +41,4 @@ "use strict"; | ||
okex: okex_1.OkexRealTimeFeed, | ||
'okex-futures': okex_1.OkexRealTimeFeed, | ||
'okex-swap': okex_1.OkexRealTimeFeed, | ||
'huobi-dm': huobi_1.HuobiDMRealTimeFeed, | ||
@@ -43,0 +45,0 @@ 'huobi-us': huobi_1.HuobiUSRealTimeFeed, |
{ | ||
"name": "tardis-dev", | ||
"version": "7.7.10", | ||
"version": "8.0.0", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=12" |
@@ -8,2 +8,4 @@ export const EXCHANGES = [ | ||
'okex', | ||
'okex-futures', | ||
'okex-swap', | ||
'huobi', | ||
@@ -29,5 +31,3 @@ 'huobi-dm', | ||
const BINANCE_CHANNELS = ['trade', 'aggTrade', 'ticker', 'depth', 'depthSnapshot', 'bookTicker'] as const | ||
const BINANCE_DEX_CHANNELS = ['trades', 'marketDiff', 'depthSnapshot'] as const | ||
const BITFINEX_CHANNELS = ['trades', 'book'] as const | ||
@@ -89,16 +89,11 @@ | ||
const OKEX_CHANNELS = [ | ||
'spot/trade', | ||
'spot/ticker', | ||
'spot/depth', | ||
'swap/trade', | ||
'swap/ticker', | ||
'swap/depth', | ||
'swap/funding_rate', | ||
'swap/price_range', | ||
'swap/mark_price', | ||
const OKEX_CHANNELS = ['spot/trade', 'spot/depth', 'spot/ticker'] as const | ||
const OKCOIN_CHANNELS = ['spot/trade', 'spot/depth', 'spot/ticker'] as const | ||
const OKEX_FUTURES_CHANNELS = [ | ||
'futures/trade', | ||
'futures/ticker', | ||
'futures/depth', | ||
'futures/depth_l2_tbt', | ||
'futures/ticker', | ||
'futures/price_range', | ||
@@ -108,4 +103,14 @@ 'futures/mark_price', | ||
'index/ticker' | ||
] as const | ||
] | ||
const OKEX_SWAP_CHANNELS = [ | ||
'swap/trade', | ||
'swap/depth', | ||
'swap/ticker', | ||
'swap/funding_rate', | ||
'swap/price_range', | ||
'swap/mark_price', | ||
'index/ticker' | ||
] | ||
const CRYPTOFACILITIES_CHANNELS = ['trade', 'trade_snapshot', 'book', 'book_snapshot', 'ticker', 'heartbeat'] as const | ||
@@ -119,3 +124,3 @@ | ||
const BINANCE_FUTURES_CHANNELS = ['trade', 'aggTrade', 'ticker', 'depth', 'markPrice', 'depthSnapshot', 'bookTicker'] | ||
const BINANCE_FUTURES_CHANNELS = ['trade', 'aggTrade', 'ticker', 'depth', 'markPrice', 'depthSnapshot', 'bookTicker', 'forceOrder'] | ||
@@ -132,4 +137,2 @@ const BITFINEX_DERIV_CHANNELS = ['trades', 'book', 'status'] as const | ||
const OKCOIN_CHANNELS = ['spot/trade', 'spot/depth', 'spot/ticker'] as const | ||
const HITBTC_CHANNELS = ['snapshotTrades', 'updateTrades', 'snapshotOrderbook', 'updateOrderbook'] as const | ||
@@ -145,6 +148,8 @@ | ||
okex: OKEX_CHANNELS, | ||
'okex-swap': OKEX_SWAP_CHANNELS, | ||
'okex-futures': OKEX_FUTURES_CHANNELS, | ||
binance: BINANCE_CHANNELS, | ||
'binance-jersey': BINANCE_CHANNELS, | ||
'binance-dex': BINANCE_DEX_CHANNELS, | ||
'binance-us': BINANCE_CHANNELS, | ||
'binance-dex': BINANCE_DEX_CHANNELS, | ||
bitfinex: BITFINEX_CHANNELS, | ||
@@ -151,0 +156,0 @@ ftx: FTX_CHANNELS, |
@@ -44,3 +44,5 @@ import { BookChange, DerivativeTicker, Trade } from '../types' | ||
kraken: () => krakenTradesMapper, | ||
okex: () => new OkexTradesMapper('okex'), | ||
okex: () => new OkexTradesMapper('okex', 'spot'), | ||
'okex-futures': () => new OkexTradesMapper('okex-futures', 'futures'), | ||
'okex-swap': () => new OkexTradesMapper('okex-swap', 'swap'), | ||
huobi: () => new HuobiTradesMapper('huobi'), | ||
@@ -50,7 +52,7 @@ 'huobi-dm': () => new HuobiTradesMapper('huobi-dm'), | ||
bybit: () => new BybitTradesMapper('bybit'), | ||
okcoin: () => new OkexTradesMapper('okcoin'), | ||
okcoin: () => new OkexTradesMapper('okcoin', 'spot'), | ||
hitbtc: () => hitBtcTradesMapper | ||
} | ||
const OKEX_TICK_BY_TICK_CHANNEL_AVAILABILITY_TIMESTAMP = new Date('2019-12-04').valueOf() | ||
const OKEX_TICK_BY_TICK_CHANNEL_AVAILABILITY_TIMESTAMP = new Date('2019-12-05').valueOf() | ||
@@ -74,4 +76,6 @@ const bookChangeMappers = { | ||
kraken: () => krakenBookChangeMapper, | ||
okex: (localTimestamp: Date) => | ||
new OkexBookChangeMapper('okex', localTimestamp.valueOf() >= OKEX_TICK_BY_TICK_CHANNEL_AVAILABILITY_TIMESTAMP), | ||
okex: () => new OkexBookChangeMapper('okex', 'spot', false), | ||
'okex-futures': (localTimestamp: Date) => | ||
new OkexBookChangeMapper('okex-futures', 'futures', localTimestamp.valueOf() >= OKEX_TICK_BY_TICK_CHANNEL_AVAILABILITY_TIMESTAMP), | ||
'okex-swap': () => new OkexBookChangeMapper('okex-swap', 'swap', false), | ||
huobi: () => new HuobiBookChangeMapper('huobi'), | ||
@@ -81,3 +85,3 @@ 'huobi-dm': () => new HuobiBookChangeMapper('huobi-dm'), | ||
bybit: () => new BybitBookChangeMapper('bybit'), | ||
okcoin: () => new OkexBookChangeMapper('okcoin', false), | ||
okcoin: () => new OkexBookChangeMapper('okcoin', 'spot', false), | ||
hitbtc: () => hitBtcBookChangeMapper | ||
@@ -92,3 +96,4 @@ } | ||
deribit: () => new DeribitDerivativeTickerMapper(), | ||
okex: () => new OkexDerivativeTickerMapper(), | ||
'okex-futures': () => new OkexDerivativeTickerMapper('okex-futures'), | ||
'okex-swap': () => new OkexDerivativeTickerMapper('okex-swap'), | ||
bybit: () => new BybitDerivativeTickerMapper() | ||
@@ -95,0 +100,0 @@ } |
@@ -6,72 +6,16 @@ import { BookChange, DerivativeTicker, Exchange, FilterForExchange, Trade } from '../types' | ||
const tradeChannels: FilterForExchange['okex']['channel'][] = ['spot/trade', 'futures/trade', 'swap/trade'] | ||
const bookChangeChannels: FilterForExchange['okex']['channel'][] = ['spot/depth', 'futures/depth', 'swap/depth'] | ||
const bookChangeChannelsWithTickByTickSource: FilterForExchange['okex']['channel'][] = ['spot/depth', 'futures/depth_l2_tbt', 'swap/depth'] | ||
export class OkexTradesMapper implements Mapper<OKEX_EXCHANGES, Trade> { | ||
constructor(private readonly _exchange: Exchange, private readonly _market: OKEX_MARKETS) {} | ||
const derivativeTickerChannels: FilterForExchange['okex']['channel'][] = [ | ||
'spot/ticker', | ||
'futures/ticker', | ||
'swap/ticker', | ||
'futures/mark_price', | ||
'swap/mark_price', | ||
'swap/funding_rate' | ||
] | ||
const mapToFilters = (mapping: FilterForExchange['okex']['channel'][], symbols?: string[]): FilterForExchange['okex'][] => { | ||
// depending if symbols is for spot/swap/futures it needs different underlying channel | ||
// for ticker symbol we also need data for funding_rate and mark_price when applicable | ||
if (symbols === undefined) { | ||
return mapping.map(channel => { | ||
return { | ||
channel | ||
} | ||
}) | ||
} | ||
return symbols | ||
.map(symbol => { | ||
const isSwap = symbol.endsWith('-SWAP') | ||
const isFuture = symbol.match(/[0-9]$/) | ||
let prefix: string | ||
if (isSwap) { | ||
prefix = 'swap' | ||
} else if (isFuture) { | ||
prefix = 'futures' | ||
} else { | ||
prefix = 'spot' | ||
} | ||
return mapping | ||
.filter(c => c.startsWith(prefix)) | ||
.map(channel => { | ||
return { | ||
channel, | ||
symbols: [symbol] | ||
} | ||
}) | ||
}) | ||
.flatMap(c => c) | ||
.reduce((prev, current) => { | ||
const matchingExisting = prev.find(c => c.channel === current.channel) | ||
if (matchingExisting !== undefined) { | ||
matchingExisting.symbols!.push(current.symbols[0]) | ||
} else { | ||
prev.push(current) | ||
} | ||
return prev | ||
}, [] as FilterForExchange['okex'][]) | ||
} | ||
export class OkexTradesMapper implements Mapper<'okex' | 'okcoin', Trade> { | ||
constructor(private readonly _exchange: Exchange) {} | ||
canHandle(message: OkexDataMessage) { | ||
return tradeChannels.includes(message.table) | ||
return message.table === `${this._market}/trade` | ||
} | ||
getFilters(symbols?: string[]) { | ||
return mapToFilters(tradeChannels, symbols) | ||
return [ | ||
{ | ||
channel: `${this._market}/trade`, | ||
symbols | ||
} | ||
] | ||
} | ||
@@ -103,15 +47,23 @@ | ||
export class OkexBookChangeMapper implements Mapper<'okex' | 'okcoin', BookChange> { | ||
private readonly _channels: FilterForExchange['okex']['channel'][] | ||
export class OkexBookChangeMapper implements Mapper<OKEX_EXCHANGES, BookChange> { | ||
constructor( | ||
private readonly _exchange: Exchange, | ||
private readonly _market: OKEX_MARKETS, | ||
private readonly _useTickByTickChannel: boolean | ||
) {} | ||
constructor(private readonly _exchange: Exchange, useTickByTickChannel: boolean) { | ||
this._channels = useTickByTickChannel ? bookChangeChannelsWithTickByTickSource : bookChangeChannels | ||
} | ||
canHandle(message: OkexDataMessage) { | ||
const channelSuffix = this._useTickByTickChannel ? 'depth_l2_tbt' : 'depth' | ||
canHandle(message: OkexDataMessage) { | ||
return this._channels.includes(message.table) | ||
return message.table === `${this._market}/${channelSuffix}` | ||
} | ||
getFilters(symbols?: string[]) { | ||
return mapToFilters(this._channels, symbols) | ||
const channelSuffix = this._useTickByTickChannel ? 'depth_l2_tbt' : 'depth' | ||
return [ | ||
{ | ||
channel: `${this._market}/${channelSuffix}`, | ||
symbols | ||
} | ||
] | ||
} | ||
@@ -135,10 +87,23 @@ | ||
export class OkexDerivativeTickerMapper implements Mapper<'okex', DerivativeTicker> { | ||
export class OkexDerivativeTickerMapper implements Mapper<'okex-futures' | 'okex-swap', DerivativeTicker> { | ||
private readonly pendingTickerInfoHelper = new PendingTickerInfoHelper() | ||
private _futuresChannels = ['futures/ticker', 'futures/mark_price'] | ||
private _swapChannels = ['swap/ticker', 'swap/mark_price', 'swap/funding_rate'] | ||
constructor(private readonly _exchange: Exchange) {} | ||
canHandle(message: OkexDataMessage) { | ||
return derivativeTickerChannels.includes(message.table) | ||
const channels = this._exchange === 'okex-futures' ? this._futuresChannels : this._swapChannels | ||
return channels.includes(message.table) | ||
} | ||
getFilters(symbols?: string[]) { | ||
return mapToFilters(derivativeTickerChannels, symbols) | ||
const channels = this._exchange === 'okex-futures' ? this._futuresChannels : this._swapChannels | ||
return channels.map(channel => { | ||
return { | ||
channel, | ||
symbols | ||
} | ||
}) | ||
} | ||
@@ -151,3 +116,3 @@ | ||
for (const okexMessage of message.data) { | ||
const pendingTickerInfo = this.pendingTickerInfoHelper.getPendingTickerInfo(okexMessage.instrument_id, 'okex') | ||
const pendingTickerInfo = this.pendingTickerInfoHelper.getPendingTickerInfo(okexMessage.instrument_id, this._exchange) | ||
if ('funding_rate' in okexMessage) { | ||
@@ -231,1 +196,5 @@ pendingTickerInfo.updateFundingRate(Number(okexMessage.funding_rate)) | ||
type OkexBookLevel = [number | string, number | string, number | string, number | string] | ||
type OKEX_EXCHANGES = 'okex' | 'okcoin' | 'okex-futures' | 'okex-swap' | ||
type OKEX_MARKETS = 'spot' | 'swap' | 'futures' |
@@ -43,2 +43,4 @@ import { Exchange, Filter } from '../types' | ||
okex: OkexRealTimeFeed, | ||
'okex-futures': OkexRealTimeFeed, | ||
'okex-swap': OkexRealTimeFeed, | ||
'huobi-dm': HuobiDMRealTimeFeed, | ||
@@ -45,0 +47,0 @@ 'huobi-us': HuobiUSRealTimeFeed, |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
590968
10385