예제 #1
0
    def test_from_dict_returns_expected_tick(self):
        # Arrange
        order1 = Order(price=10, size=5, side=OrderSide.BUY, id="1")
        delta1 = OrderBookDelta(
            instrument_id=AUDUSD,
            level=BookLevel.L2,
            delta_type=DeltaType.ADD,
            order=order1,
            ts_event_ns=0,
            ts_recv_ns=0,
        )

        order2 = Order(price=10, size=15, side=OrderSide.BUY, id="2")
        delta2 = OrderBookDelta(
            instrument_id=AUDUSD,
            level=BookLevel.L2,
            delta_type=DeltaType.ADD,
            order=order2,
            ts_event_ns=0,
            ts_recv_ns=0,
        )

        deltas = OrderBookDeltas(
            instrument_id=AUDUSD,
            level=BookLevel.L2,
            deltas=[delta1, delta2],
            ts_event_ns=0,
            ts_recv_ns=0,
        )

        # Act
        result = OrderBookDeltas.from_dict(OrderBookDeltas.to_dict(deltas))

        # Assert
        assert result == deltas
예제 #2
0
    def test_to_dict_returns_expected_dict(self):
        # Arrange
        order1 = Order(price=10, size=5, side=OrderSide.BUY, id="1")
        delta1 = OrderBookDelta(
            instrument_id=AUDUSD,
            level=BookLevel.L2,
            delta_type=DeltaType.ADD,
            order=order1,
            ts_event_ns=0,
            ts_recv_ns=0,
        )

        order2 = Order(price=10, size=15, side=OrderSide.BUY, id="2")
        delta2 = OrderBookDelta(
            instrument_id=AUDUSD,
            level=BookLevel.L2,
            delta_type=DeltaType.ADD,
            order=order2,
            ts_event_ns=0,
            ts_recv_ns=0,
        )

        deltas = OrderBookDeltas(
            instrument_id=AUDUSD,
            level=BookLevel.L2,
            deltas=[delta1, delta2],
            ts_event_ns=0,
            ts_recv_ns=0,
        )

        # Act
        result = OrderBookDeltas.to_dict(deltas)

        # Assert
        assert result == {
            "type": "OrderBookDeltas",
            "instrument_id": "AUD/USD.SIM",
            "level": "L2",
            "deltas":
            '[{"type": "OrderBookDelta", "instrument_id": "AUD/USD.SIM", "level": "L2", "delta_type": "ADD", "order_price": 10.0, "order_size": 5.0, "order_side": "BUY", "order_id": "1", "ts_event_ns": 0, "ts_recv_ns": 0}, {"type": "OrderBookDelta", "instrument_id": "AUD/USD.SIM", "level": "L2", "delta_type": "ADD", "order_price": 10.0, "order_size": 15.0, "order_side": "BUY", "order_id": "2", "ts_event_ns": 0, "ts_recv_ns": 0}]',  # noqa
            "ts_event_ns": 0,
            "ts_recv_ns": 0,
        }