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.tradePlease 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"
NODE_URL = "https://api.testnet.aptoslabs.com/v1" and for Mainnet, set NODE_URL = "https://api.mainnet.aptoslabs.com/v1"1. Get Market Info
Endpoint URL:
https://perps-tradeapi.kanalabs.io/getMarketInfoMethod:
GETQuery Parameters:
marketId(Required) - The ID of the market you want information about.
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Method:
GETQuery Parameters:
userAddress(Required) - The wallet address for which the account balance is being fetched.
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Method:
GETQuery Parameters:
userAddress(Required) - The wallet address for which the account balance is being fetched.
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/depositMethod:
GETQuery 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 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/withdrawSpecifiMarketMethod:
GETQuery 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 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/placeLimitOrderMethod:
GETQuery Parameters:
marketId (Required) - The ID of the market where the limit order will be placed.
tradeSide (Required) - Indicates the trade side:
truefor the long side.falsefor the short side.
direction (Required) - Indicates the direction of the trade:
falseto open a position.trueto 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
restrictionis not provided, it defaults to0. 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 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/placeMarketOrderMethod:
GETQuery Parameters:
marketId (Required) - The ID of the market where the limit order will be placed.
tradeSide (Required) - Indicates the trade side:
truefor the long side.falsefor the short side.
direction (Required) - Indicates the direction of the trade:
falseto open a position.trueto 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 OKResponse 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
Endpoint URL:
htps://perps-tradeapi.kanalabs.io/cancelMultipleOrdersMethod:
POSTRequest 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 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/placeMultipleOrdersMethod:
POST
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
restrictionis not provided, it defaults to0. 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 OKResponse 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
Method:
POST
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:
truefor long sides.falsefor 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
restrictionis not provided, it defaults to0. 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 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/getOpenOrdersMethod:
GETQuery Parameters:
userAddress (Required) - The wallet address to retrieve open orders for.
marketId - The ID of the market to filter open orders. // Optional
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/getOrderHistoryMethod:
GETQuery 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
ascordesc.
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Endpoint URL: h
ttps://perps-tradeapi.kanalabs.io/getPositionsMethod:
GETQuery 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 OKResponse 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
Method:
GETQuery Parameters:
marketId (Required) - The ID of the market associated with the order.
orderId (Required) - The unique identifier of the order to retrieve its status.
Example Request:
Example Response:
Status Code:
200 OKResponse 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.
Endpoint URL:
https://perps-tradeapi.kanalabs.io/getFillsMethod:
GETQuery 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 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/getMarketPriceMethod:
GETQuery Parameters:
marketId (Required) - The ID of the market for which the price information is being retrieved.
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/getLastPlacedPriceMethod:
GETQuery Parameters:
marketId (Required) - The ID of the market for which the last execution price information is being retrieved.
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/getAllOpenOrderIdsMethod:
GETQuery Parameters:
userAddress(Required) - The address associated with the orders.
marketId (optional) - The ID of the market for which open order IDs are being retrieved.
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/updateTakeProfitMethod:
GETQuery Parameters:
marketId (Required) - The ID of the market for which the take profit values will be updated.
tradeSide (Required) - The trade side:
truefor the long side.falsefor the short side.
newTakeProfitPrice (Required) - The new take profit price to be set for the trade.
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/getAccountAptBalanceMethod:
GETQuery Parameters:
userAddress (Required) - The address of the account whose balance will be
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/updateStopLossMethod:
GETQuery Parameters:
marketId (Required) - The ID of the market for which the take profit values will be updated.
tradeSide (Required) - The trade side:
truefor the long side.falsefor the short side.
newStopLossPrice (Required) - The new stop loss price to be set for the trade.
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/getProfileAddressMethod:
GETQuery Parameters:
userAddress(Required) - The address of the user to get the profile address.
Example Request:
Copy
Example Response:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/collapsePositionMethod:
GETQuery Parameters:
marketId(Required) - The ID of the market you want to collapse a position.
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/getAllTradesMethod:
GETQuery Parameters:
marketId (Required) - The ID of the market to retrieve all trades information.
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/getAccountAptBalanceMethod:GETQuery Parameters:
userAddress(Required) - The wallet address for which the account balance is being fetched.
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/addMarginMethod:
GETQuery Parameters:
marketId (Required) – The unique identifier of the market where the margin is being added.
tradeSide (Required) - Indicates the trade side:
truefor the long side.falsefor the short side.
amount (Required) – The amount of additional margin to be added to the position.
Example Request:
Example Response:
Status Code:
200 OKResponse 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.
Endpoint URL:
https://perps-tradeapi.kanalabs.io/getNetProfileBalanceMethod:
GETQuery Parameters:
userAddress(Required) - The wallet address for which the account balance is being fetched.
Example Request:
Example Response:
Status Code:
200 OKResponse 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.
Endpoint URL:
https://perps-tradeapi.kanalabs.io/settlePnlMethod:
GETQuery Parameters:
marketId (Required) -
userAddress (Required) -
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/getTradeHistoryMethod:
GETQuery 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
ascordesc.
Example Request:
Example Response:
Status Code:
200 OKResponse 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
Method:
GETQuery Parameters:
userAddress (Required) - The wallet address to retrieve the order history
Example Request:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/getFundingHistoryMethod:
GETQuery 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
ascordesc.
Example Request:
Status Code:
200 OKResponse 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
Endpoint URL:
https://perps-tradeapi.kanalabs.io/fetchOrderStatusByIdMethod:
GETQuery Parameters:
marketId (Required) - The ID of the market associated with the order.
orderId (Required) - The unique identifier of the order to retrieve its status.
Example Request:
Example Response:
Status Code:
200 OKResponse Body:
Possible Order Status Values:
The status field will contain one of the following values:
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:
GETQuery 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 OKResponse 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:
GETQuery 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 OKResponse 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
Method:
GETQuery Parameters:
userAddress (Required) - The wallet address to retrieve open orders for.
marketId (Optional) - The ID of the market to filter open orders. // Optional
Example Request:
Example Response:
Status Code:
200 OKResponse 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