> 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/exchange.md).

# Exchange API

All trading operations go through a single endpoint:

```
POST /api/v1/exchange
```

The `action.type` field determines which operation to execute. Every request requires an EIP-712 signature. See [Authentication](/api-reference/signing.md) for signing details.

JavaScript snippets in this section are illustrative pseudocode for action shape and flow. The official high-level SDK examples are currently provided by the Python SDK.

{% hint style="warning" %}
Vault operations can affect vault balances, ownership, withdrawal flow, or lifecycle depending on the action. Do not treat a vault-authorized Agent as trading-only. Review [Agent Safety](/api-reference/agent-safety.md) before automating vault workflows.
{% endhint %}

## Python SDK Examples

The official SDK repository includes runnable examples for common Exchange actions:

* Orders: [place\_order.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/place_order.py), [place\_tp\_sl\_orders.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/place_tp_sl_orders.py), [replace\_order.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/replace_order.py), [place\_bracket\_order.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/place_bracket_order.py), [cancel\_order.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/cancel_order.py), [cancel\_all.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/cancel_all.py)
* Authorization: [faucet\_claim.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/faucet_claim.py), [approve\_agent.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/approve_agent.py), [revoke\_agent.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/revoke_agent.py)
* Account settings: [set\_leverage.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/set_leverage.py), [set\_margin\_mode.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/set_margin_mode.py), [assign\_pos\_margin.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/assign_pos_margin.py)
* Funds and vaults: [withdraw.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/withdraw.py), [vault\_deposit.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/vault_deposit.py), [vault\_withdraw.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/vault_withdraw.py), [bind\_referral.py](https://github.com/afx-dex/afx-python-sdk/blob/main/examples/exchange/bind_referral.py)

## Agent Revocation

Use `revoke_agent.py` or `client.exchange.revoke_agent(...)` to revoke the currently approved Agent wallet. The SDK submits an `approveAgent` action with the zero address and `validitySeconds=0`.

Revocation is a **Master wallet** operation. Keep it available in operational runbooks so automated trading access can be disabled quickly.


---

# 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/exchange.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.
