Kana Perps Python REST API

1. Get Market Info

Example Request:

GET https://perps-tradeapi.kanalabs.io/getMarketInfo?marketId=66

Example Response:

  • Status Code: 200 OK

  • Response Body:

{
  "success": true,
  "message": "Fetched market info successfully",
  "data": [
    {
      "base_decimals": 8,
      "base_name": "APT/USDC",
      "counter": "0",
      "creator_address": "0xb61d7b57333abf8ac036e752f19d0ba0c4baa5404db1cbf868c57dac3628f2bf",
      "lot_size": "150000000",
      "maintenance_margin": "250",
      "market_address": "0x2b1c1f9288506541f5a9ad37b5071e100bf289a74d27801cb6d3dc92a2c5fcca",
      "market_id": "301",
      "max_leverage": "20",
      "max_lots": "1500000",
      "min_lots": "500",
      "quote_decimals": 6,
      "quote_precision": 3,
      "tick_size": "1"
    }
  ]
}

Example Code to Fetch Market Information:

The following TypeScript/Node.js script demonstrates how to call the Get Market Info API using the axios 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 TypeScript/Node.js script demonstrates how to call the Get Wallet Account Balance API using the axios library.

3. Get Trading Account Balance

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Trading Account Balance Information:

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

4. Deposit

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Depsoit a quote coin:

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

5. Withdraw

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Withdraw a quote coin:

The following TypeScript/Node.js script demonstrates how to call the Get Withdraw API using the axios 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 TypeScript/Node.js script demonstrates how to call the Get Place Limit Order API using the axios 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 TypeScript/Node.js script demonstrates how to call the Get Place Market Order API using the axios library.

8. Cancel Multiple Orders

  • Method: POST

  • Request Body:

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

    • orderIds: A list of order IDs to cancel.

    • cancelTradeSides: 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 TypeScript/Node.js script demonstrates how to call the Post Cancel Multiple Orders API using the axios 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 TypeScript/Node.js script demonstrates how to call the Get Place Multiple Orders API using the axios library.

9. Cancel and Place Multiple Orders

Request Body :

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

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

  • cancelTradeSides (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.

  • orderTradeSides (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 TypeScript/Node.js script demonstrates how to call the Get Open Orders API using the axios library.

11. Get Order History

  • Method: GET

  • Query Parameters:

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

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

    • offset (Optional) - The number of records to skip for pagination (default is 0 if not provided).

    • limit (Optional) - The maximum number of records to retrieve (default is 10 if not provided).

    • order (Optional) - The sorting order for the results. Options:

      • 'asc' for ascending order.

      • 'desc' for descending order.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Order History:

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

12. Get Open Position

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Open Position:

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

12. Get All Trades

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Open Position:

The following TypeScript/Node.js script demonstrates how to call the Get Open Position API using the axios 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 TypeScript/Node.js script demonstrates how to call the Get Order Status By Order Id API using the axios library.

14. Get Fills

  • 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 TypeScript/Node.js script demonstrates how to call the Get Fills Data API using the axios library.

14. Get Market Price

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Market Price:

The following TypeScript/Node.js script demonstrates how to call the Get Market Price API using the axios 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 TypeScript/Node.js script demonstrates how to call the Get Last Execution Price API using the axios library.

16. Get Open Order Ids

  • Method: GET

  • Query Parameters:

    • address (Required) - The address associated with the orders.

    • marketId (Required) - The ID of the market for which open order IDs are being retrieved.

Example Request:

Example Response:

  • Status Code: 200 OK

  • Response Body:

Example Code to Fetch Open Order Ids:

The following TypeScript/Node.js script demonstrates how to call the Get Open Order Ids API using the axios 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 TypeScript/Node.js script demonstrates how to call the Get Update Take Profit Price API using the axios 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 TypeScript/Node.js script demonstrates how to call the Get Wallet Account Aptos Balance API using the axios 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 TypeScript/Node.js script demonstrates how to call the Get Update Stop Loss Price API using the axios library.

Last updated