Back to Community
Order rejections from IB with order_target_percent at 1.0

Could anyone out there please help me to understand why I’m getting order rejection errors from IB on certain days?

As background, my algo is set up to trade once per day, one minute after market open. The relevant order execution code looks like this:

(Various criteria in code to determine what value is stored in variable name ‘buy_mode’, which determines whether I will place an order for asset1 or sell my holdings in asset1 and switch to asset2 or vice versa.)

if buy_mode == 3:
order_target_percent(context.asset2, 0.0)
order_target_percent(context.asset1, 1.0)

if buy_mode == 2:
order_target_percent(context.asset1, 0.0)
order_target_percent(context.asset2, 1.0)

When I receive the error in my live trading dashboard, for example, it shows that I sold all of the shares of asset2 successfully, but that my order of 100% of my portfolio value for asset1 securities was rejected. It says that, "Your order is not accepted because your Equity with Loan Value of [8631 USD] is insufficient to cover the Initial Margin requirement of [11062 USD]."

This order rejection error keeps on happening every few days and I have to restart the algo. I called IB and they basically just told me that because it is a market order, they don’t know what price I would get filled at ultimately, so I need to have more cash in my account. So, needless to say, this explanation doesn’t really help me if I want to be able to place orders for 100% of my portfolio value. Note that I have also run into this issue at order_target_percent levels less than 1.0 (e.g., at 0.9, 0.8, 0.7). I’m pretty sure the orders would sail through every day with no problem if I set the order_target_percent at 0.5...maybe? However, I don’t particularly want to leave half of my portfolio in cash every day…

By the way, my algo trades fine in backtests with no issues whatsoever, and it worked fine for a few days of live-trading at a time, so I'm trying to understand how I can resolve this issue.

Has anyone else encountered this kind of problem?

2 responses

I found I had to use limit orders with Robinhood due to the volatility of the stock - would not let me place a market order.

I don't use IB, so not sure if this is your problem.

I also found that in backtesting target percent created small amounts of leverage. Because of this I use the Cash/portfolio to ensure it does not leverage

In backtests it's OK to sell than instantly buy again but in the real world things do not work that smoothly. First off when you sell there is a T+3 day waiting period after you sell before the funds become available to buy with, UNLESS you have a margin account. Now if you already have a margin account it's because your margin is not enough to cover the value you sold (pending) and 50% of the amount you bought (this is the initial margin requirement to buy on margin).

I take it you're buying long/short ETF's swapping on a trigger? I would diversify your algo to buy and sell smaller amounts of different long/short ETF pairs, so they don't all trigger at once to reduce your portfolio turnover. OR just put more money in, but set your algo so that it does not touch the "buffer" cash. You can accomplish the second method by reducing your target percent until it no longer happens which should be .5.