我们如何使用 ibpy 来编辑订单?

How could we use ibpy for editing orders?

我知道在 ibpy 中我可以下订单来创建新订单:

    self._tws.placeOrder(order_id,contract, order)

但是,假设我知道要更改一些已经下单的限价。有没有像:?

    self._tws.editOrder(order_id,contract, order)

或者简单地使用特定的下单 order_id 可以吗?

您只需使用相同的 orderId 但更改了数据再次调用 placeOrder。您只能更改某些字段,但 m_lmtPrice 很容易。

来自文档,

Modification of an open order through the API can be achieved by the same client which placed the original order. In the case of orders placed manually in TWS, the order can be modified by the client with ID 0.

To modify an order, simply call the IBApi.EClient.placeOrder function again with the same parameters used to place the original order, except for the changed parameter. This includes the IBApi.Order.OrderId, which must match the IBApi.Order.OrderId of the original. It is not generally recommended to try to change order parameters other than the order price and order size. To change other parameters, it might be preferable to cancel the original order and place a new order.

Link http://interactivebrokers.github.io/tws-api/modifying_orders.html#gsc.tab=0