How could we use ibpy for editing orders?

936 views Asked by At

I know that in ibpy I could place order to create a new order:

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

However, suppose I know want to change the limit price of some already placed order. Is there anything like:?

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

Or simply use place order with the specific order_id is ok?

1

There are 1 answers

0
brian On BEST ANSWER

You just call placeOrder again with the same orderId but with changed data. You can only change certain fields but m_lmtPrice is easy.

From the docs,

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