def _build_order_book_deltas(values):
     return OrderBookDeltas(
         instrument_id=InstrumentId.from_str(values[0]["instrument_id"]),
         level=BookLevelParser.from_str_py(values[0]["level"]),
         deltas=[OrderBookDelta.from_dict(v) for v in values],
         ts_event_ns=data[0]["ts_event_ns"],
         ts_recv_ns=data[0]["ts_recv_ns"],
     )
    def test_serialize_and_deserialize_order_book_deltas(self):

        kw = {
            "instrument_id": "AUD/USD.SIM",
            "ts_event_ns": 0,
            "ts_recv_ns": 0,
            "level": "L2",
        }
        deltas = OrderBookDeltas(
            instrument_id=TestStubs.audusd_id(),
            level=BookLevel.L2,
            deltas=[
                OrderBookDelta.from_dict({
                    "delta_type": "ADD",
                    "order_side": "BUY",
                    "order_price": 8.0,
                    "order_size": 30.0,
                    "order_id": "e0364f94-8fcb-0262-cbb3-075c51ee4917",
                    **kw,
                }),
                OrderBookDelta.from_dict({
                    "delta_type": "ADD",
                    "order_side": "SELL",
                    "order_price": 15.0,
                    "order_size": 10.0,
                    "order_id": "cabec174-acc6-9204-9ebf-809da3896daf",
                    **kw,
                }),
            ],
            ts_event_ns=0,
            ts_recv_ns=0,
        )

        serialized = to_parquet(buff=self.buffer, objects=[deltas])
        deserialized = from_parquet(serialized)

        # Assert
        assert deserialized == [deltas]
Пример #3
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
Пример #4
0
    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 _build_order_book_delta(values):
     return OrderBookDelta.from_dict(values[0])