Skip to content

Commit 7302ab3

Browse files
committed
improvement: update trade bar timestamp only if it's newer then last updated one
1 parent 53d98fa commit 7302ab3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/computable/tradebar.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ class TradeBarComputable implements Computable<TradeBar> {
133133
inProgressBar.vwap = (inProgressBar.vwap * inProgressBar.volume + trade.price * trade.amount) / (inProgressBar.volume + trade.amount)
134134
// volume needs to be updated after vwap otherwise vwap calc will go wrong
135135
inProgressBar.volume += trade.amount
136-
inProgressBar.timestamp = trade.timestamp
136+
137+
if (trade.timestamp.valueOf() > inProgressBar.timestamp.valueOf()) {
138+
inProgressBar.timestamp = trade.timestamp
139+
}
137140
}
138141

139142
private _reset() {

0 commit comments

Comments
 (0)