def test_to_dict_returns_expected_dict(self): # Arrange order = Order(price=10, size=5, side=OrderSide.BUY, id="1") delta = OrderBookDelta( instrument_id=AUDUSD, level=BookLevel.L2, delta_type=DeltaType.ADD, order=order, ts_event_ns=0, ts_recv_ns=0, ) # Act result = OrderBookDelta.to_dict(delta) # Assert assert result == { "type": "OrderBookDelta", "instrument_id": "AUD/USD.SIM", "level": "L2", "delta_type": "ADD", "order_id": "1", "order_price": 10.0, "order_side": "BUY", "order_size": 5.0, "ts_event_ns": 0, "ts_recv_ns": 0, }
def test_from_dict_returns_expected_clear(self): # Arrange delta = OrderBookDelta( instrument_id=AUDUSD, level=BookLevel.L2, delta_type=DeltaType.CLEAR, order=None, ts_event_ns=0, ts_recv_ns=0, ) # Act result = OrderBookDelta.from_dict(OrderBookDelta.to_dict(delta)) # Assert assert result == delta
def test_from_dict_returns_expected_delta(self): # Arrange order = Order(price=10, size=5, side=OrderSide.BUY) delta = OrderBookDelta( instrument_id=AUDUSD, level=BookLevel.L2, delta_type=DeltaType.ADD, order=order, ts_event_ns=0, ts_recv_ns=0, ) # Act result = OrderBookDelta.from_dict(OrderBookDelta.to_dict(delta)) # Assert assert result == delta
def _parse_delta(delta: OrderBookDelta): return OrderBookDelta.to_dict(delta)