Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
No enough cash when rebalancing several stocks
for i,stock in enumerate(context.stocks):  
        order_target_percent(stock,allocation[i])  

The first order is a sell and the second is a buy.
When I run this, the first stock is filled a market order. Then before it's executed, the second stock was rejected for not having enough cash since the first order hasn't been executed. How can I file the second order after the first is executed?

Thanks

3 responses

Hello Xiaolei,
Maybe if you use something that prevents orders from being placed if there are open orders. Something that uses either the get_open_orders(security) or get_order(order). I use something like this:
for security in context.shorts.index:
if get_open_orders(security):
continue
if data.can_trade(security):
order_target_percent(security, -weight)

Thanks for reply. But I need the order to be placed. If I just continue, the order is skipped.

Can you make the first order a buy, then follow up with the sell? What about scheduling the the functions 1 minute apart from each other?