def test_set_partial_updates_bar_to_expected_properties(self): # Arrange bar_spec = TestStubs.bar_spec_1min_mid() builder = BarBuilder(bar_spec, use_previous_close=True) partial_bar = Bar( open_price=Price("1.00001"), high_price=Price("1.00010"), low_price=Price("1.00000"), close_price=Price("1.00002"), volume=Quantity("1"), timestamp=UNIX_EPOCH + timedelta(seconds=1), ) # Act builder.set_partial(partial_bar) bar = builder.build() # Assert self.assertEqual(Price("1.00001"), bar.open) self.assertEqual(Price("1.00010"), bar.high) self.assertEqual(Price("1.00000"), bar.low) self.assertEqual(Price("1.00002"), bar.close) self.assertEqual(Quantity("1"), bar.volume) self.assertEqual(UNIX_EPOCH + timedelta(seconds=1), bar.timestamp) self.assertEqual(UNIX_EPOCH + timedelta(seconds=1), builder.last_timestamp)
def test_set_partial_updates_bar_to_expected_properties(self): # Arrange bar_type = TestStubs.bartype_btcusdt_binance_100tick_last() builder = BarBuilder(BTCUSDT_BINANCE, bar_type, use_previous_close=True) partial_bar = Bar( bar_type=bar_type, open_price=Price.from_str("1.00001"), high_price=Price.from_str("1.00010"), low_price=Price.from_str("1.00000"), close_price=Price.from_str("1.00002"), volume=Quantity.from_str("1"), ts_event_ns=1_000_000_000, ts_recv_ns=1_000_000_000, ) # Act builder.set_partial(partial_bar) bar = builder.build_now() # Assert self.assertEqual(Price.from_str("1.00001"), bar.open) self.assertEqual(Price.from_str("1.00010"), bar.high) self.assertEqual(Price.from_str("1.00000"), bar.low) self.assertEqual(Price.from_str("1.00002"), bar.close) self.assertEqual(Quantity.from_str("1"), bar.volume) self.assertEqual(1_000_000_000, bar.ts_recv_ns) self.assertEqual(1_000_000_000, builder.last_timestamp_ns)
def test_set_partial_updates_bar_to_expected_properties(self): # Arrange bar_type = TestStubs.bartype_btcusdt_binance_100tick_last() builder = BarBuilder(BTCUSDT_BINANCE, bar_type) partial_bar = Bar( bar_type=bar_type, open=Price.from_str("1.00001"), high=Price.from_str("1.00010"), low=Price.from_str("1.00000"), close=Price.from_str("1.00002"), volume=Quantity.from_str("1"), ts_event=1_000_000_000, ts_init=1_000_000_000, ) # Act builder.set_partial(partial_bar) bar = builder.build_now() # Assert assert bar.open == Price.from_str("1.00001") assert bar.high == Price.from_str("1.00010") assert bar.low == Price.from_str("1.00000") assert bar.close == Price.from_str("1.00002") assert bar.volume == Quantity.from_str("1") assert bar.ts_init == 1_000_000_000 assert builder.ts_last == 1_000_000_000
def test_set_partial_when_already_set_does_not_update(self): # Arrange bar_type = TestStubs.bartype_btcusdt_binance_100tick_last() builder = BarBuilder(BTCUSDT_BINANCE, bar_type) partial_bar1 = Bar( bar_type=bar_type, open=Price.from_str("1.00001"), high=Price.from_str("1.00010"), low=Price.from_str("1.00000"), close=Price.from_str("1.00002"), volume=Quantity.from_str("1"), ts_event=1_000_000_000, ts_init=1_000_000_000, ) partial_bar2 = Bar( bar_type=bar_type, open=Price.from_str("2.00001"), high=Price.from_str("2.00010"), low=Price.from_str("2.00000"), close=Price.from_str("2.00002"), volume=Quantity.from_str("2"), ts_event=1_000_000_000, ts_init=3_000_000_000, ) # Act builder.set_partial(partial_bar1) builder.set_partial(partial_bar2) bar = builder.build(4_000_000_000) # Assert assert bar.open == Price.from_str("1.00001") assert bar.high == Price.from_str("1.00010") assert bar.low == Price.from_str("1.00000") assert bar.close == Price.from_str("1.00002") assert bar.volume == Quantity.from_str("1") assert bar.ts_init == 4_000_000_000 assert builder.ts_last == 1_000_000_000
def test_set_partial_when_already_set_does_not_update(self): # Arrange bar_type = TestStubs.bartype_btcusdt_binance_100tick_last() builder = BarBuilder(bar_type, use_previous_close=True) partial_bar1 = Bar( bar_type=bar_type, open_price=Price.from_str("1.00001"), high_price=Price.from_str("1.00010"), low_price=Price.from_str("1.00000"), close_price=Price.from_str("1.00002"), volume=Quantity.from_str("1"), timestamp_origin_ns=1_000_000_000, timestamp_ns=1_000_000_000, ) partial_bar2 = Bar( bar_type=bar_type, open_price=Price.from_str("2.00001"), high_price=Price.from_str("2.00010"), low_price=Price.from_str("2.00000"), close_price=Price.from_str("2.00002"), volume=Quantity.from_str("2"), timestamp_origin_ns=1_000_000_000, timestamp_ns=3_000_000_000, ) # Act builder.set_partial(partial_bar1) builder.set_partial(partial_bar2) bar = builder.build(4_000_000_000) # Assert self.assertEqual(Price.from_str("1.00001"), bar.open) self.assertEqual(Price.from_str("1.00010"), bar.high) self.assertEqual(Price.from_str("1.00000"), bar.low) self.assertEqual(Price.from_str("1.00002"), bar.close) self.assertEqual(Quantity.from_str("1"), bar.volume) self.assertEqual(4_000_000_000, bar.timestamp_ns) self.assertEqual(1_000_000_000, builder.last_timestamp_ns)