def test_update_correctly_updates_analyzer(self):
        # Arrange
        analyzer = SpreadAnalyzer(AUDUSD_SIM.id, 1000)
        tick1 = QuoteTick(
            AUDUSD_SIM.id,
            Price("0.80000"),
            Price("0.80010"),
            Quantity(1),
            Quantity(1),
            0,
        )

        tick2 = QuoteTick(
            AUDUSD_SIM.id,
            Price("0.80002"),
            Price("0.80008"),
            Quantity(1),
            Quantity(1),
            0,
        )

        # Act
        analyzer.handle_quote_tick(tick1)
        analyzer.handle_quote_tick(tick2)

        # Assert
        self.assertAlmostEqual(6e-05, analyzer.current)
        self.assertAlmostEqual(8e-05, analyzer.average)
    def test_update_correctly_updates_analyzer(self):
        # Arrange
        analyzer = SpreadAnalyzer(AUDUSD_SIM.id, 1000)
        tick1 = QuoteTick(
            instrument_id=AUDUSD_SIM.id,
            bid=Price.from_str("0.80000"),
            ask=Price.from_str("0.80010"),
            bid_size=Quantity.from_int(1),
            ask_size=Quantity.from_int(1),
            ts_event=0,
            ts_init=0,
        )

        tick2 = QuoteTick(
            instrument_id=AUDUSD_SIM.id,
            bid=Price.from_str("0.80002"),
            ask=Price.from_str("0.80008"),
            bid_size=Quantity.from_int(1),
            ask_size=Quantity.from_int(1),
            ts_event=0,
            ts_init=0,
        )

        # Act
        analyzer.handle_quote_tick(tick1)
        analyzer.handle_quote_tick(tick2)

        # Assert
        assert analyzer.current == pytest.approx(6e-05)
        assert analyzer.average == pytest.approx(8e-05)
    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        instance = SpreadAnalyzer(AUDUSD_SIM.id, 1000)

        # Act
        instance.reset()

        # Assert
        self.assertFalse(instance.initialized)
        self.assertEqual(0, instance.current)
    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        instance = SpreadAnalyzer(AUDUSD_SIM.id, 1000)

        # Act
        instance.reset()

        # Assert
        assert not instance.initialized
        assert instance.current == 0
    def test_handle_ticks_initializes_indicator(self):
        # Arrange
        analyzer = SpreadAnalyzer(AUDUSD_SIM.id, 1)  # Only one tick
        tick = TestStubs.quote_tick_5decimal()

        # Act
        analyzer.handle_quote_tick(tick)
        analyzer.handle_quote_tick(tick)

        # Assert
        self.assertTrue(analyzer.initialized)
 def test_update_with_incorrect_tick_raises_exception(self):
     # Arrange
     analyzer = SpreadAnalyzer(AUDUSD_SIM.id, 1000)
     tick = QuoteTick(
         instrument_id=USDJPY_SIM.id,
         bid=Price.from_str("117.80000"),
         ask=Price.from_str("117.80010"),
         bid_size=Quantity.from_int(1),
         ask_size=Quantity.from_int(1),
         ts_event=0,
         ts_init=0,
     )
     # Act, Assert
     with pytest.raises(ValueError):
         analyzer.handle_quote_tick(tick)
    def test_instantiate(self):
        # Arrange
        analyzer = SpreadAnalyzer(AUDUSD_SIM.id, 1000)

        # Act, Assert
        assert analyzer.current == 0
        assert analyzer.current == 0
        assert analyzer.average == 0
        assert analyzer.initialized is False
    def test_instantiate(self):
        # Arrange
        analyzer = SpreadAnalyzer(AUDUSD_SIM.id, 1000)

        # Act
        # Assert
        self.assertEqual(0, analyzer.current)
        self.assertEqual(0, analyzer.current)
        self.assertEqual(0, analyzer.average)
        self.assertEqual(False, analyzer.initialized)
 def test_update_with_incorrect_tick_raises_exception(self):
     # Arrange
     analyzer = SpreadAnalyzer(AUDUSD_SIM.id, 1000)
     tick = QuoteTick(
         USDJPY_SIM.id,
         Price("117.80000"),
         Price("117.80010"),
         Quantity(1),
         Quantity(1),
         0,
     )
     # Act
     # Assert
     self.assertRaises(ValueError, analyzer.handle_quote_tick, tick)