Kana Perps Python REST API

Important Note:

For all the API endpoints below, pass your wallet address as the userAddress parameter.

To track your transactions on-chain (e.g., via Aptos Explorer or Aptos Scan), you must use your profile address, as all on-chain trades are executed using this profile address.

To obtain your profile address, use the /getProfileAddress endpoint and provide your wallet address as the userAddress parameter.

How to Fetch the Profile Address:

Example endpoint: https://perps-tradeapi.kanalabs.io/getProfileAddress?userAddress=0xd01e3a233632a41463bd6d289e99e69e1b50815c7afff710e1c992659a8722f3 Example code: https://docs.kanalabs.io/perpetual-futures/kana-perps/api-docs/kana-perps-python-rest-api#id-20.-get-profile-address

Testnet API Endpoint URL

https://perps-tradeapi.kanalabs.io

Mainnet API Endpoint URL

https://perps-tradeapi.kana.trade

Please ensure that the correct network is used: for Testnet, set NODE_URL = "https://api.testnet.aptoslabs.com/v1" and for Mainnet, set NODE_URL = "https://api.mainnet.aptoslabs.com/v1"

1. Get Market Info

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Market Information:

The following Python script demonstrates how to call the Get Market Info API using the requests library.

2. Get Wallet Account Balance

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Wallet Account Balance Information:

The following Python script demonstrates how to call the Get Wallet Account Balance API using the requests library.

3. Get Profile Balance Snapshot

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Trading Account Balance Information:

The following Python script demonstrates how to call the Get Trading Account Balance API using the requests library.

4. Deposit

  • Method: GET

  • Query Parameters:

    • amount (Required) - The amount of the quote coin to deposit.

    • userAddress (Required) - The address of the user making the deposit.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Depsoit a quote coin:

The following Python script demonstrates how to call the Get Deposit API using the requests library.

5. Withdraw Specific Market

  • Method: GET

  • Query Parameters:

    • marketId (Required) - The ID of the market you want to withdraw.

    • amount (Required) - The amount of the quote coin to withdraw.

    • userAddress (Required) - The address of the user making the withdraw.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Withdraw a quote coin:

The following Python script demonstrates how to call the Get Withdraw API using the requests library.

6. Place Limit Order

  • Method: GET

  • Query Parameters:

    • marketId (Required) - The ID of the market where the limit order will be placed.

    • tradeSide (Required) - Indicates the trade side:

      • true for the long side.

      • false for the short side.

    • direction (Required) - Indicates the direction of the trade:

      • false to open a position.

      • true to close a position.

    • size (Required) - The size of the order.

    • price (Required) - The price at which the order is to be placed.

    • leverage (Required) - The leverage to be used for the order.

    • restriction - Specifies the type of order restriction. It is an optional parameter with a default value of 0. Possible values are:

      • 0 - NO_RESTRICTION: Optionally fill as a taker, then post to the book as a maker.

      • 1 - FILL_OR_ABORT: Abort if any size posts as a maker (only fill).

      • 3 - POST_OR_ABORT: Abort if any size fills as a taker (only post).

      • If restriction is not provided, it defaults to 0. It can either be a number or left undefined.

    • takeProfit - The take profit value is optional. If not provided, it defaults to 0. It can either be a number or left undefined.

    • stopLoss - The stop loss value is also optional. If not provided, it defaults to 0. It can either be a number or left undefined.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Place a limit order:

The following Python script demonstrates how to call the Get Place Limit Order API using the requests library.

7. Place Market Order

  • Method: GET

  • Query Parameters:

    • marketId (Required) - The ID of the market where the limit order will be placed.

    • tradeSide (Required) - Indicates the trade side:

      • true for the long side.

      • false for the short side.

    • direction (Required) - Indicates the direction of the trade:

      • false to open a position.

      • true to close a position.

    • size (Required) - The size of the order.

    • leverage (Required) - The leverage to be used for the order.

    • takeProfit - The take profit value is optional. If not provided, it defaults to 0. It can either be a number or left undefined.

    • stopLoss - The stop loss value is also optional. If not provided, it defaults to 0. It can either be a number or left undefined.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Place a market order:

