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

Last updated