Question About "MAX_NUM_ALGO_ORDERS" In Margin Account Isolated. C#

Hello! So from what I’ve read for the Algo Orders(OCO, StopLimit, etc etc) The max number you can have at the same time for Symbol is 10(5 OCO).

So we we create algo order for Example:

My Account have:
USDT = 30k
BTC = 0

I want to buy 1 BTC on market order (Current Price is 30k USDT).
Then Create OCO(One cancle the other)
I create 2 orders:
First order → with Target Price. I will Sell 1 BTC when the price Reach 31k USDT
Second order → with Stop Price. I will Sell 1 BTC When the price drop 29k USDT

We can create 5 of these pairs Which I call Positions. This one is Long.

After this Order I will have in My Account USDT = 0 and BTC = 0, because I have my 1 btc that I bought locked for the OCO Order.

Now Is there a way I could do this without alog Order.
For Example:
I will buy 1 BTC with marked order for 30k
My Account will have:
USDT = 0
BTC = 1

And I will have code in C# that will have the logic for:
I will Sell 1 BTC when the price Reach 31k USDT
I will Sell 1 BTC When the price drop 29k USDT
But the problem is my account will have USDT = 0 and BTC = 1.
Is there a way I can lock this BTC like in the algo order and unlock it when the price reach the point for target or stoploss and then sell it.

Because if I don’t lock it and I want to create Short Position which is:
I want to sell 1 BTC at market Price for 30k
I will Buy 1 BTC when the price drop 28.5k USDT
I will Buy 1 BTC When the price reach 31.5k USDT

and if I do that It will sell the BTC I have and if the first Position I create reach the target or stoploss won’t have the btc to sell .
The idea of the lock is not to sell the BTC I user for the first Position, but to Borrow If I don’t have any.

So is there any way I can mimic the OCO Orders with C# Code using the api and therefore have more then 5 OCO

I believe I only need the part where I can lock and unlock USDT or BTC when I create Market orders. I already have the logic for sell at target or stoploss price.

hi there,

Can you summarize the problem and share what is the question about?

If you can lock base(BTC) or quote(USDT) assets you can mimic the OCO Orders with your code. But instead of 5 OCO orders limit you can have a lot more. But you need to write your logic in your code which I already did.

The following is my answer to the maximum algorithmic order limit. Take the following 2 into consideration:

  • Handling stoplosses manually is terrible.

The second is evident. Crypto price is volatile, your connection might break, Binance isn’t instantaneous in reporting price updates, and it takes way too long when request a market exit order compared to that volatile price movement that broke your stoploss in the first place.

At the time of execution, including slippage, your order might fill at 2x, 3x, or do-you-want-to-risk-it-x times of our initial stoploss, implying 2x, 3x, … loss of your position.

If you really want to avoid using programmatic stop orders and want to keep ‘your options open’ I suggest setting them when price comes near your stoploss.

Therefore Binance will execute your position at approximately your price (excluding slippage) since the order will be in their system, and you’ll keep your algo order count down.

I still do not recommend that due to your algorithm dying, stopping, breaking, getting a power outage, etc. If you open 5 positions using this method, and your device / internet / Binance’s API dies, you will have 5 unprotected orders (hello forced liquidation)

The second take is:

  • Binance doesn’t lock the funds when using stop-limit orders until the stop price is triggered (coming directly from Binance support)

We use stoplosses and entry triggers on all our orders. To ‘save up’ on one algo order (5 max on BTCUSDT) we employ the following approach:

  1. set entry stop-limit order
  2. on trigger, set stoploss stop-limit order

Singe a triggered stop-limit order becomes a limit order (not an algo order) we save up on setting both the entry and the stoploss order at the same time. This way we get an extra order before the limit is hit.

There is a caveat thought. The price might move through our stoploss while we are processing the successful entry and the request for a stoploss is being sent.

That is a big issue because our stoploss order won’t get processed. It will be rejected due to it being triggered immediately.

So in those cases we send a exit market order request as soon as we fetch the response, but that is 2x the time it takes the our request to reach binance and for us to receive the answer from Binance.

During that time the price could go haywire.

Therefore

  • If you can afford creating 2 orders for one position, I wholeheartedly recommend sticking to it. A successful strategy doesn’t need more than 5 open orders at a given time, which you would have.

Other than that, play around. Just take this into consideration. It took me multiple chats with Binance support to figure it out, and multiple refactors to implement it.

1 Like