The following Python script demonstrates how to call the Get Place Market Order API using the requests library.

8. Cancel Multiple Orders

  • Method: POST

  • Request Body:

    • marketId: The ID of the market for which the orders will be canceled.

    • cancelOrderIds: A list of order IDs to cancel.

    • orderSides: The sides of the orders to cancel (true for long, false for short).

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Cancel multiple orders:

The following Python script demonstrates how to call the Post Cancel Multiple Orders API using the requests library.

8. Place Multiple Orders

Request Body :

  • marketId (Required) - The ID of the market where the orders will be placed.

  • orderTypes (Required) - An array of order types for each order:

    • true for limit orders.

    • false for market orders.

  • tradeSides (Required) - An array indicating the trade sides for each order:

    • true for long positions.

    • false for short positions.

  • directions (Required) - An array indicating the direction of each trade:

    • false to open a position.

    • true to close a position.

  • sizes (Required) - An array of sizes for each order.

  • leverages (Required) - An array of leverages for each order.

  • prices (Required) - An array of prices at which each order is to be placed.

  • restriction - Specifies the type of order restriction. It is an optional parameter with a default value of 0. Possible values are:

    • 0 - NO_RESTRICTION: Optionally fill as a taker, then post to the book as a maker.

    • 1 - FILL_OR_ABORT: Abort if any size posts as a maker (only fill).

    • 3 - POST_OR_ABORT: Abort if any size fills as a taker (only post).

    • If restriction is not provided, it defaults to 0. It can either be a number or left undefined.

  • takeProfits - The take profit value is optional. If not provided, it defaults to 0. It can either be a number or left undefined.

  • stopLosses - The stop loss value is also optional. If not provided, it defaults to 0. It can either be a number or left undefined.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Place a multiple orders:

The following Python script demonstrates how to call the Get Place Multiple Orders API using the requests library.

9. Cancel and Place Multiple Orders

Request Body :

  • marketId (Required) - The ID of the market where the orders will be placed.

  • cancelOrderIds (Required) - An array of strings representing the IDs of the orders to be canceled.

  • orderSides (Required) - An array indicating the sides of the orders being canceled:

    • true for long sides.

    • false for short sides.

  • orderTypes (Required) - An array of order types for each order:

    • true for limit orders.

    • false for market orders.

  • tradeSides (Required) - An array indicating the trade sides for each order:

    • true for long positions.

    • false for short positions.

  • directions (Required) - An array indicating the direction of each trade:

    • false to open a position.

    • true to close a position.

  • sizes (Required) - An array of sizes for each order.

  • leverages (Required) - An array of leverages for each order.

  • prices (Required) - An array of prices at which each order is to be placed.

  • restriction - Specifies the type of order restriction. It is an optional parameter with a default value of 0. Possible values are:

    • 0 - NO_RESTRICTION: Optionally fill as a taker, then post to the book as a maker.

    • 1 - FILL_OR_ABORT: Abort if any size posts as a maker (only fill).

    • 3 - POST_OR_ABORT: Abort if any size fills as a taker (only post).

    • If restriction is not provided, it defaults to 0. It can either be a number or left undefined

  • takeProfits - The take profit value is optional. If not provided, it defaults to 0. It can either be a number or left undefined.

  • stopLosses - The stop loss value is also optional. If not provided, it defaults to 0. It can either be a number or left undefined.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to cancel and Place a multiple orders:

The following TypeScript/Node.js script demonstrates how to call the Get Cancel And Place Multiple Orders API using the axios library.

10. Get Open Orders

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Open Orders:

The following Python script demonstrates how to call the Get Open Orders API using the requests library.

