> 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`
