Esempio n. 1
0
    def test_add_price(self):
        # Arrange
        instance = WindowedMinMaxPrices(timedelta(minutes=5))

        # Act
        instance.add_price(
            datetime(2020, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
            Price("1.0"),
        )
        # Assert
        self.assertEqual(Price("1.0"), instance.min_price)
        self.assertEqual(Price("1.0"), instance.max_price)
Esempio n. 2
0
    def test_add_price(self):
        # Arrange
        instance = WindowedMinMaxPrices(timedelta(minutes=5))

        # Act
        instance.add_price(
            datetime(2020, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
            Price.from_str("1.0"),
        )
        # Assert
        assert instance.min_price == Price.from_str("1.0")
        assert instance.max_price == Price.from_str("1.0")
Esempio n. 3
0
    def test_instantiate(self):
        # Arrange
        instance = WindowedMinMaxPrices(timedelta(minutes=5))

        # Act, Assert
        assert instance.min_price is None
        assert instance.max_price is None
Esempio n. 4
0
    def test_instantiate(self):
        # Arrange
        instance = WindowedMinMaxPrices(timedelta(minutes=5))

        # Act
        # Assert
        self.assertEqual(None, instance.min_price)
        self.assertEqual(None, instance.max_price)
    def test_reset(self):
        # Arrange
        instance = WindowedMinMaxPrices(timedelta(minutes=5))

        # Act
        instance.add_price(
            datetime(2020, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
            Price.from_str("1"),
        )
        instance.reset()

        # Assert
        self.assertEqual(None, instance.min_price)
        self.assertEqual(None, instance.max_price)
Esempio n. 6
0
    def test_expire_items(self):
        # Arrange
        instance = WindowedMinMaxPrices(timedelta(minutes=5))

        # Act
        instance.add_price(
            datetime(2020, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
            Price("1.0"),
        )
        # 5 min later (still in the window)
        instance.add_price(
            datetime(2020, 1, 1, 0, 5, 0, tzinfo=pytz.utc),
            Price("0.9"),
        )
        # Allow the first item to expire out
        # This also tests that the new tick is the new min/max
        instance.add_price(
            datetime(2020, 1, 1, 0, 5, 1, tzinfo=pytz.utc),
            Price("0.95"),
        )

        # Assert
        self.assertEqual(Price("0.95"), instance.min_price)
        self.assertEqual(Price("0.95"), instance.max_price)
Esempio n. 7
0
    def test_add_multiple_prices(self):
        # Arrange
        instance = WindowedMinMaxPrices(timedelta(minutes=5))

        # Act
        instance.add_price(
            datetime(2020, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
            Price("1.0"),
        )
        # 5 min later (still in the window)
        instance.add_price(
            datetime(2020, 1, 1, 0, 5, 0, tzinfo=pytz.utc),
            Price("0.9"),
        )

        # Assert
        self.assertEqual(Price("0.9"), instance.min_price)
        self.assertEqual(Price("1.0"), instance.max_price)