tardis-dev
Advanced tools
Comparing version 12.2.2 to 12.3.0
@@ -13,3 +13,7 @@ "use strict"; | ||
constructor({ kind, interval, name }) { | ||
this.sourceDataTypes = ['trade']; | ||
// use book_change messages as workaround for issue when time passes for new bar to be produced but there's no trades, | ||
// so logic `compute` would not execute | ||
// assumption is that if one subscribes to book changes too then there's pretty good chance that | ||
// even if there are no trades, there's plenty of book changes that trigger computing new trade bar if time passess | ||
this.sourceDataTypes = ['trade', 'book_change']; | ||
this._type = 'trade_bar'; | ||
@@ -27,18 +31,21 @@ this._kind = kind; | ||
} | ||
*compute(trade) { | ||
*compute(message) { | ||
// first check if there is a new trade bar for new timestamp for time based trade bars | ||
if (this._hasNewBar(trade.timestamp)) { | ||
yield this._computeBar(trade); | ||
if (this._hasNewBar(message.timestamp)) { | ||
yield this._computeBar(message); | ||
} | ||
if (message.type !== 'trade') { | ||
return; | ||
} | ||
// update in progress trade bar with new data | ||
this._update(trade); | ||
this._update(message); | ||
// and check again if there is a new trade bar after the update (volume/tick based trade bars) | ||
if (this._hasNewBar(trade.timestamp)) { | ||
yield this._computeBar(trade); | ||
if (this._hasNewBar(message.timestamp)) { | ||
yield this._computeBar(message); | ||
} | ||
} | ||
_computeBar(trade) { | ||
this._inProgressBar.localTimestamp = trade.localTimestamp; | ||
this._inProgressBar.symbol = trade.symbol; | ||
this._inProgressBar.exchange = trade.exchange; | ||
_computeBar(message) { | ||
this._inProgressBar.localTimestamp = message.localTimestamp; | ||
this._inProgressBar.symbol = message.symbol; | ||
this._inProgressBar.exchange = message.exchange; | ||
const tradeBar = { ...this._inProgressBar }; | ||
@@ -45,0 +52,0 @@ this._reset(); |
@@ -140,3 +140,4 @@ "use strict"; | ||
'openInterest', | ||
'recentTrades' | ||
'recentTrades', | ||
'compositeIndex' | ||
]; | ||
@@ -143,0 +144,0 @@ const BINANCE_DELIVERY_CHANNELS = [ |
{ | ||
"name": "tardis-dev", | ||
"version": "12.2.2", | ||
"version": "12.3.0", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=12" |
@@ -1,2 +0,2 @@ | ||
import { Trade, TradeBar, Writeable } from '../types' | ||
import { BookChange, NormalizedData, Trade, TradeBar, Writeable } from '../types' | ||
import { Computable } from './computable' | ||
@@ -19,3 +19,7 @@ | ||
class TradeBarComputable implements Computable<TradeBar> { | ||
public readonly sourceDataTypes = ['trade'] | ||
// use book_change messages as workaround for issue when time passes for new bar to be produced but there's no trades, | ||
// so logic `compute` would not execute | ||
// assumption is that if one subscribes to book changes too then there's pretty good chance that | ||
// even if there are no trades, there's plenty of book changes that trigger computing new trade bar if time passess | ||
public readonly sourceDataTypes = ['trade', 'book_change'] | ||
@@ -42,21 +46,25 @@ private _inProgressBar: Writeable<TradeBar> | ||
public *compute(trade: Trade) { | ||
public *compute(message: Trade | BookChange) { | ||
// first check if there is a new trade bar for new timestamp for time based trade bars | ||
if (this._hasNewBar(trade.timestamp)) { | ||
yield this._computeBar(trade) | ||
if (this._hasNewBar(message.timestamp)) { | ||
yield this._computeBar(message) | ||
} | ||
if (message.type !== 'trade') { | ||
return | ||
} | ||
// update in progress trade bar with new data | ||
this._update(trade) | ||
this._update(message) | ||
// and check again if there is a new trade bar after the update (volume/tick based trade bars) | ||
if (this._hasNewBar(trade.timestamp)) { | ||
yield this._computeBar(trade) | ||
if (this._hasNewBar(message.timestamp)) { | ||
yield this._computeBar(message) | ||
} | ||
} | ||
private _computeBar(trade: Trade) { | ||
this._inProgressBar.localTimestamp = trade.localTimestamp | ||
this._inProgressBar.symbol = trade.symbol | ||
this._inProgressBar.exchange = trade.exchange | ||
private _computeBar(message: NormalizedData) { | ||
this._inProgressBar.localTimestamp = message.localTimestamp | ||
this._inProgressBar.symbol = message.symbol | ||
this._inProgressBar.exchange = message.exchange | ||
@@ -63,0 +71,0 @@ const tradeBar: TradeBar = { ...this._inProgressBar } |
@@ -154,3 +154,4 @@ export const EXCHANGES = [ | ||
'openInterest', | ||
'recentTrades' | ||
'recentTrades', | ||
'compositeIndex' | ||
] | ||
@@ -157,0 +158,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
1011188
18147