Exemplo n.º 1
0
    def test_instantiate(self):
        # Arrange
        indicator = BidAskMinMax(self.instrument_id, timedelta(minutes=5))

        # Act, Assert
        assert indicator.bids.min_price is None
        assert indicator.bids.max_price is None
        assert indicator.asks.min_price is None
        assert indicator.asks.max_price is None
        assert indicator.initialized is False
Exemplo n.º 2
0
    def test_instantiate(self):
        # Arrange
        indicator = BidAskMinMax(self.instrument_id, timedelta(minutes=5))

        # Act
        # Assert
        self.assertEqual(None, indicator.bids.min_price)
        self.assertEqual(None, indicator.bids.max_price)
        self.assertEqual(None, indicator.asks.min_price)
        self.assertEqual(None, indicator.asks.max_price)
        self.assertEqual(False, indicator.initialized)
Exemplo n.º 3
0
    def test_handle_quote_tick(self):
        # Arrange
        indicator = BidAskMinMax(self.instrument_id, timedelta(minutes=5))

        # Act
        indicator.handle_quote_tick(
            QuoteTick(
                self.instrument_id,
                Price("1.0"),
                Price("2.0"),
                Quantity(1),
                Quantity(1),
                0,
            ))
        # 5 min later (still in the window)
        indicator.handle_quote_tick(
            QuoteTick(
                self.instrument_id,
                Price("0.9"),
                Price("2.1"),
                Quantity(1),
                Quantity(1),
                3e11,
            ))

        # Assert
        self.assertEqual(Price("0.9"), indicator.bids.min_price)
        self.assertEqual(Price("1.0"), indicator.bids.max_price)
        self.assertEqual(Price("2.1"), indicator.asks.min_price)
        self.assertEqual(Price("2.1"), indicator.asks.max_price)
    def test_handle_quote_tick(self):
        # Arrange
        indicator = BidAskMinMax(self.symbol, timedelta(minutes=5))

        # Act
        indicator.handle_quote_tick(
            QuoteTick(
                self.symbol,
                Price("1.0"),
                Price("2.0"),
                Quantity(1),
                Quantity(1),
                datetime(2020, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
            )
        )
        # 5 min later (still in the window)
        indicator.handle_quote_tick(
            QuoteTick(
                self.symbol,
                Price("0.9"),
                Price("2.1"),
                Quantity(1),
                Quantity(1),
                datetime(2020, 1, 1, 0, 5, 0, tzinfo=pytz.utc),
            )
        )

        # Assert
        self.assertEqual(Price("0.9"), indicator.bids.min_price)
        self.assertEqual(Price("1.0"), indicator.bids.max_price)
        self.assertEqual(Price("2.1"), indicator.asks.min_price)
        self.assertEqual(Price("2.1"), indicator.asks.max_price)
Exemplo n.º 5
0
    def test_handle_quote_tick(self):
        # Arrange
        indicator = BidAskMinMax(self.instrument_id, timedelta(minutes=5))

        # Act
        indicator.handle_quote_tick(
            QuoteTick(
                instrument_id=self.instrument_id,
                bid=Price.from_str("1.0"),
                ask=Price.from_str("2.0"),
                bid_size=Quantity.from_int(1),
                ask_size=Quantity.from_int(1),
                ts_event=0,
                ts_init=0,
            ))
        # 5 min later (still in the window)
        indicator.handle_quote_tick(
            QuoteTick(
                instrument_id=self.instrument_id,
                bid=Price.from_str("0.9"),
                ask=Price.from_str("2.1"),
                bid_size=Quantity.from_int(1),
                ask_size=Quantity.from_int(1),
                ts_event=3e11,
                ts_init=3e11,
            ))

        # Assert
        assert indicator.bids.min_price == Price.from_str("0.9")
        assert indicator.bids.max_price == Price.from_str("1.0")
        assert indicator.asks.min_price == Price.from_str("2.1")
        assert indicator.asks.max_price == Price.from_str("2.1")
Exemplo n.º 6
0
    def test_reset(self):
        # Arrange
        indicator = BidAskMinMax(self.instrument_id, timedelta(minutes=5))

        indicator.handle_quote_tick(
            QuoteTick(
                self.instrument_id,
                Price("0.9"),
                Price("2.1"),
                Quantity(1),
                Quantity(1),
                0,
            ))

        # Act
        indicator.reset()

        # Assert
        self.assertIsNone(indicator.bids.min_price)
        self.assertIsNone(indicator.asks.min_price)
Exemplo n.º 7
0
    def test_reset(self):
        # Arrange
        indicator = BidAskMinMax(self.instrument_id, timedelta(minutes=5))

        indicator.handle_quote_tick(
            QuoteTick(
                instrument_id=self.instrument_id,
                bid=Price.from_str("0.9"),
                ask=Price.from_str("2.1"),
                bid_size=Quantity.from_int(1),
                ask_size=Quantity.from_int(1),
                ts_event=0,
                ts_init=0,
            ))

        # Act
        indicator.reset()

        # Assert
        assert indicator.bids.min_price is None
        assert indicator.asks.min_price is None
    def test_reset(self):
        # Arrange
        indicator = BidAskMinMax(self.symbol, timedelta(minutes=5))

        indicator.handle_quote_tick(
            QuoteTick(
                self.symbol,
                Price("0.9"),
                Price("2.1"),
                Quantity(1),
                Quantity(1),
                datetime(2020, 1, 1, 0, 5, 0, tzinfo=pytz.utc),
            )
        )

        # Act
        indicator.reset()

        # Assert
        self.assertIsNone(indicator.bids.min_price)
        self.assertIsNone(indicator.asks.min_price)