> For the complete documentation index, see [llms.txt](https://docs.lighter.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lighter.xyz/developers/integration-guides/manage-trading-mode-and-margin.md).

# Manage Trading Mode and Margin

Configure UTA and Multi-Asset Margin through the Lighter Core API. For the concepts, see [Unified Trading Accounts](https://docs.lighter.xyz/trading/unified-trading-accounts.md) and [Multi-Asset Margin](https://docs.lighter.xyz/trading/multi-asset-margin.md).

## Change trading mode

On Lighter Core, switching the mode is a signed L2 transaction, `UpdateAccountConfig`, signed with the account's API key (no wallet signature). It works for master accounts and sub-accounts; each account index has its own mode.

| account\_trading\_mode | Mode          |
| ---------------------- | ------------- |
| `0`                    | Simple        |
| `1`                    | Unified (UTA) |

* Python SDK: `await client.update_account_config(account_trading_mode=1)`. Examples: [enable\_uta.py](https://github.com/elliottech/lighter-python/blob/main/examples/margin/enable_uta.py), [disable\_uta.py](https://github.com/elliottech/lighter-python/blob/main/examples/margin/disable_uta.py).
* lighter-go WASM signer (TypeScript): `SignUpdateAccountConfig(accountTradingMode, skipNonce, nonce, apiKeyIndex, accountIndex)`. See [WASM signer functions](https://docs.lighter.xyz/developers/reference/wasm-signer), then submit the signed transaction with [sendTx](https://docs.lighter.xyz/api/transactions/sendtx).
* To read the current mode, use `account_trading_mode` on [account](https://docs.lighter.xyz/api/account/account).

When UTA is enabled, the account's spot USDC balance moves into the perps margin balance.

To switch back to Simple, use `account_trading_mode=0`. The transaction is rejected when:

* Open spot orders lock USDC in the account (`21143`).
* A non-USDC asset is still enabled as margin; disable it first (`21158`).
* The account is not healthy (`21723`), or its cross USDC collateral is negative (`21300`).

Sending the mode the account is already in returns `21142`.

## Configure margin assets

1. Enable UTA (see [Change trading mode](#change-trading-mode)).
2. Enable margin for the asset with `UpdateAccountAssetConfig`. Python: `await client.update_account_asset_config(asset_index=..., asset_margin_mode=client.ASSET_MARGIN_MODE_ENABLED)`. WASM: `SignUpdateAccountAssetConfig(assetIndex, assetMarginMode, ...)`. The asset's full spot balance moves into its margin (perps) balance in the same transaction.
3. To add more from the spot balance later, transfer it to perps within the same account. Python: `await client.transfer_same_master_account(..., route_from=client.ROUTE_SPOT, route_to=client.ROUTE_PERP)`, with `to_account_index=client.account_index`. WASM: `SignTransfer` with `fromRouteType=1` (spot), `toRouteType=0` (perps), and `toAccountIndex` set to the same account index.

To stop using an asset as margin, call `update_account_asset_config` with `asset_margin_mode=client.ASSET_MARGIN_MODE_DISABLED`. The margin balance moves back to spot. Disabling is rejected with `21300` if the full margin balance is not available to move back to spot.

Python examples: [enable\_eth\_as\_margin.py](https://github.com/elliottech/lighter-python/blob/main/examples/margin/enable_eth_as_margin.py), [disable\_eth\_as\_margin.py](https://github.com/elliottech/lighter-python/blob/main/examples/margin/disable_eth_as_margin.py), [add\_eth\_margin.py](https://github.com/elliottech/lighter-python/blob/main/examples/margin/add_eth_margin.py) (full flow).


---

# 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.lighter.xyz/developers/integration-guides/manage-trading-mode-and-margin.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.
