Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Live trading concern

When looking at the Live Trading guidelines I see the following...

  • All open orders are cancelled at end of day.

This does not appear to be the case when doing paper trading. For my algo, when I enter into a security I automatically throw out a take profit. I do not want this take profit to go away every day; I want them to remain until hit. Again, they are not going away in the paper trading on Quantopian, but it sounds like in live trading they would? Please help.

8 responses

Yes, to properly replicate live trading, you need to add code to cancel all open orders at the end of the day. And having persistent take-profits will run into the same problem one has when making persistent/trailing stop orders - if you have to re-enter them every day, you need to know what price to put them at, but you can't store that price in context because if the stock splits overnight, or in some cases if there's a dividend, you need to adjust or re-create the limit/stop price.

Thanks Simon,

Is there any way to take the function that cancels all open orders each day?

This is what I do:

def initialize(context):  
    schedule_function(highbar_cancel_all, date_rule=date_rules.every_day(), time_rule=time_rules.market_close(minutes=1))

def highbar_cancel_all(context, data):  
    record(leverage=context.account.leverage)  
    sids_cancelled = set()  
    logged_cancel = False  
    open_orders = get_open_orders()  
    for security, orders in open_orders.iteritems():  
        for oo in orders:  
            if (not logged_cancel):  
                log.warn("Cancelling orders at close")  
                logged_cancel = True  
            sids_cancelled.add(oo.sid)  
            cancel_order(oo)  
    return sids_cancelled  

I do something like that in every single algo I write these days.

sorry, I meant to say is there any way to take away the function that removed all open orders?

Not that I am aware of...

It is not currently possible to have open orders persist overnight in live trading. Even if they are not explicitly cancelled by Quantopian, IB will cancel them because their default orders are DAY orders, which are only active for the current trading trading day.

David, are there any plans to add GTC orders to Quantopian?

It is in our feature queue, but not a top priority at the moment, you just gave it a bump though.