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

# Trading API

> Trade through Legend with account-scoped API keys.

Use the Legend Trading API to place, modify, and cancel orders, manage positions, and read your account’s balances and fills.

## Base URL

All trading endpoints are versioned under `/api/trading/v1/*`. API-key registration, revocation, orders, account reads, and execution actions all use `/v1`. The machine-readable contract is at `/api/trading/v1/openapi.json`.

Breaking API changes require a new major path version. The documentation below describes v1.

```text theme={null}
https://app.legend.trade/api/trading/v1
```

## Getting started

1. Sign in to Legend and open Settings → Trading.
2. Create an API key. **Allow trading** is on by default; switch it off for read-only access.
3. Copy the key and store it securely; Legend does not retain the plaintext key.
4. Send it in the `Authorization: Bearer …` header. Include a unique `Idempotency-Key` for each trading action.

Keys remain valid until revoked. Keys can only be created for your main account on mainnet. Revocation prevents future API actions; it does not cancel existing orders or reverse completed trades. Keys cannot withdraw or transfer funds.

```bash theme={null}
export LEGEND_API_BASE="https://app.legend.trade/api/trading"

curl "$LEGEND_API_BASE/v1/account" \
  -H "Authorization: Bearer $LEGEND_API_KEY"
```

Set `LEGEND_API_KEY` to your API key. Keep credentials out of URLs and logs.

## Exchange conventions

* Prices and sizes are decimal strings, with Hyperliquid market precision rules.
* `gtc`, `ioc`, and `alo` map to Hyperliquid’s `Gtc`, `Ioc`, and `Alo` time-in-force values.
* Market execution uses an IOC order with an explicit worst acceptable price. A partially filled IOC may return `canceled` with a nonzero `filled_size`.
* Markets use the venue symbol, including HIP-3 DEX-qualified names. Order retrieval and mutation accept Legend UUIDs or native Hyperliquid order IDs.
* There are no API-specific notional, position-size, or cumulative trading-volume budgets. Exchange requirements, available margin, and request rate limits still apply.
* Legend derives the wallet signer from the authenticated account. Callers cannot supply a wallet signer, vault, or arbitrary exchange action.

Read the [orders reference](/api-reference/trading/orders), [authentication guide](/api-reference/trading/authentication), and [retry rules](/api-reference/trading/errors). The [OpenAPI document](/api-reference/trading/openapi.json) contains the full schema.

Hyperliquid’s [exchange endpoint documentation](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint) describes the underlying order and execution semantics.
