Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Robinhood Instant order_target_percent question for rebalancing portfolio

Using Robinhood Instant as my broker, I have the following method for rebalancing my portfolio:

    def rebalance_portfolio(context, SID):  
        order_target_percent(context.aapl,0)  
        order_target_percent(context.msft,0)  
        if SID =="AAPL":  
            order_target_percent(context.aapl,1)  
        elif SID == "MSFT":  
            order_target_percent(context.msft,1)  

So I sell everything off first, then, my hope, is that I reinvest that money into AAPL or MSFT

My question is: will the money from the sell off be available to make purchases with on the next line of code. I understand that if my broker can't fulfill, then I won't be able to sell and I won't get that cash. If it does get filled immediately, can I expect the order_target_percent method to wait for Robinhood to credit that cash to my account immediately? Has anyone run into an issue with this? Just wondering if I should code for the possibility.

Note: I have a Robinhood Instant account so I'm not worried about the T+3 clearing time.

3 responses

I check for open orders and nest my buy/sell orders inside if/elif/else logic based on open positions.

for stock in context.stocks_owned:  
            open_order = get_open_orders()  
            if stock in open_order:  
                    #additional trading logic goes here  
                    if 'condition is met to sell a stock, that still hasn't fully been ordered':  
                        cancel_order(stock)  
                        #this may not be the best solution, but because additional shares may be bought before the algo or broker can cancel the order, I don't want to immediately sell the stocks. Since this is in handle_data, it will run every minute and will pass the first if statement and come to the upcoming if statement. Additionally, if the order cancels fast enough, technically, it should be triggered at the next if statement.  
                    else:  
                        pass  
            if stock not in open_order:  
                  if 'condition is met to sell a stock':  
                              order_target_percent(stock,0)  
                  else:  
                         pass  

Hope this helps!

Sorry, I just noticed you were not under handle_data, but hopefully the concept can still help. Additionally, even with Robinhood instant, you cannot use 100% of the credit on the same day you sell a volatile stock. You still have a decent amount available to 'spend' but not all of it.

Thanks Addison! This was great help.