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

# Trading account

> One account per wallet that trades every venue, committed orders, the bin books and the order book, with a browser trading key that needs no wallet prompt and can only ever send funds back to your wallet.

Every trade in the app goes through your trading account. You set it up once, fund it from your wallet, and then trade with a trading key that lives in your browser and signs without a wallet prompt. Hyperliquid works the same way: a deposit, then trading with a key that can trade but can't take funds anywhere else.

The account trades every venue:

| Venue | When | Price |
| - | - | - |
| [Committed orders](https://docs.continuum.markets/flows/trade.md#committed-orders) | While the market is open | The next official price, plus a spread |
| [Bin book](https://docs.continuum.markets/flows/trade.md#bin-books) | While the market is closed | The pool's quote, from the last official price |
| [Order book](https://docs.continuum.markets/flows/order-book.md) | Any hour | What other traders set |

Tokens you buy stay in the account until you withdraw them. They're the same SPL tokens as anywhere else, and moving them to your wallet takes one click.

## Setting up

One wallet approval does three things:

1. Opens the account: a record of who may trade for you, and a trader address that holds your funds, book seats and orders.
2. Puts a trading key in your browser, made by the browser's crypto API with a private key that can't be exported, and stored for this site only.
3. Sends about 0.03 SOL: rent for book seats, orders and committed orders, and fees for the key's transactions. You can take what's left back.

The key lasts 30 days, the program's maximum. **Turn off** revokes it at once and sends its unused fee SOL back.

## What the key can do

| | Your wallet | Trading key |
| - | - | - |
| Trade: market and limit orders, the pool, committed orders | Yes | Yes |
| Cancel book orders | Yes | Yes |
| Move funds between the account and a book | Yes | Yes |
| Withdraw | Yes, only to your wallet | Yes, only to your wallet |
| Move funds in from your wallet | Yes | No |
| Grant or revoke the key | Yes | No |

Nothing the key signs can send funds anywhere except your own wallet. The program checks that every withdrawal pays your wallet's own token account, whoever signs it.

A stolen key could still trade badly with an accomplice on the other side of a book. So the program holds every key-signed book order, and every key-signed pool fill, to a backstop band around the posted price: `3 · σ · √(t / 30s) + 10%`, clamped to 10%–25%. A pool fill is judged on what actually moved, so a key can't force a fill deep into the book either. Committed orders fill at the official price, so there's no one to trade with. Orders your wallet signs are not checked.

The key also has a total budget, so a thief can't just keep placing orders. It is \$10,000 by default. When you turn the key on you can pick \$1,000, \$10,000, \$100,000 or **No limit**, and the trading panel shows "\$X of \$Y left". The budget counts what the key's orders commit when they are placed. A bid counts at its quote, an ask, a pool sale and a committed sale at the NAV of what they sell, and a pool buy at the cUSDC it pays. Cancelled orders still count, and so do fills, because nothing is refunded to the budget. When it runs out, the app asks you to approve the key again, which resets the count. Orders your wallet signs don't use the budget.

The app sets no per-order limit. The program supports one (`max_order_quote`), but it bounds each order, not the total, so the budget and the band do the work.

A key can place orders only on a market's canonical book, one per side, which the program records for each market. All 13 active markets have them. Your wallet can use any book. A key can't trade a market that is not active: orders, pool swaps and committed orders fail with `MarketNotActive`, while cancels still work.

## Funding a trade

A trade draws on the account first. A book order uses that book's seat first, then the account. If neither covers it, the app moves the difference in from your wallet in the same transaction, and your wallet signs that one instead of the key. When the account's rent SOL is low, a wallet-signed trade tops it back up in the same approval.

After a fill, proceeds stay in the account, ready for the next trade. A committed order that can't fill is refunded to the account.

## Staking S for the rebate

The [short rebate](https://docs.continuum.markets/concepts/short-rebate.md) pays cUSDC to S that is staked from your trading account. S in your wallet, in a book seat or in the account's token account earns nothing until it is staked.

1. **Open a position** for the market, once. `open_rebate_position` creates an empty position and vault, and anyone may pay its rent.
2. **Stake.** `stake_rebate` moves S from the account's token account into the position's vault. The owner, the trading key or the keeper can sign it.
3. **Claim.** `claim_rebate` pays what the position has earned into the account's own cUSDC token account. The owner, the key or the keeper can sign it, and the money can't go anywhere else.
4. **Unstake.** `unstake_rebate` moves S back to the account. Only the owner or the trading key can sign it, and the keeper never can.

Staked S earns exactly while it is staked, because staking and unstaking each settle first. There is no lockup and no penalty for unstaking early, and earnings stay claimable after an unstake. Staked S is out of the account's token account, so it isn't there to sell or to place an order against until you unstake it. The app unstakes what a sale or withdrawal needs in the same transaction. The rate can be 0, and it depends on the market's collateral yield and on how long traders are net long, so read `RebateMarket.rate_bps` from chain. Instruction and account details are on the [trading program](https://docs.continuum.markets/programs/trading.md) page.

## Where a market order goes

* While a market is closed, the pool's quotes and traders' orders are [one book](https://docs.continuum.markets/flows/order-book.md#one-book-while-closed). A market order takes the cheapest offers first when you buy and the highest bids first when you sell, from either, in one transaction. At the same price, traders' orders fill first.
* While a market is open, a market order is a committed order, estimated at the current price; it fills at the next one. Traders' orders take it instead only when they fill all of it now for less when you buy, or for more when you sell. While committed orders pause for a top-up, or one of yours is pending, the book still trades.
* A limit order rests on the order book. One priced through the pool's quote takes from the pool first, then rests the rest.

The ticket shows what the order gets and where it fills from; there is no venue to pick.

## While a market is closed

The pool quotes from the last official price. When outside markets move past its spread (Hyperliquid's stock perps, pre- and after-hours quotes, index futures, Coinbase's gold and euro tokens), the keeper pulls the side a trader could profit from, and those quotes leave the book. The side left behind still prices the close, so the app warns anyone trading into it: after a rise, a sale gets the pool's bid from before the move, and a limit order can wait for a higher one.

## Your balances

The trading panel shows the account's cash and tokens for the market you're on. The portfolio counts everything the account holds: its token accounts, its seats on every book, and what its open book orders have set aside. Mint, redeem and burn still spend from your wallet, so withdraw first if you need tokens there.

## Closing the account

**Close account** returns everything to your wallet. It first sends every balance, in the account's token accounts and in its book seats, back to your wallet with the key. Then one wallet approval sends the key's unused fee SOL back and closes the account, its token accounts and its rent. It waits while you have open book orders or a committed order in flight.

One cost never comes back: each book seat, and each book slot an order once needed, is an 80-byte block of rent that Manifest keeps. The seats stay yours, and work again if you open the account later.

## Program

`trading`, `Anyy78cCJqapwvvFsignmQ45an5PCg9HfeDhDtAPNfmA` (devnet). IDL: [`idl/trading.json`](https://github.com/continuum-markets/continuum-docs/blob/main/idl/trading.json).

| Account | Seeds |
| - | - |
| Rules (`TradingRules`) | `["account", owner]` |
| Trader (holds funds, seats and orders, pays rent) | `["trader", owner]` |

| Instruction | Signer | What it does |
| - | - | - |
| `open_account` | Owner | Creates the rules account |
| `set_session(SessionParams)`, `revoke_session` | Owner | Grants or revokes the trading key. `SessionParams { key, expires_at, max_order_quote, max_session_quote }`, where `max_session_quote` is the key's total budget in cUSDC atoms (6 decimals): 0 means the program default of \$10,000, and `u64::MAX` means no limit. `set_session` resets the spent counter |
| `set_canonical_books` | The trading program's upgrade authority | Records a market's canonical Manifest book for each side in a `CanonicalBooks` account |
| `deposit` | Owner | Wallet → account |
| `withdraw` | Owner or key | Account → the owner's own token account |
| `withdraw_sol` | Owner | Trader's rent SOL → owner |
| `close_account` | Owner | Closes the empty token accounts and the rules account, and sends their rent and the trader's SOL to the owner |
| `claim_seat`, `deposit_to_market`, `withdraw_from_market` | Owner or key | Manifest seats. For a key, `claim_seat` takes the market's `CanonicalBooks` account as `remaining[0]` |
| `place_orders` | Owner or key | Manifest orders and cancels; up to two global groups (mint, global, global vault, market vault, token program) as remaining accounts, each checked against the market. A key must pass the rules account as writable, and the market's `CanonicalBooks` account as the first remaining account |
| `swap_pool` | Owner or key | The CLP's `pool_swap` from the account. On a capped market, pass the pool long and short synth vaults and the CLP's long and short token accounts as remaining accounts; `swap_pool` hands them on to `pool_swap` for the [exposure cap](https://docs.continuum.markets/flows/trade.md#exposure-cap). A key must pass the rules account as writable |
| `commit_order` | Owner or key | The CLP's `commit_swap` from the account; the order's owner is the trader address. A key must pass the rules account as writable |
| `open_rebate_position` | Anyone | Opens the account's [rebate position](https://docs.continuum.markets/programs/trading.md#open_rebate_position) for a market |
| `stake_rebate`, `claim_rebate` | Owner, key or keeper | Stakes S into the rebate vault; pays earnings to the trader's own cUSDC account |
| `unstake_rebate` | Owner or key | Returns staked S to the account. Never the keeper |

Session spend is recorded in `TradingRules` (186 bytes): `max_session_quote` at offset 122, `session_spent_quote` at 130, and 48 reserved bytes. A key-signed call that doesn't pass the rules account as writable fails with `SessionAccountReadOnly`, and one past the budget fails with `SessionBudgetExceeded`. The price-band check is exact at any NAV.

A `CanonicalBooks` account is the PDA `["canonical_books", mr_market]`, 137 bytes, holding the canonical long and short book. A key-signed book call without it fails with `CanonicalBooksMissing`, and with any other book it fails with `NotCanonicalBook`.

A committed order placed from the account is owned by the trader address. Settlement pays the token accounts recorded at commit, and refunds return there, the same as for any other order. If a recorded account can't receive, the funds are [held for claim](https://docs.continuum.markets/flows/trade.md#held-orders).


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