> For the complete documentation index, see [llms.txt](https://docs.nexus.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nexus.xyz/api-reference/account/adjust-margin.md).

# POST /account/margin

Add or remove isolated margin on an open position

Add or remove isolated margin on an open position.

`operationId`: `adjustMargin` · CCXT method: `addMargin`

**Authentication:** `hmacAuth`.

## Request body

**Required.** `application/json`. **The contract declares no schema for this body** — only the example below, so a generated client gets an untyped body here.

```json
{
  "market_id": "BTC-USDX-PERP",
  "amount": "100",
  "direction": "add"
}
```

## Responses

| Status | Body                                                                            | Meaning                                                                                                                                                                                                                                                                                                                                                                                                           |
| ------ | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `200`  | [`AdjustMarginResponse`](/api-reference/guides/schemas.md#adjustmarginresponse) | Updated allocated margin and account collateral after the adjustment.                                                                                                                                                                                                                                                                                                                                             |
| `400`  | — *(no schema declared)*                                                        | Invalid amount, position not in isolated mode (MarginModeNotIsolated), or removal breaches the withdrawal floor / exceeds collateral (InsufficientMargin / InsufficientBalance).                                                                                                                                                                                                                                  |
| `401`  | — *(no schema declared)*                                                        | —                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `403`  | — *(no schema declared)*                                                        | —                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `404`  | — *(no schema declared)*                                                        | No open position for the account in this market (NoOpenPosition). Two causes, and one of them is transient. The position may genuinely not exist — or it may have been opened so recently that the risk store, which validates this route and folds committed fills asynchronously, has not seen the fill yet. A `NoOpenPosition` immediately after the order that opened the position is the second case; retry. |
| `429`  | — *(no schema declared)*                                                        | —                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `503`  | — *(no schema declared)*                                                        | The adjustment was decided but could not be durably recorded, and was rolled back — collateral and allocated margin are unchanged (IsolatedMarginNotRecorded). Retry.                                                                                                                                                                                                                                             |

## Example

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST 'https://exchange.nexus.xyz/api/exchange/account/margin' \
  -H 'X-API-Key: nx_7f3a1b...' \
  -H 'X-Timestamp: 1776033911836' \
  -H 'X-Signature: <hmac-sha256>' \
  -H 'Content-Type: application/json' \
  -d '{
  "market_id": "BTC-USDX-PERP",
  "amount": "100",
  "direction": "add"
}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

headers = {
    "X-API-Key": "nx_7f3a1b...",
    "X-Timestamp": "1776033911836",
    "X-Signature": "<hmac-sha256>",
    "Content-Type": "application/json"
}
payload = {
    "market_id": "BTC-USDX-PERP",
    "amount": "100",
    "direction": "add"
}

response = requests.post("https://exchange.nexus.xyz/api/exchange/account/margin", headers=headers, json=payload)
response.raise_for_status()
print(response.json())
```

{% endtab %}

{% tab title="TypeScript" %}

```typescript
const response = await fetch("https://exchange.nexus.xyz/api/exchange/account/margin", {
  method: "POST",
  headers: {
    "X-API-Key": "nx_7f3a1b...",
    "X-Timestamp": "1776033911836",
    "X-Signature": "<hmac-sha256>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "market_id": "BTC-USDX-PERP",
    "amount": "100",
    "direction": "add"
  }),
});
if (!response.ok) throw new Error(`${response.status} ${await response.text()}`);
console.log(await response.json());
```

{% endtab %}
{% endtabs %}

`X-Signature` is a placeholder: it is derived from this specific request. See [Authentication](/api-reference/guides/authentication.md) for the canonical string and the HMAC rule.

***

<sub>Generated from</sub> <sub></sub><sub>`eng/apps/exchange/api/openapi.json`</sub> <sub></sub><sub>(spec</sub> <sub></sub><sub>`0.9.72`</sub><sub>). Do not edit by hand — regenerate with</sub> <sub></sub><sub>`python3 product/docs/tools/api-reference/generate.py`</sub><sub>. Hand-authored context lives in the Guides pages.</sub>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.nexus.xyz/api-reference/account/adjust-margin.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
