> For the complete documentation index, see [llms.txt](https://docs.carbon.inc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.carbon.inc/developers/architecture/accounts-and-trading-modes.md).

# Accounts & trading modes

How Carbon accounts, subaccounts and virtual accounts are organized, how cross and isolated margin work for crypto and tradfi, and how to allocate funds.

Carbon's account model has one more level than a typical exchange. Get it right and balances, permissions, and isolation all fall into place.

### The three levels

```mermaid
flowchart TD
    W["Account (your wallet)"] --> S1["Subaccount (PartyA)"]
    W --> S2["Subaccount (PartyA)"]
    S1 --> P1["Cross positions<br/>(shared margin)"]
    S2 --> VA1["Virtual Account → isolated position"]
    S2 --> VA2["Virtual Account → isolated position"]
```

| Level                    | Identifier          | What it is                                                                                                            |
| ------------------------ | ------------------- | --------------------------------------------------------------------------------------------------------------------- |
| **Account**              | wallet address      | Your owner identity — the wallet that signs in. Holds no positions itself.                                            |
| **Subaccount**           | `subaccountAddress` | An on-chain **PartyA**. **Positions live here.** One wallet can own many.                                             |
| **Virtual Account (VA)** | VA address          | A margin-**isolated** container inside a subaccount, for isolated positions (tradfi, or an isolated crypto position). |

Almost every trading and balance endpoint takes a **`subaccountAddress`**, not your wallet — the wallet authorizes, the subaccount trades.

Discover accounts with `GET /v1/accounts/subaccounts`, balances with `/v1/accounts/subaccount/balance`, and isolated VAs with `/v1/accounts/subaccount/isolated-vas`.

### Crypto vs tradfi

A subaccount trades in one mode, which fixes the margin model and which positions are allowed:

|           | **Crypto**                                                                              | **TradFi**                                      |
| --------- | --------------------------------------------------------------------------------------- | ----------------------------------------------- |
| Margin    | **Cross** (default) or **isolated** per position                                        | **Isolated** — each position has its own margin |
| Allowed   | **Cross** or **isolated**                                                               | **Isolated only**                               |
| Container | Subaccount (cross) or Virtual Account (isolated)                                        | Virtual Account per position/group              |
| Risk      | Cross: shared, liquidation considers the whole cross pool. Isolated: ring-fenced per VA | Ring-fenced per VA                              |

> Crypto positions are cross unless you pass `isolate: true`. TradFi positions are always isolated.

#### Cross (crypto)

All positions draw from the shared pool. Open one by simply *not* isolating:

```jsonc
POST /v1/trade/create-position
{ "subaccountAddress": "0x…", "chainId": 42161, "marketId": 1,
  "positionType": "LONG", "orderType": "MARKET", "quantity": 1, "leverage": 10 }
```

#### Isolated (tradfi, or an isolated crypto position)

Each position gets its own VA with dedicated margin:

```jsonc
POST /v1/trade/create-position
{ "subaccountAddress": "0x…", "chainId": 42161, "marketId": 1,
  "positionType": "LONG", "orderType": "MARKET", "quantity": 1, "leverage": 10,
  "isolate": true, "isolationType": "POSITION" }
```

`isolationType` groups risk by `POSITION`, `MARKET`, `MARKET_LONG`, or `MARKET_SHORT`. The VA is funded from its parent subaccount's **free balance**; move margin with `POST /v1/trade/add-margin` and `/remove-margin`.

### Allocated vs free balance

A subaccount's collateral sits in one of two buckets:

| Bucket                 | Field              | What it's for                                                              |
| ---------------------- | ------------------ | -------------------------------------------------------------------------- |
| **Allocated**          | `allocatedBalance` | The **cross** margin pool. Counts toward equity and backs cross positions. |
| **Free (deallocated)** | `freeBalance`      | Uncommitted collateral. This is what **isolated** VAs are funded from.     |

Deposits default to the bucket that matches the subaccount's mode:

* **Crypto** deposits land in the **allocated** balance — ready for cross trading.
* **TradFi** deposits land in the **free (deallocated)** balance — ready to fund isolated positions.

Move funds between the two with the Instant Layer collateral endpoints:

```jsonc
// free → allocated: make funds usable as cross margin
POST /v1/instant-layer/allocate
{ "subaccountAddress": "0x…", "chainId": 42161, "amountWei": "1000000000000000000" }

// allocated → free: make funds available for isolated positions
POST /v1/instant-layer/deallocate
{ "subaccountAddress": "0x…", "chainId": 42161, "amountWei": "1000000000000000000" }
```

Amounts are collateral wei (1e18) as decimal strings. `allocate` requires the `OPEN_POSITION` permission, `deallocate` requires `CLOSE_POSITION`. Deallocating is solvency-checked (the API obtains the required signature for you), so it fails if it would leave open cross positions under-margined. Both execute through the Instant Layer, so the subaccount must be enabled for API access first — see [Enabling API access](https://docs.carbon.inc/developers/http-api/enabling-api-access.md).

### Trading a subaccount over the API

Owning a subaccount isn't enough — it must be enabled for API access and your API key must be granted permissions before it can trade. This one-time setup (via the Carbon app or the API) is covered in its own page: [Enabling API access](https://docs.carbon.inc/developers/http-api/enabling-api-access.md).


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.carbon.inc/developers/architecture/accounts-and-trading-modes.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
