def test_getting_bar_at_out_of_range_index_raises_exception(self): # Arrange strategy = TradingStrategy(order_id_tag='001') bar_type = TestStubs.bartype_gbpusd_1sec_mid() bar = Bar(Price(1.00001, 5), Price(1.00004, 5), Price(1.00002, 5), Price(1.00003, 5), Volume(100000), datetime(1970, 1, 1, 00, 00, 0, 0, timezone.utc)) strategy.handle_bar(bar_type, bar) # Act # Assert self.assertRaises(IndexError, strategy.bar, bar_type, -2)
def test_can_get_bar(self): strategy = TradingStrategy(order_id_tag='001') bar_type = TestStubs.bartype_gbpusd_1sec_mid() bar = Bar(Price(1.00001, 5), Price(1.00004, 5), Price(1.00002, 5), Price(1.00003, 5), Volume(100000), datetime(1970, 1, 1, 00, 00, 0, 0, timezone.utc)) strategy.handle_bar(bar_type, bar) # Act result = strategy.bar(bar_type, 0) # Assert self.assertEqual(bar, result)
def test_handle_bar_updates_indicator_registered_for_bars(self): # Arrange bar_type = TestStubs.bartype_audusd_1min_bid() strategy = TradingStrategy() strategy.register( trader_id=self.trader_id, portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, logger=self.logger, ) ema = ExponentialMovingAverage(10) strategy.register_indicator_for_bars(bar_type, ema) bar = TestStubs.bar_5decimal() # Act strategy.handle_bar(bar) strategy.handle_bar(bar, True) # Assert assert ema.count == 2