> For the complete documentation index, see [llms.txt](https://docs.nexus.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nexus.xyz/apis-and-rates/apis-and-rates/exchange-rest.md).

# Exchange REST

The REST API at a glance: authentication and keys, account, orders, market data, and stats.

Base URL: `https://api.testnet.nexus.xyz/v1`, the public testnet base.

All routes **except** `/health`, `/openapi.json`, and `/auth/login` require HMAC authentication (see the Sign requests step of the Quickstart). The complete machine-readable schema, including request/response bodies and CCXT method mappings, is at `/openapi.json`.

Conventions:

* All monetary values are decimal **strings**.
* On single-order routes, `market_id` is **required** as a query parameter. The engine routes directly to the owning market.
* Authenticated requests carry `X-API-Key`, `X-Timestamp`, `X-Signature`. The timestamp must be within ±30s of server time.

### Authentication & keys

| Method | Path          | Auth    | Description                                                     |
| ------ | ------------- | ------- | --------------------------------------------------------------- |
| POST   | `/auth/login` | —       | EIP-191 wallet signature → 24h session Bearer token             |
| POST   | `/keys`       | Session | Create an HMAC API key (`key_id` + `secret`; secret shown once) |
| GET    | `/keys`       | Session | List your API keys                                              |
| DELETE | `/keys/{id}`  | Session | Revoke an API key                                               |
| POST   | `/ws/token`   | HMAC    | Mint a 60s single-use token for the `/ws` WebSocket             |
| POST   | `/ws-tokens`  | HMAC    | Legacy token route. Nothing on the current API needs its tokens |

### Account

| Method | Path                                        | Auth | Description                                                           |
| ------ | ------------------------------------------- | ---- | --------------------------------------------------------------------- |
| GET    | `/account`                                  | HMAC | Balance, equity, margin used, margin ratio                            |
| GET    | `/account/summary`                          | HMAC | Portfolio aggregates plus the withdrawable balance                    |
| GET    | `/account/state`                            | HMAC | Portfolio summary **and** all open positions from one coherent read   |
| GET    | `/account/fees`                             | HMAC | Effective maker/taker fee schedule for the account                    |
| POST   | `/leverage`                                 | HMAC | Set the account's standing leverage for one market                    |
| GET    | `/account/portfolio-history?window=&limit=` | HMAC | Equity / cumulative PnL / cumulative volume time-series               |
| GET    | `/positions`                                | HMAC | Open positions with unrealized PnL and per-position risk detail       |
| POST   | `/account/credit`                           | HMAC | Faucet synthetic USDX (testnet; up to 500/day per key)                |
| GET    | `/account/{address}/adl-history?limit=`     | HMAC | Auto-deleveraging events where the account was target or counterparty |

[Portfolio & Account State](https://docs.nexus.xyz/api-reference/guides/portfolio) documents the portfolio routes and the enriched position fields in full, including the nullable-field convention, the `funding_paid` sign, and why `/account/state` is better than two separate calls.

### Orders

| Method | Path                            | Auth | Description                                                           |
| ------ | ------------------------------- | ---- | --------------------------------------------------------------------- |
| POST   | `/orders`                       | HMAC | Place an order of any of the eight order types                        |
| POST   | `/orders/batch`                 | HMAC | Place multiple orders (sequential; results preserve request order)    |
| POST   | `/orders/preview`               | HMAC | Project margin, equity, fee and liquidation impact without submitting |
| GET    | `/orders`                       | HMAC | List open orders                                                      |
| GET    | `/orders/history`               | HMAC | Terminal-status order history                                         |
| GET    | `/orders/{order_id}?market_id=` | HMAC | Get a single order                                                    |
| PATCH  | `/orders/{order_id}?market_id=` | HMAC | Amend an order (atomic cancel-replace; returns a **new** order id)    |
| DELETE | `/orders/{order_id}?market_id=` | HMAC | Cancel a single order                                                 |
| DELETE | `/orders?market_id=`            | HMAC | Cancel all open orders in a market                                    |

Order body fields: `market_id`, `side` (`Buy`/`Sell`), `order_type`, `quantity`, `time_in_force` (`GTC`/`IOC`/`FOK`/`PostOnly`), `price` (limit-family types only), and optional `reduce_only`.

`order_type` takes one of **eight** values: `Limit` and `Market`, plus six conditional types (`StopLimit`, `StopMarket`, `TakeProfitLimit`, `TakeProfitMarket`, `TrailingStop`, `TrailingLimit`). Which of `price`, `trigger_price`, `trailing_offset_bps` and `limit_offset_bps` a request needs depends on the type. See [Order types](/trading/trading/perpetuals/order-types.md) for the trader's view and [Order Types](https://docs.nexus.xyz/api-reference/guides/order-types) for the full per-type requirement matrix.

### Market data

| Method | Path                              | Description                                            |
| ------ | --------------------------------- | ------------------------------------------------------ |
| GET    | `/markets`                        | List all live markets and their status                 |
| GET    | `/markets/summary`                | Mark price, 24h volume, trade count, status per market |
| GET    | `/markets/{id}/ticker`            | Last / bid / ask / volume / change                     |
| GET    | `/markets/{id}/orderbook`         | Level 2 order book depth                               |
| GET    | `/markets/{id}/trades`            | Recent trades                                          |
| GET    | `/markets/{id}/candles`           | OHLCV candles (1m / 5m / 1h)                           |
| GET    | `/markets/{id}/funding`           | Funding rate history                                   |
| GET    | `/markets/{id}/mark-price`        | Current mark price                                     |
| GET    | `/markets/{id}/status`            | Active/halted, reason, timestamp, ADL count            |
| GET    | `/markets/{id}/adl-events?limit=` | Per-market auto-deleveraging history                   |
| GET    | `/tickers`                        | All tickers in one call                                |
| GET    | `/stats`, `/stats/history`        | Exchange-wide stats                                    |

### Streaming

Real-time order book, trade, and account updates are delivered over WebSocket, not REST. See the WebSocket API Reference.

> **Status:** testnet preview. Endpoint set tracks the versioned OpenAPI spec at [`nexus-xyz/nexus-exchange-api`](https://github.com/nexus-xyz/nexus-exchange-api); consult `/openapi.json` for the authoritative, current schema.


---

# 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.nexus.xyz/apis-and-rates/apis-and-rates/exchange-rest.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.
