# How is "openOrderInitialMargin" calculated?

Hi. I’m trying to understand how open orders initial margin from /fapi/v2/account works when there is opened position. Testing on isolated mode, leverage x1.
If there no opened position, it’s simply sum of limit orders (quantity * price) / leverage as i concluded.
But when there’s open long position for e.g. 0.01 BTC and i trying to place sell limit order with quantity 0.02 (it must close existing position and open short for 0.01), openOrderInitialMargin is staying 0 until some point or gives strange numbers, that definetely less than my calculations, even exluding position size. Does anyone have exact formula for this value?

@tantialex that’s not what he wants. He want for “open orders”.

Isolated open order initial margin = abs(isolated present notional) * IMR - abs(size) * IMR * mark price

Ok thank you. But size - what size exactly?

The size of the open order. Tells me your infos like mark price, actual position etc I will tell you

x1, it’s in first message

so, i found out it must be something like that: `MAX[0, (order_qty - abs(pos_size)) * order_price * IMR - abs(pos_size) * mark_price * IMR]`
but this is not 100% accurate. Differs by few usdt

Formulas used when placing an order can be found on our FAQ.

Yes, i have read that article. “initial margin” formula from it works only when no position opened. Question is not about placing an order, but how “open orders initial margin” of existing orders calculated.

Cost = Initial Margin + Open Loss (if any)
Long order has an open loss, thus the cost required to open a long position is higher as we need to take open loss into consideration besides the initial margin.

(i) Cost Required to Open a Long Position

= 104.670109 + 1.04418

= 105.71 (rounding difference)

When a position is active, you must consider the open loss of said position.

When a position is active, you must consider the open loss of said position.

What does it mean? How position can have open loss? Anyway, i don’t see where open losses may appear, real example:

I have long position with entry price 39500 usdt, size 0.01 btc.
Then im placing SELL limit order at price 40000 and qty 0.05.
Mark price “39602.18940937”.
After that, openOrderInitialMargin from “0” changes to “1207.95621182”.

Can you explain how “1207.95621182” comes from this data?