I'm having problems with one of my trading accounts. I'm having trouble getting out of a position. It throws up the error:
"Rejected at RMS - Total sell quantity of account would exceed its limit"
It is a new Funded Topstep account. The maximum number of contracts according to the scaling plan is 2.
I use the Addons/Accounts API to create and submit orders using some ChartTrader custom UI code.
The flow that causes the error is as follows:
Submit Market order for 1 contract.
When the market order is filled, Submit a Limit Order (target) and a Stop Market Order (stop-loss)
Submit Market order for a second contract
When the market order is filled, Submit a Limit Order (target) and a Stop Market Order (stop-loss)
I am now at Max leverage on this account. With an open position of 2 contracts, Plus 2 Limit target orders and 2 StopLoss orders.
I want to close the position at the market.
So I'm doing the following:
firstly. Cancel the stop-loss and target orders;
account.Cancel(new [] { target1, stop1, target2, stop2 });
Then submit a market order to flatten the account:
account.CreateOrder(....)
at this point it throws up the Error: "Rejected at RMS - Total sell quantity of account would exceed its limit"
I believe the issue is the timing of the requests. When the Market Order to flatten the account is submitted, the stop/target orders haven't fully been cancelled. At least one order is still active, and therefore the market order to exit the position plus the not-yet-cancelled stop/target orders would take me over the position size limit.
The issue only seems to happen on one account. A new TopStep Express Funded account. I'm able to reproduce it very consistently. But it doesn't happen on any other accounts. Even a Practice account that TopStep has set up with the same parameters.
Is there anything incorrect with the flow I'm using to close this position?
A "Thread.Sleep(100)" resolves things after the account.Cancel() request. But this is not an idea solution. I also can't use account.Flatten() as The code in question keeps track of its Brackets and knows that it is managing a position of 2... There might be other positions open under normal circumstances.
Comment