# Order Cost

### Order Placement

When a user places a new order, we check that the Available Balance for Trading is greater than or equal to the Order Cost, where:

* Available Balance for Trading = Equity - Initial Margin for Open Positions and Orders
* Order Cost for Buy Orders = max(Initial Margin Rate \* New Order Price \* (New Order Size + min(0, 2 \* (Open Position Size + Triggered Buy Order Size 1+ … + Triggered Buy Order Size N))) - Open Loss, 0)
* Order Cost for Sell Orders = max(-Initial Margin Rate \* New Order Price \* (New Order Size + max(0, 2 \* (Open Position Size + Triggered Sell Order Size 1+ … + Triggered Sell Order Size N))) - Open Loss, 0)

In the equations above:

* Open Loss =  min(New Order Size \* (Mark Price - New Order Price), 0)
* Position / Order Size is positive for Long and Negative for Short

### Orders Cancellation

If the Available Balance for Trading becomes less than 0, all open orders except for reduce-only orders are canceled. Additionally, as long as the Available Balance is less than 0, the user can only place orders that reduce the size of existing positions.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.extended.exchange/extended-resources/trading/order-cost.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
