示例#1
0
 def bartype_usdjpy_1min_bid() -> BarType:
     return BarType(TestStubs.usdjpy_id(), TestStubs.bar_spec_1min_bid())
示例#2
0
 def bartype_gbpusd_1sec_mid() -> BarType:
     return BarType(TestStubs.gbpusd_id(), TestStubs.bar_spec_1sec_mid())
    def test_handle_trade_tick_when_volume_beyond_threshold_sends_bars_to_handler(
            self):
        # Arrange
        bar_store = ObjectStorer()
        handler = bar_store.store
        instrument_id = TestStubs.audusd_id()
        bar_spec = BarSpecification(100000, BarAggregation.VALUE,
                                    PriceType.LAST)
        bar_type = BarType(instrument_id, bar_spec)
        aggregator = ValueBarAggregator(bar_type, handler, Logger(TestClock()))

        tick1 = TradeTick(
            instrument_id=AUDUSD_SIM.id,
            price=Price.from_str("20.00001"),
            size=Quantity.from_str("3000.00"),
            aggressor_side=AggressorSide.BUY,
            match_id=TradeMatchId("123456"),
            timestamp_origin_ns=0,
            timestamp_ns=0,
        )

        tick2 = TradeTick(
            instrument_id=AUDUSD_SIM.id,
            price=Price.from_str("20.00002"),
            size=Quantity.from_str("4000.00"),
            aggressor_side=AggressorSide.BUY,
            match_id=TradeMatchId("123457"),
            timestamp_origin_ns=0,
            timestamp_ns=0,
        )

        tick3 = TradeTick(
            instrument_id=AUDUSD_SIM.id,
            price=Price.from_str("20.00000"),
            size=Quantity.from_str("5000.00"),
            aggressor_side=AggressorSide.BUY,
            match_id=TradeMatchId("123458"),
            timestamp_origin_ns=0,
            timestamp_ns=0,
        )

        # Act
        aggregator.handle_trade_tick(tick1)
        aggregator.handle_trade_tick(tick2)
        aggregator.handle_trade_tick(tick3)

        # Assert
        self.assertEqual(2, len(bar_store.get_store()))
        self.assertEqual(Price.from_str("20.00001"),
                         bar_store.get_store()[0].open)
        self.assertEqual(Price.from_str("20.00002"),
                         bar_store.get_store()[0].high)
        self.assertEqual(Price.from_str("20.00001"),
                         bar_store.get_store()[0].low)
        self.assertEqual(Price.from_str("20.00002"),
                         bar_store.get_store()[0].close)
        self.assertEqual(
            Quantity.from_str("5000.00"),
            bar_store.get_store()[0].volume)  # TODO: WIP - intermittent?
        self.assertEqual(Price.from_str("20.00002"),
                         bar_store.get_store()[1].open)
        self.assertEqual(Price.from_str("20.00002"),
                         bar_store.get_store()[1].high)
        self.assertEqual(Price.from_str("20.00000"),
                         bar_store.get_store()[1].low)
        self.assertEqual(Price.from_str("20.00000"),
                         bar_store.get_store()[1].close)
        self.assertEqual(
            Quantity.from_str("4999.99"),
            bar_store.get_store()[1].volume)  # TODO: WIP - intermittent?
        self.assertEqual(
            Decimal("40000.11000"),
            aggregator.get_cumulative_value())  # TODO: WIP - Should be 40000
示例#4
0
 def bartype_audusd_1min_ask() -> BarType:
     return BarType(TestStubs.audusd_id(), TestStubs.bar_spec_1min_ask())
    def test_handle_trade_tick_when_volume_beyond_threshold_sends_bars_to_handler(
            self):
        # Arrange
        bar_store = ObjectStorer()
        handler = bar_store.store
        instrument_id = TestStubs.audusd_id()
        bar_spec = BarSpecification(10000, BarAggregation.VOLUME,
                                    PriceType.LAST)
        bar_type = BarType(instrument_id, bar_spec)
        aggregator = VolumeBarAggregator(bar_type, handler,
                                         Logger(TestClock()))

        tick1 = TradeTick(
            instrument_id=AUDUSD_SIM.id,
            price=Price.from_str("1.00001"),
            size=Quantity.from_int(2000),
            aggressor_side=AggressorSide.BUY,
            match_id=TradeMatchId("123456"),
            timestamp_origin_ns=0,
            timestamp_ns=0,
        )

        tick2 = TradeTick(
            instrument_id=AUDUSD_SIM.id,
            price=Price.from_str("1.00002"),
            size=Quantity.from_int(3000),
            aggressor_side=AggressorSide.BUY,
            match_id=TradeMatchId("123457"),
            timestamp_origin_ns=0,
            timestamp_ns=0,
        )

        tick3 = TradeTick(
            instrument_id=AUDUSD_SIM.id,
            price=Price.from_str("1.00000"),
            size=Quantity.from_int(25000),
            aggressor_side=AggressorSide.BUY,
            match_id=TradeMatchId("123458"),
            timestamp_origin_ns=0,
            timestamp_ns=0,
        )

        # Act
        aggregator.handle_trade_tick(tick1)
        aggregator.handle_trade_tick(tick2)
        aggregator.handle_trade_tick(tick3)

        # Assert
        self.assertEqual(3, len(bar_store.get_store()))
        self.assertEqual(Price.from_str("1.00001"),
                         bar_store.get_store()[0].open)
        self.assertEqual(Price.from_str("1.00002"),
                         bar_store.get_store()[0].high)
        self.assertEqual(Price.from_str("1.00000"),
                         bar_store.get_store()[0].low)
        self.assertEqual(Price.from_str("1.00000"),
                         bar_store.get_store()[0].close)
        self.assertEqual(Quantity.from_int(10000),
                         bar_store.get_store()[0].volume)
        self.assertEqual(Price.from_str("1.00000"),
                         bar_store.get_store()[1].open)
        self.assertEqual(Price.from_str("1.00000"),
                         bar_store.get_store()[1].high)
        self.assertEqual(Price.from_str("1.00000"),
                         bar_store.get_store()[1].low)
        self.assertEqual(Price.from_str("1.00000"),
                         bar_store.get_store()[1].close)
        self.assertEqual(Quantity.from_int(10000),
                         bar_store.get_store()[1].volume)
        self.assertEqual(Price.from_str("1.00000"),
                         bar_store.get_store()[2].open)
        self.assertEqual(Price.from_str("1.00000"),
                         bar_store.get_store()[2].high)
        self.assertEqual(Price.from_str("1.00000"),
                         bar_store.get_store()[2].low)
        self.assertEqual(Price.from_str("1.00000"),
                         bar_store.get_store()[2].close)
        self.assertEqual(Quantity.from_int(10000),
                         bar_store.get_store()[2].volume)