From 7302ab301348ead49ea99ba18dc12129af14d5a2 Mon Sep 17 00:00:00 2001 From: Thaddeus Date: Fri, 26 Jul 2024 19:44:54 +0200 Subject: [PATCH] improvement: update trade bar timestamp only if it's newer then last updated one --- src/computable/tradebar.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/computable/tradebar.ts b/src/computable/tradebar.ts index 21e300e..573df4a 100644 --- a/src/computable/tradebar.ts +++ b/src/computable/tradebar.ts @@ -133,7 +133,10 @@ class TradeBarComputable implements Computable { inProgressBar.vwap = (inProgressBar.vwap * inProgressBar.volume + trade.price * trade.amount) / (inProgressBar.volume + trade.amount) // volume needs to be updated after vwap otherwise vwap calc will go wrong inProgressBar.volume += trade.amount - inProgressBar.timestamp = trade.timestamp + + if (trade.timestamp.valueOf() > inProgressBar.timestamp.valueOf()) { + inProgressBar.timestamp = trade.timestamp + } } private _reset() {