Unable to replace order

I have created a stop limit order. The order is accepted. Using API V2, I try to replace the order with a new limit price, stop price and quantity:

api.replace_order(order_id, qty=qty, limit_price=limit_price, stop_price=stop_price)

The above code, sometimes works. But oftentimes I receive the below exception:

“unable to replace order, order is already replaced”

What’s the issue?

The issue is that I thought that “replace_order” updates an excising order. But actually the command replaces an order with a new one. The ID of the new order is recorded in “replaced_by” attribute of the old order object.

@Amir Exactly! The new order is also returned by the replace method.

replaced_order = api.replace(old_order.id, stop_price=new_stop_price)

Use that ‘replaced_order.id’ then as the current order number.

1 Like