Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Possible bug in get_open_orders()
API

Check out the following quick script I have:

def initialize(context):  
    context.stocks = [sid(24), sid(42000)]  
    context.weights = [0.5,0.5]  
# Will be called on every trade event for the securities you specify.  
def handle_data(context, data):  
    if not get_open_orders():  
        print "no open order START"  
    else:  
        print "open order START"  
    for index in range(len(context.stocks)):  
        if context.stocks[index] not in context.portfolio.positions:  
            order_target_percent(context.stocks[index],context.weights[index])  
            if not get_open_orders(context.stocks[index]):  
                print "no open IN LOOP"  
            else:  
                print "open order IN LOOP"  

You would think that at the end, for the section:

            else:  
                print "open order IN LOOP"  

It would actually print something to the log, however, it never does! However, print "open order START" does print to the console! This has been bugging me for hours now and I can't figure out what is going on.

Output:

2011-10-13PRINTno open order START  
2011-10-13PRINTopen order IN LOOP  
2011-10-13PRINTopen order IN LOOP  
2011-10-14PRINTopen order START  
2011-10-17PRINTno open order START  
2011-10-18PRINTno open order START  
2011-10-19PRINTno open order START  
2011-10-20PRINTno open order START  
2011-10-21PRINTno open order START  
2011-10-24PRINTno open order START  
2011-10-25PRINTno open order START  
2011-10-26PRINTno open order START  
2011-10-27PRINTno open order START  
2011-10-28PRINTno open order START  
2011-10-31PRINTno open order START  
2011-11-01PRINTno open order START  
2011-11-02PRINTno open order START  
2011-11-03PRINTno open order START  
2011-11-04PRINTno open order START  
2011-11-07PRINTno open order START

1 response

Never mind, I'm blind as a bat apparently. The problem is the line context.stocks[index] not in context.portfolio.positions.