11. Get Order History

  • Method: GET

  • Query Parameters:

    • userAddress (Required) - The wallet address to retrieve the order history.

    • marketId (optional) - The ID of the market to filter the order history.

    • offset (Optional) - The offset for paginating the results. limit (Optional) - The maximum number of results to return. order (Optional) - The sort order of the results. Accepts asc or desc.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Order History:

The following Python script demonstrates how to call the Get Order History API using the requests library.

12. Get Positions

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Open Position:

The following Python script demonstrates how to call the Get Open Position API using the requests library.

13. Get Order Status By Order Id

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Order Status B Order Id:

The following Python script demonstrates how to call the Get Order Status By Order Id API using the requests library.

14. Get Fills

Note: For the getFills endpoint, you must pass the profile address, not the wallet address. Please make sure to first call the Get Profile Address endpoint and use that returned address as the address parameter in the getFills request.

  • Method: GET

  • Query Parameters:

    • marketId (Required) - The ID of the market for which fills are retrieved.

    • address (Optional) - The address of the user to filter fills (if applicable).

    • from (Required) - The start time of the range in ISO 8601 format (e.g., 2024-11-21T00:00:00Z).

    • to (Required) - The end time of the range in ISO 8601 format (e.g., 2024-11-21T23:59:59Z).

    • orderId (Required) - The unique identifier of the order to retrieve its status.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Order Status B Order IdFills Data:

The following Python script demonstrates how to call the Get Fills Data API using the requests library.

14. Get Market Price

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Market Price:

The following Python script demonstrates how to call the Get Market Price API using the requests library.

15. Get Last Execution Price

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Last Execution Price:

The following Python script demonstrates how to call the Get Last Execution Price API using the requests library.

16. Get All Open Order Ids

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Open Order Ids:

The following Python script demonstrates how to call the Get Open Order Ids API using the requests library.

17. Update Take Profit

  • Method: GET

  • Query Parameters:

    • marketId (Required) - The ID of the market for which the take profit values will be updated.

    • tradeSide (Required) - The trade side:

      • true for the long side.

      • false for the short side.

    • newTakeProfitPrice (Required) - The new take profit price to be set for the trade.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Update take profit price:

The following Python script demonstrates how to call the Get Update Take Profit Price API using the requests library.

18. Get Account Aptos Balance

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Wallet Account Aptos Balance Information:

The following Python script demonstrates how to call the Get Wallet Account Aptos Balance API using the requests library.

19. Update Stop Loss

  • Method: GET

  • Query Parameters:

    • marketId (Required) - The ID of the market for which the take profit values will be updated.

    • tradeSide (Required) - The trade side:

      • true for the long side.

      • false for the short side.

    • newStopLossPrice (Required) - The new stop loss price to be set for the trade.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Update stop loss price:

The following Python script demonstrates how to call the Get Update Stop Loss Price API using the requests library.

20. Get Profile Address

Example Request:

Copy

Example Response:

  • Status Code: 200 OK

  • Response Body:

Copy

Example Code to Fetch the profile address:

The following TypeScript/Node.js script demonstrates how to call the Get profile address API using the axios library.

21. Collapse position

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to collapse a position:

The following TypeScript/Node.js script demonstrates how to call the collapse position API using the axios library.

22. Get All Trades

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch All trades:

The following Python script demonstrates how to call the Get Open Position API using the requests library.

23. Get Account Apt Balance

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Account Apt Balance Information:

The following TypeScript/Node.js script demonstrates how to call the Get Account Apt Balance API using the axios library.

24. Get Perpetual Asset Info

Endpoint URL: https://perps-tradeapi.kanalabs.io/getPerpetualAssetsInfo

Method: GET

Query Parameters:

  • marketId (optional) – Numeric ID of the market to fetch.

  • baseName (optional) – Name of the base asset (e.g., "ETH", "BTC").

Note: Either marketId or baseName must be provided. If neither is provided, the server will respond with a 400 error.

