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

# CCXT

CCXT maintains integration docs here: <https://docs.ccxt.com/#/exchanges/aftermath>\
\
The CCXT section of the Aftermath Finance API provides an easy way for users to read from and write to the Sui blockchain for anything related to the Aftermath Perpetuals exchange. The CCXT endpoints are all prefixed with `/api/ccxt`; e.g., `/api/ccxt/build/createAccount`.

### Transaction Execution

Using the CCXT API, you can call `/api/ccxt/build/*` endpoints for several operations and get back the transaction bytes and its signing digest. See the `TransactionBuildResponse` schema for the data that's returned by **all** `/api/ccxt/build/*` endpoints. Then, clients can sign the transaction digest with any of Sui's [supported signature scheme](https://docs.sui.io/concepts/cryptography/transaction-auth/signatures).

The transaction bytes and signatures can be sent back to the corresponding `/api/ccxt/submit/*` endpoint, which will send the authenticated transaction to the Sui network, parse its effects and send them back to the client in an easy-to-understand format.

### Why \`/api/ccxt/build\` endpoints?

Our `/api/ccxt/build` endpoints provide a convenience service for clients that can't do [BCS](https://move-book.com/programmability/bcs.html) and/or Blake2b-256 locally. CCXT also implements a uniform interface across many exchanges, alleviating the overhead of integrating a new exchange.\
\
Our CCXT API:

1. Creates the \[`Transaction`]
2. Serializes (BCS) the `Transaction` into bytes
3. Prepends an [Intent](https://docs.rs/sui-sdk-types/latest/sui_sdk_types/struct.Intent.html) to it (always `[0, 0, 0]` for user transactions on Sui)
4. Hashes the bytes with Blake2b-256

Another important aspect of the `/api/ccxt/build` endpoints is that they will automatically adapt some Move calls depending on the state of the chain, which the service keeps track of internally. This will be used for things like automatically including an oracle update if necessary, but not if the onchain price is fresh enough already.

### Is there any way to verify the response of the first API call?

Yes, you can. The `TransactionBuildResponse.transactionBytes` is the output of step 2 above. You can deserialize into the `Transaction` if you have access to a [BCS](https://move-book.com/programmability/bcs.html) implementation (e.g., [Rust](https://docs.rs/bcs/latest/bcs/), [Go](https://github.com/fardream/go-bcs), [Typescript](https://sdk.mystenlabs.com/bcs)).

### Example user flow

1. Get gas, e.g., from [Sui's Discord](https://discord.com/channels/916379725201563759/1037811694564560966)
2. Get collateral from our [frontend faucet](https://testnet.aftermath.finance/faucet)
3. Create an account using `/api/ccxt/build/createAccount` then `/api/ccxt/submit/createAccount`
4. Call `/api/ccxt/build/deposit` then `/api/ccxt/submit/deposit` into the account (`.type == "account"`) that's created in the last step
5. `/api/ccxt/build/allocate` then `/api/ccxt/submit/allocate` a certain amount to a market (this should automatically create a position)
6. `/api/ccxt/build/createOrders` then `/api/ccxt/submit/createOrders`
7. `/api/ccxt/build/cancelOrders` then `/api/ccxt/submit/cancelOrders`


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.aftermath.finance/for-developers/api/ccxt.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
