Skip to content

Commit 48649ca

Browse files
committed
Skip indicator updates for revision bars
1 parent bf240e2 commit 48649ca

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

nautilus_trader/common/actor.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4242,7 +4242,7 @@ cdef class Actor(Component):
42424242

42434243
# Update indicators
42444244
cdef list indicators = self._indicators_for_bars.get(bar.bar_type.id_spec_key())
4245-
if indicators:
4245+
if indicators and not bar.is_revision:
42464246
self._handle_indicators_for_bar(indicators, bar)
42474247

42484248
if historical:

tests/unit_tests/common/test_actor.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from nautilus_trader.data.engine import DataEngine
3434
from nautilus_trader.data.messages import DataResponse
3535
from nautilus_trader.execution.engine import ExecutionEngine
36+
from nautilus_trader.indicators.base import Indicator
3637
from nautilus_trader.model.currencies import EUR
3738
from nautilus_trader.model.currencies import USD
3839
from nautilus_trader.model.data import Bar
@@ -1208,6 +1209,50 @@ def test_handle_bar_when_running_sends_to_on_bar(self) -> None:
12081209
assert actor.calls == ["on_start", "on_bar"]
12091210
assert actor.store[0] == bar
12101211

1212+
def test_handle_bar_does_not_update_indicators_for_revision_bars(self) -> None:
1213+
class CountingIndicator(Indicator):
1214+
def __init__(self):
1215+
super().__init__([])
1216+
self.calls = 0
1217+
1218+
def handle_bar(self, bar):
1219+
self.calls += 1
1220+
1221+
def _reset(self):
1222+
self.calls = 0
1223+
1224+
# Arrange
1225+
actor = Actor(config=ActorConfig(component_id=self.component_id))
1226+
actor.register_base(
1227+
portfolio=self.portfolio,
1228+
msgbus=self.msgbus,
1229+
cache=self.cache,
1230+
clock=self.clock,
1231+
)
1232+
1233+
bar = TestDataStubs.bar_5decimal()
1234+
actor.register_indicator_for_bars(bar.bar_type, CountingIndicator())
1235+
indicator = actor.registered_indicators[0]
1236+
1237+
revision_bar = Bar(
1238+
bar_type=bar.bar_type,
1239+
open=bar.open,
1240+
high=bar.high,
1241+
low=bar.low,
1242+
close=bar.close,
1243+
volume=bar.volume,
1244+
ts_event=bar.ts_event,
1245+
ts_init=bar.ts_init,
1246+
is_revision=True,
1247+
)
1248+
1249+
# Act
1250+
actor.handle_bar(revision_bar)
1251+
actor.handle_bar(bar)
1252+
1253+
# Assert
1254+
assert indicator.calls == 1
1255+
12111256
def test_handle_bars(self) -> None:
12121257
# Arrange
12131258
actor = MockActor()

0 commit comments

Comments
 (0)