示例#1
0
    def test_update_order_when_not_connected_logs_and_does_not_send(self):
        # Arrange
        order = self.order_factory.stop_market(
            ETHUSDT_BINANCE.id,
            OrderSide.BUY,
            Quantity.from_int(100),
            Price.from_str("1000.00"),
        )

        command = UpdateOrder(
            self.trader_id,
            order.strategy_id,
            order.instrument_id,
            order.client_order_id,
            order.venue_order_id,
            Quantity.from_int(100),
            Price.from_str("1010.00"),
            None,
            self.uuid_factory.generate(),
            self.clock.timestamp_ns(),
        )

        # Act
        self.exec_client.update_order(command)

        # Assert
        assert True  # No exceptions raised
示例#2
0
 def update_order_command(instrument_id=None, client_order_id=None):
     return UpdateOrder(
         instrument_id=instrument_id or BetfairTestStubs.instrument_id(),
         trader_id=BetfairTestStubs.trader_id(),
         account_id=BetfairTestStubs.account_id(),
         client_order_id=client_order_id or ClientOrderId("1"),
         quantity=Quantity(50),
         price=Price(0.74347, precision=5),
         command_id=BetfairTestStubs.uuid(),
         timestamp_ns=BetfairTestStubs.clock().timestamp_ns(),
     )
示例#3
0
    def test_update_order_with_default_settings_sends_to_client(self):
        # Arrange
        self.exec_engine.start()

        strategy = TradingStrategy(order_id_tag="001")
        strategy.register_trader(
            TraderId("TESTER-000"),
            self.clock,
            self.logger,
        )

        self.exec_engine.register_strategy(strategy)

        order = strategy.order_factory.stop_market(
            AUDUSD_SIM.id,
            OrderSide.BUY,
            Quantity.from_int(100000),
            Price.from_str("1.00010"),
        )

        submit = SubmitOrder(
            self.trader_id,
            strategy.id,
            PositionId.null(),
            order,
            self.uuid_factory.generate(),
            self.clock.timestamp_ns(),
        )

        update = UpdateOrder(
            self.trader_id,
            strategy.id,
            order.instrument_id,
            order.client_order_id,
            order.venue_order_id,
            order.quantity,
            Price.from_str("1.00010"),
            None,
            self.uuid_factory.generate(),
            self.clock.timestamp_ns(),
        )

        self.risk_engine.execute(submit)

        # Act
        self.risk_engine.execute(update)

        # Assert
        assert self.exec_client.calls == [
            "connect", "submit_order", "update_order"
        ]
        assert self.risk_engine.command_count == 2
        assert self.exec_engine.command_count == 2
示例#4
0
 def update_order_command(instrument_id=None, client_order_id=None):
     if instrument_id is None:
         instrument_id = BetfairTestStubs.instrument_id()
     return UpdateOrder(
         trader_id=BetfairTestStubs.trader_id(),
         strategy_id=BetfairTestStubs.strategy_id(),
         instrument_id=instrument_id,
         client_order_id=client_order_id
         or ClientOrderId("O-20210410-022422-001-001-1"),
         venue_order_id=VenueOrderId("001"),
         quantity=Quantity.from_int(50),
         price=Price(0.74347, precision=5),
         command_id=BetfairTestStubs.uuid(),
         timestamp_ns=BetfairTestStubs.clock().timestamp_ns(),
     )
    def test_update_order_raises_not_implemented_error(self):
        # Arrange
        # Act
        command = UpdateOrder(
            AUDUSD_SIM.id,
            self.trader_id,
            self.account_id,
            ClientOrderId("O-123456789"),
            Quantity(120000),
            Price("1.00000"),
            self.uuid_factory.generate(),
            self.clock.timestamp_ns(),
        )

        # Assert
        self.assertRaises(NotImplementedError, self.client.update_order,
                          command)
    def test_update_order_raises_not_implemented_error(self):
        # Arrange
        # Act
        command = UpdateOrder(
            self.trader_id,
            StrategyId("SCALPER-001"),
            AUDUSD_SIM.id,
            ClientOrderId("O-123456789"),
            VenueOrderId("001"),
            Quantity.from_int(120000),
            Price.from_str("1.00000"),
            self.uuid_factory.generate(),
            self.clock.timestamp_ns(),
        )

        # Assert
        self.assertRaises(NotImplementedError, self.client.update_order,
                          command)
    def test_serialize_and_deserialize_amend_order_commands(self):
        # Arrange
        command = UpdateOrder(
            AUDUSD_SIM.id,
            self.trader_id,
            self.account_id,
            ClientOrderId("O-123456"),
            Quantity(100000),
            Price("1.00001"),
            uuid4(),
            0,
        )

        # Act
        serialized = self.serializer.serialize(command)
        deserialized = self.serializer.deserialize(serialized)

        # Assert
        self.assertEqual(command, deserialized)
        print(b64encode(serialized))
        print(command)
    def test_serialize_and_deserialize_amend_order_commands(self):
        # Arrange
        command = UpdateOrder(
            self.trader_id,
            StrategyId("SCALPER-001"),
            AUDUSD_SIM.id,
            ClientOrderId("O-123456"),
            VenueOrderId("001"),
            Quantity(100000, precision=0),
            Price(1.00001, precision=5),
            uuid4(),
            0,
        )

        # Act
        serialized = self.serializer.serialize(command)
        deserialized = self.serializer.deserialize(serialized)

        # Assert
        assert deserialized == command
        print(b64encode(serialized))
        print(command)