Example Request:

Example Response:

Example Code:


Get All Perpetual Market Assets

Endpoint URL: https://perps-tradeapi.kanalabs.io/getPerpetualAssetsInfo/allMarkets

Method: GET

Description: Fetches all available perpetual market asset information. This endpoint does not require any query parameters.

Example Request:

Example Response:

Example Code:

25. Add Margin

  • Method: GET

  • Query Parameters:

    • marketId (Required) – The unique identifier of the market where the margin is being added.

    • tradeSide (Required) - Indicates the trade side:

      • true for the long side.

      • false for the short side.

    • amount (Required) – The amount of additional margin to be added to the position.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to add a margin:

The following python demonstrates how to call the Get Add Margin API using the axios library.

26. Get Net Profile Balance

This endpoint returns the net profile balance, which includes both the available balance in trading account and any pending balances from closed positions on all markets.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Net Profile Balance Information:

The following python demonstrates how to call the Get Net Profile Balance API using the axios library.

27. Settle Pnl

This API returns a transaction payload used to manually (or automatically, on user interactions) refresh the user's position and settle the Pnl for a specific market, allowing the user to claim any unreleased Pnl.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Get Settle Pnl:

The following python demonstrates how to call the Get Settle pnl API using the axios library.

28. Get Trade History

  • Method: GET

  • Query Parameters:

    • userAddress (Required) - The wallet address to retrieve the trade history.

    • marketId (optional) - The ID of the market to filter the trade history.

    • offset (Optional) - The offset for paginating the results. limit (Optional) - The maximum number of results to return. order (Optional) - The sort order of the results. Accepts asc or desc.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Trade History:

The following TypeScript/Node.js script demonstrates how to call the Get Trade History API using the axios library.

29. Get Deposit and Withdraw History

Example Request:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Deposit and Withdraw History:

The following Python script demonstrates how to call the Get Deposit and Withdraw History API using the requests library.

29. Get Funding History

  • Method: GET

  • Query Parameters:

    • userAddress (Required) - The wallet address to retrieve the funding history.

    • marketId (optional) - The ID of the market to filter the funding history.

    • offset (Optional) - The offset for paginating the results. limit (Optional) - The maximum number of results to return. order (Optional) - The sort order of the results. Accepts asc or desc.

Example Request:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Funding History:

The following Python script demonstrates how to call the Get Funding History API using the requests library.

30. Fetch Order Status By Id

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Possible Order Status Values:

The status field will contain one of the following values:

Status
Meaning

Open

Order is open

Filled

The order is fully filled. There will be no remaining open orders with the same order ID in the order history

Partially Filled

The order is partially filled. There will be remaining open orders with the same order ID in the order history.

Cancelled

The order has been cancelled

Example Code to Fetch Order Status By Id:

The following Python script demonstrates how to call the Fetch Order Status By Id API using the requests library.

31. Get Fills For Given Timestamp

  • Method: GET

  • Query Parameters:

    userAddress (required) marketId (optional) offset (optional) limit (optional) —-> default 50 order (optional) —-> asc or desc fromTimestamp (optional) --> In seconds (not milliseconds) toTimestamp (optional) --> In seconds (not milliseconds)

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Get fills for given timestamp:

The following Python script demonstrates how to call the get fills for given timestamp API using the requests library.

32. Get Positions From Contract

  • Endpoint URL:

https://perps-tradeapi.kanalabs.io/getPositionsFromContract

  • Method: GET

  • Query Parameters:

    • userAddress (Required) - The wallet address of the user to view positions for.

    • marketId (optional) - The ID of the market to filter the positions.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Open Position from contract:

The following TypeScript/Node.js script demonstrates how to call the Get Open Position From Contract API using the axios library.

33. Get Open Orders From Contract

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Open Orders From Contarct:

The following TypeScript/Node.js script demonstrates how to call the Get Open Orders From Contract API using the axios library.

Last updated