> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aultblockchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Margin Trading

> Borrow through Lending to trade Spot markets with leverage.

> [!NOTE]
>
> **Testnet-Only.** Margin Trading is available on Ault Testnet. Mainnet currently supports Spot DEX only.

Margin Trading lets you borrow through Lending to make leveraged Spot trades. A buy can borrow the quote asset, and a sell can borrow the base asset. You hold real assets and debt, unlike a Perpetual position.

## Select the account first

Each wallet has one cross-margin account and a separate isolated account for each market. Both are addresses derived from your wallet, so you do not need a new key. A cross account shares collateral and debt across eligible markets. An isolated account covers one market's base and quote assets.

Orders belong to the margin account, so funds in your Spot balance or another account cannot fund them. Deposits become Lending collateral and do not earn supply interest.

## Five rules for a leveraged order

1. **Borrowing can start before a fill.** Placing an order reserves available collateral in the asset you pay. With automatic borrowing, any shortfall is borrowed immediately, and interest runs while the order rests.
2. **Reserved funds stay as collateral.** They still count toward health, but cannot fund another order, withdrawal, or repayment. Modifying an order cannot borrow more, so a larger order needs collateral you already have.
3. **Proceeds stay in the account.** A fill credits the asset you receive, minus fees, as collateral. A fill that would leave the account unsafe can be rejected.
4. **Auto-repayment is optional.** Auto-repay on fill uses proceeds to repay debt in the asset received. Auto-repay on cancel is a separate option, limited to what the order borrowed. Neither guarantees the debt is cleared.
5. **Some order types are not supported.** TWAP and multi-order scale placements cannot be funded with Margin.

## Close exposure and repay

To close, reverse the trade in the same margin account, repay the debt with interest, then withdraw your collateral. Reversing the trade does not repay the loan by itself.

The asset borrowed to fund a buy stays as debt until you repay it. An expired order or an unfilled IOC remainder releases its reservation without triggering auto-repay on cancel, so check your remaining debt.

A CLOB market halt blocks new orders. A service pause does not cancel orders or guarantee that you can withdraw.

## Liquidation

Before any collateral is seized, the account's resting and pending conditional orders are canceled and their reservations are released. If health recovers, nothing is seized.

Otherwise, a liquidator repays debt and receives collateral under the [Lending liquidation rules](https://docs.aultblockchain.com/ault-dex/lending.md#liquidation).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.