# API

You can trade permissionlessly using CAP's smart contracts without a UI.

### Parameter Formatting

All numbers should be submitted in **base units** (8 decimals) unless otherwise noted. So 10 ETH would be submitted as `10 * 10^8 = 1000000000`.

Parameters that require specific formatting:

#### productId

The product you want to trade, submitted in bytes32 format.

* ETH-USD: `0x4554482d55534400000000000000000000000000000000000000000000000000`
* BTC-USD: `0x4254432d55534400000000000000000000000000000000000000000000000000`

**currency**

The address of the currency you want to use for your trade.

* ETH: `0x0000000000000000000000000000000000000000`
* USDC: `0xff970a61a04b1ca14834a43f5de4533ebddb5cc8`

### Trading

Go to the [trading contract ](https://arbiscan.io/address/0xbEd32937D8A5D1421241F52809908f1a17D75bDb)and connect your wallet.

#### Submit an order

Scroll down to submitOrder and enter:

* **`payableAmount`** is your margin if submitting an ETH based trade. Enter the amount in wei (18 decimals). For ERC20 based trades, leave this blank and enter the amount in the **margin** field.
* **`productId`**.
* **`currency`**.
* **`isLong`**. Enter 1 to go long, 0 to go short.
* **`margin`**. In base units.
* **`size`**. In base units. Size / margin determines your position's leverage.

#### Cancel an order

If your order has not yet been executed by the oracle, you can cancel it. Scroll down to cancelOrder and enter:

* **`productId`.** Your order's productId.
* **`currency`**. Your order's currency.
* **`isLong`**. Your order's direction (1 for long, 0 for short).

#### Close a position

Scroll down to submitCloseOrder and enter:

* **`payableAmount`** is the fee to pay if submitting an ETH based trade. Enter the amount in wei (18 decimals), usually 0.1% \* your trade size. Otherwise leave blank.
* **`productId`**. Your position's productId.
* **`currency`**. Your position's currency.
* **`isLong`**. Your position's direction.
* **`size`**. In base units. The amount you want to close.


---

# Agent Instructions: 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.cap.finance/extras/api.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.
