Cancel order example?
what I'm trying to do in english is this:
If price closes under the lowest of last 50 candles:
create 2 layers of limit buy order at 0.9lowest and 0.8lowest.
if one layer is filled, limit sell at buyprice+5%
if both layers are filled, cancel the sell order above and set a new limit sell order at averagebuyprice+5%
The canceling part is needed because the next round my signal enters, the unfilled sell limit will be there waiting for me.
I haven't found any working examples of cancelling a specific order, and can't make it just by reading the docs.
Strat is working as intended, but I can't get to cancel the sell order.
What I'm trying rn is:
when one layer is filled:
self.order = self.sell(exectype=Order.Limit, price=self.buy1 * 1.05, tradeid=self.something)
if the second layer gets filled:
self.order = self.sell(exectype=Order.Limit, price=self.averagebuy* 1.05)
any help or live example is appreciated. I know I could probably ease my life using oco or brackets but I really would like to understand how to cancel orders just to have it in my toolbox.
run-out last edited by
@firebee You are going to have to track your orders. You can do this either with a list or a dictionary. If just trading one symbol, a list will suffice,otherwise a dict of lists with symbols as keys.
So, based upon what you said above, when you place your orders, you will have
# two limit buy orders. self.ords = [o1, o2]
When these orders fill, you will get a notification in notify order where you can filter for completed trades. As your trades complete, you can take action.
def notify_order(self, order): # Check if an order has been completed if order.status in [order.Completed]: ## Here you have a just completed order. Compare this to your self.ords list and take whatever actions you need. Cancel/create, whatever works.