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

# API Reference

AFX DEX uses wallet-signed requests and on-chain settlement for perpetual trading. No API keys required -- all Exchange API requests are authenticated via EIP-712 signatures from Ethereum wallets.

<a href="/pages/WCgkp1vggPjuI3svW0zW" class="button primary">Quick Start — First Trade in 5 Minutes</a>

## Base URLs

| Environment | Exchange API                                  | Info API                               | WebSocket                         |
| ----------- | --------------------------------------------- | -------------------------------------- | --------------------------------- |
| **Mainnet** | `https://api.afx.xyz/api/v1/exchange`         | `https://api.afx.xyz/info/...`         | `wss://ws.afx.xyz/ws/dex`         |
| **Testnet** | `https://api-testnet.afx.xyz/api/v1/exchange` | `https://api-testnet.afx.xyz/info/...` | `wss://ws-testnet.afx.xyz/ws/dex` |

{% hint style="info" %}
Start with the **Testnet** environment. Use `faucetClaim` to get free test funds.
{% endhint %}

## Funding Limits

On mainnet, the minimum deposit is 10 USDC and the minimum withdrawal is 2 USDC.

## API Categories

<table data-view="cards"><thead><tr><th>Title</th><th>Description</th><th data-card-target data-type="content-ref">Target</th></tr></thead><tbody><tr><td><strong>Exchange API</strong></td><td>POST /api/v1/exchange — Place/cancel orders, set leverage, vault management. Requires EIP-712 signature.</td><td><a href="/pages/BuhOTIH4l63pXQfDPXCo">/pages/BuhOTIH4l63pXQfDPXCo</a></td></tr><tr><td><strong>Info API</strong></td><td>GET /info/... — Query account, orders, positions, trades, kline, funding rate. No signature required.</td><td><a href="/pages/uz7Xewliilx3mtOBwGXU">/pages/uz7Xewliilx3mtOBwGXU</a></td></tr><tr><td><strong>WebSocket</strong></td><td>Real-time orderbook, kline, ticker, trades, and account state updates via persistent connection.</td><td><a href="/pages/4YkYRib0XiUqm9hKouPx">/pages/4YkYRib0XiUqm9hKouPx</a></td></tr></tbody></table>

## Authentication

{% columns %}
{% column %}

#### Master Wallet

Controls funds and permissions.

Signs: `approveAgent`, `withdraw`

Domain: `SignTransaction`
{% endcolumn %}

{% column %}

#### Agent Wallet

Authorized by Master for daily trading.

Signs: `placeOrder`, `replaceOrder`, `placeBracketOrder`, `cancelOrder`, `setLeverage`, `setMarginMode`, and other authorized trading operations.

Domain: `Exchange`
{% endcolumn %}
{% endcolumns %}

See [Authentication](/api-reference/signing.md) for the full EIP-712 signing specification.

### Permission Boundary

| Operation family                                                                                        | Signature                       | Notes                                                                                                                                                                                                  |
| ------------------------------------------------------------------------------------------------------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Trading actions such as `placeOrder`, `replaceOrder`, `cancelOrder`, `setLeverage`, and `setMarginMode` | Agent wallet                    | Intended for day-to-day trading automation. These actions can change market risk but cannot withdraw account funds to an external address.                                                             |
| `approveAgent`, `revokeAgent`, account `withdraw`, and testnet `faucetClaim`                            | Master wallet                   | Privileged operations. Keep the Master wallet separate from automated trading infrastructure.                                                                                                          |
| Vault operations                                                                                        | Agent wallet in a vault context | Vault actions can affect vault balances, ownership, withdrawal flow, or closure. Do not assume a vault-authorized Agent is trading-only. Review each vault operation before granting automated access. |

{% hint style="warning" %}
Only the Master wallet can authorize or revoke an Agent wallet. Do not give the Master private key to trading bots or AI agents.
{% endhint %}

See [Agent Safety](/api-reference/agent-safety.md) for key handling, revocation, rotation, and vault-operation guidance.

## Common Response Format

```json
{
  "code": 0,
  "message": "success",
  "data": { ... }
}
```

<details>

<summary>Error Codes</summary>

| Code    | Description                   |
| ------- | ----------------------------- |
| `0`     | Success                       |
| `40201` | Unsupported action type       |
| `40204` | Signature verification failed |
| `40207` | Invalid nonce                 |
| `40208` | Request expired               |
| `40220` | Rate limit exceeded           |
| `40230` | Blockchain call failed        |
| `40231` | Transaction broadcast failed  |
| `40006` | Location is not supported     |
| `40280` | Action disabled (emergency)   |
| `40281` | Address banned                |

</details>

## Available Symbols

Query `GET /info/public/product-meta` for the canonical product list. Do not hardcode symbol codes or max leverage from examples, because listed markets and risk parameters can change.

Important fields returned by `product-meta`:

| Field                            | Description                                         |
| -------------------------------- | --------------------------------------------------- |
| `code`                           | Numeric product code used by Exchange API requests. |
| `symbol`                         | Product symbol, such as `BTCUSDC`.                  |
| `maxLeverage`                    | Current maximum leverage for the product.           |
| `pricePrecision`, `qtyPrecision` | Display and input precision.                        |
| `tickSize`, `stepSize`           | Minimum price and quantity increments.              |
| `minOrderValue`                  | Minimum order notional.                             |
| `maxSlippagePct`                 | Maximum allowed market-order slippage ratio.        |

## Rate Limits

| Dimension                              | Limit                        |
| -------------------------------------- | ---------------------------- |
| Per address per action                 | Configurable per action type |
| WebSocket connections per IP           | 10                           |
| WebSocket subscriptions per connection | 50                           |
| WebSocket messages per second          | 50                           |


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.afx.xyz/api-reference/index.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
