Ejemplo n.º 1
0
    def test_order_initialized_event_to_from_dict_and_str_repr(self):
        # Arrange
        uuid = UUID4()
        event = OrderInitialized(
            trader_id=TraderId("TRADER-001"),
            strategy_id=StrategyId("SCALPER-001"),
            instrument_id=InstrumentId(Symbol("BTC/USDT"), Venue("BINANCE")),
            client_order_id=ClientOrderId("O-2020872378423"),
            order_side=OrderSide.BUY,
            order_type=OrderType.LIMIT,
            quantity=Quantity.from_str("0.561000"),
            time_in_force=TimeInForce.DAY,
            reduce_only=True,
            options={"price": "15200.10"},
            order_list_id=OrderListId("1"),
            parent_order_id=None,
            child_order_ids=[ClientOrderId("O-2020872378424")],
            contingency=ContingencyType.OTO,
            contingency_ids=[ClientOrderId("O-2020872378424")],
            tags="ENTRY",
            event_id=uuid,
            ts_init=0,
        )

        # Act, Assert
        assert OrderInitialized.from_dict(
            OrderInitialized.to_dict(event)) == event
        assert (
            str(event) ==
            f"OrderInitialized(instrument_id=BTC/USDT.BINANCE, client_order_id=O-2020872378423, side=BUY, type=LIMIT, quantity=0.561000, time_in_force=DAY, reduce_only=True, options={{'price': '15200.10'}}, order_list_id=1, parent_order_id=None, child_order_ids=['O-2020872378424'], contingency=OTO, contingency_ids=['O-2020872378424'], tags=ENTRY)"  # noqa
        )
        assert (
            repr(event) ==
            f"OrderInitialized(trader_id=TRADER-001, strategy_id=SCALPER-001, instrument_id=BTC/USDT.BINANCE, client_order_id=O-2020872378423, side=BUY, type=LIMIT, quantity=0.561000, time_in_force=DAY, reduce_only=True, options={{'price': '15200.10'}}, order_list_id=1, parent_order_id=None, child_order_ids=['O-2020872378424'], contingency=OTO, contingency_ids=['O-2020872378424'], tags=ENTRY, event_id={uuid}, ts_init=0)"  # noqa
        )
Ejemplo n.º 2
0
def deserialize_order_initialised(data: Dict) -> OrderInitialized:
    for k in ("price", "quantity"):
        data[k] = str(data[k])
    options_fields = orjson.loads(
        NAUTILUS_PARQUET_SCHEMA[OrderInitialized].metadata[b"options_fields"])
    data["options"] = orjson.dumps(
        {k: data.pop(k, None)
         for k in options_fields})
    return OrderInitialized.from_dict(data)