Kana Perps 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:

{
  "status": true,
  "message": "Fetched market info successfully",
  "data": [
    {
      "market_id": "66",
      "base_name": "APT/USDC",
      "quote_type": "0x197b9c79f40089f150e3c493edb8cf145efec6bd6b0474f3b08ad738549fa1d1::asset::USDC",
      "lot_size": "100000",
      "tick_size": "1",
      "min_lots": "500",
      "quote_precision": 3,
      "base_decimals": 8,
      "quote_decimals": 6,
      "maintenance_margin": "400",
      "max_leverage": "20",
      "counter": "252"
    }
  ]
}

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.

import axios from "axios";

async function main(): Promise<void> {
    const baseURL = 'https://perps-tradeapi.kanalabs.io/getMarketInfo';
    const params = {
        marketId: 'your_market_id'
    };
    const res = await axios.get(baseURL, {
        params, 
        headers: {
            'api_key': process.env.API_KEY,
        },
    });
    const getMarketInfo = res.data;
    console.log("getMarketInfo: ", getMarketInfo);
}

main().catch(error => {
    console.error('An error occurred:', error);
});

2. Get Wallet Account Balance

Example Request:

GET https://perps-tradeapi.kanalabs.io/getWalletAccountBalance?marketId=66&address=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770

Example Response:

  • Status Code: 200 OK

  • Response Body:

{
  "status": true,
  "message": "Fetched wallet account balance successfully",
  "data": 611899
}

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.

import axios from "axios";

async function main(): Promise<void> {
    const baseURL = 'https://perps-tradeapi.kanalabs.io/getWalletAccountBalance';
    const params = {
        marketId: 'your_market_id',
        address: 'your_wallet_address'
    };
    const res = await axios.get(baseURL, {
        params, 
        headers: {
            'api_key': process.env.API_KEY,
        },
    });
    const getWalletAccountBalance = res.data;
    console.log("getWalletAccountBalance: ", getWalletAccountBalance);
}

main().catch(error => {
    console.error('An error occurred:', error);
});

3. Get Trading Account Balance

Example Request:

GET https://perps-tradeapi.kanalabs.io/getTradingAccountBalance?marketId=66&address=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770

Example Response:

  • Status Code: 200 OK

  • Response Body:

{
  "status": true,
  "message": "Fetched trading account balance successfully",
  "data": 1027469914
}

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.

import axios from "axios";

async function main(): Promise<void> {

    const baseURL = 'https://perps-tradeapi.kanalabs.io/getTradingAccountBalance';
    const params = {
        marketId: 'your_market_id',
        address: 'your_wallet_address'
    };
    const res = await axios.get(baseURL, {
        params, headers: {
            'api_key': "your_api_key",
        },
    });
    const getTradingAccountBalance = res.data;
    console.log("getTradingAccountBalance: ", getTradingAccountBalance);
}

main().catch(error => {
    console.error('An error occurred:', error);
});

4. Deposit

Example Request:

GET https://perps-tradeapi.kanalabs.io/deposit?marketId=66&amount=50000000

Example Response:

  • Status Code: 200 OK

  • Response Body:

{
  "status": true,
  "message": "Deposit payload built successfully",
  "data": {
    "function": "0x1ce63c441256263ea2f45dd2d3a1e68e5843107c65c10b79c7a2d5aa2b7a4e3e::perp_market::deposit",
    "functionArguments": [
      50000000
    ],
    "typeArguments": [
      "0x197b9c79f40089f150e3c493edb8cf145efec6bd6b0474f3b08ad738549fa1d1::asset::USDC"
    ]
  }
}

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.

import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";
import axios from "axios";


async function main(): Promise<void> {
    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);
    const account = Account.fromPrivateKey({
        privateKey: new Ed25519PrivateKey("your_private_key"),
    });
    const baseURL = 'https://perps-tradeapi.kanalabs.io/deposit';
    const params = {
        marketId: 'your_market_id',
        amount: 'your_amount'
    };
    const res = await axios.get(baseURL, {
        params, headers: {
            'api_key': "your_api_key",
        },
    });
    const payloadData = res.data.data;
    const transactionPayload = await aptos.transaction.build.simple({
        sender: account.accountAddress,
        data: payloadData
    });
    const committedTxn = await aptos.transaction.signAndSubmitTransaction({
        transaction: transactionPayload,
        signer: account,
    });
    await aptos.waitForTransaction({
        transactionHash: committedTxn.hash,
    });
}

main().catch(error => {
    console.error('An error occurred:', error);
});

5. Withdraw

Example Request:

GET https://perps-tradeapi.kanalabs.io/withdraw?marketId=66&amount=50000000

Example Response:

  • Status Code: 200 OK

  • Response Body:

{
  "status": true,
  "message": "Withdraw payload built successfully",
  "data": {
    "function": "0x1ce63c441256263ea2f45dd2d3a1e68e5843107c65c10b79c7a2d5aa2b7a4e3e::perp_market::withdraw",
    "functionArguments": [
      50000000
    ],
    "typeArguments": [
      "0x197b9c79f40089f150e3c493edb8cf145efec6bd6b0474f3b08ad738549fa1d1::asset::USDC"
    ]
  }
}

Example Code to Depsoit a quote coin:

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

import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";
import axios from "axios";


async function main(): Promise<void> {
    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);
    const account = Account.fromPrivateKey({
        privateKey: new Ed25519PrivateKey("your_private_key"),
    });
    const baseURL = 'https://perps-tradeapi.kanalabs.io/withdraw';
    const params = {
        marketId: 'your_market_id',
        amount: 'your_amount'
    };
    const res = await axios.get(baseURL, {
        params, headers: {
            'api_key': "your_api_key",
        },
    });
    const payloadData = res.data.data;
    const transactionPayload = await aptos.transaction.build.simple({
        sender: account.accountAddress,
        data: payloadData
    });
    const committedTxn = await aptos.transaction.signAndSubmitTransaction({
        transaction: transactionPayload,
        signer: account,
    });
    await aptos.waitForTransaction({
        transactionHash: committedTxn.hash,
    });
}

main().catch(error => {
    console.error('An error occurred:', error);
});

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 (Optional) - Specifies the type of order restriction: (Default: 0)

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

    • takeProfit (Optional) - The take profit value. Can be null if not applicable.

    • stopLoss (Optional) - The stop loss value. Can be null if not applicable.

Example Request:

GET https://perps-tradeapi.kanalabs.io/limitOrder/?marketId=66&tradeSide=true&direction=false&size=10000&price=3000&leverage=3

Example Response:

  • Status Code: 200 OK

  • Response Body:

{
  "status": true,
  "message": "Place limit order payload built successfully",
  "data": {
    "function": "0x1ce63c441256263ea2f45dd2d3a1e68e5843107c65c10b79c7a2d5aa2b7a4e3e::perp_market::place_limit_order",
    "functionArguments": [
      66,
      true,
      false,
      10000,
      3000,
      3,
      0,
      null,
      null
    ],
    "typeArguments": [
      "0x197b9c79f40089f150e3c493edb8cf145efec6bd6b0474f3b08ad738549fa1d1::asset::USDC"
    ]
  }
}

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.

import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";
import axios from "axios";


async function main(): Promise<void> {
    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);
    const account = Account.fromPrivateKey({
        privateKey: new Ed25519PrivateKey("your_private_key"),
    });
    const baseURL = 'https://perps-tradeapi.kanalabs.io/limitOrder';
    const params = {
        marketId: 'your_market_id',
        tradeSide: 'your_trade_side',
        direction: 'your_direction',
        size: 'your_size',
        price: 'your_price',
        leverage: 'your_leverage',
        restriction: 'your_restriction', //(Optional, Default: 0)
    };
    const res = await axios.get(baseURL, {
        params, headers: {
            'api_key': "your_api_key",
        },
    });
    const payloadData = res.data.data;
    const transactionPayload = await aptos.transaction.build.simple({
        sender: account.accountAddress,
        data: payloadData
    });
    const committedTxn = await aptos.transaction.signAndSubmitTransaction({
        transaction: transactionPayload,
        signer: account,
    });
    await aptos.waitForTransaction({
        transactionHash: committedTxn.hash,
    });
}

main().catch(error => {
    console.error('An error occurred:', error);
});

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 (Optional) - The take profit value. Can be null if not applicable.

    • stopLoss (Optional) - The stop loss value. Can be null if not applicable.

Example Request:

GET https://perps-tradeapi.kanalabs.io/marketOrder?marketId=66&tradeSide=false&direction=true&size=1000&leverage=20

Example Response:

  • Status Code: 200 OK

  • Response Body:

{
  "status": true,
  "message": "Place limit order payload built successfully",
  "data": {
    "function": "0x1ce63c441256263ea2f45dd2d3a1e68e5843107c65c10b79c7a2d5aa2b7a4e3e::perp_market::place_market_order",
    "functionArguments": [
      66,
      true,
      false,
      10000,
      3,
      null,
      null
    ],
    "typeArguments": [
      "0x197b9c79f40089f150e3c493edb8cf145efec6bd6b0474f3b08ad738549fa1d1::asset::USDC"
    ]
  }
}

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.

import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";
import axios from "axios";


async function main(): Promise<void> {
    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);
    const account = Account.fromPrivateKey({
        privateKey: new Ed25519PrivateKey("your_private_key"),
    });
    const baseURL = 'https://perps-tradeapi.kanalabs.io/marketOrder';
    const params = {
        marketId: 'your_market_id',
        tradeSide: 'your_trade_side',
        direction: 'your_direction',
        size: 'your_size',
        leverage: 'your_leverage',
    };
    const res = await axios.get(baseURL, {
        params, headers: {
            'api_key': "your_api_key",
        },
    });
    const payloadData = res.data.data;
    const transactionPayload = await aptos.transaction.build.simple({
        sender: account.accountAddress,
        data: payloadData
    });
    const committedTxn = await aptos.transaction.signAndSubmitTransaction({
        transaction: transactionPayload,
        signer: account,
    });
    await aptos.waitForTransaction({
        transactionHash: committedTxn.hash,
    });
}

main().catch(error => {
    console.error('An error occurred:', error);
});

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.

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

Example Request:

{
  "marketId": 66,
  "orderIds": ["1077898597726583798162207", "1077880153515406921884445"],
  "tradeSides": [true, false]
}

Example Response:

  • Status Code: 200 OK

  • Response Body:

{
  "status": true,
  "message": "Cancel multiple orders payload built successfully",
  "data": {
    "function": "0x1ce63c441256263ea2f45dd2d3a1e68e5843107c65c10b79c7a2d5aa2b7a4e3e::perp_market::cancel_multiple_orders",
    "functionArguments": [
      66,
      [
        "1077898597726583798162207",
        "1077880153515406921884445"
      ],
      [
        true,
        false
      ]
    ],
    "typeArguments": [
      "0x197b9c79f40089f150e3c493edb8cf145efec6bd6b0474f3b08ad738549fa1d1::asset::USDC"
    ]
  }
}

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.

import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";
import axios from "axios";


async function main(): Promise<void> {
    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);
    const account = Account.fromPrivateKey({
        privateKey: new Ed25519PrivateKey("your_private_key"),
    });
    const baseURL = 'https://perps-tradeapi.kanalabs.io/cancelMultipleOrders';
    const params = {
        marketId: 'your_market_id',
        orderIds: ['your_order_ids'],
        tradeSides: ['your_trade_sides']
    };
    const res = await axios.get(baseURL, {
        params, headers: {
            'api_key': "your_api_key",
        },
    });
    const payloadData = res.data.data;
    const transactionPayload = await aptos.transaction.build.simple({
        sender: account.accountAddress,
        data: payloadData
    });
    const committedTxn = await aptos.transaction.signAndSubmitTransaction({
        transaction: transactionPayload,
        signer: account,
    });
    await aptos.waitForTransaction({
        transactionHash: committedTxn.hash,
    });
}

main().catch(error => {
    console.error('An error occurred:', error);
});

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.

  • restrictions (Optional) - An array specifying the type of order restriction for each order (Default: 0):

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

  • takeProfits (Optional) - An array of take profit values for each order. Can be null if not applicable.

  • stopLosses (Optional) - An array of stop loss values for each order. Can be null if not applicable.

Example Request:

{
  "marketId": 66,
  "orderTypes": [true, true],
  "tradeSides": [true, true],
  "directions": [true, true],
  "sizes": [1000, 1000],
  "prices": [1000, 1000],
  "leverages": [2, 2]
}

Example Response:

  • Status Code: 200 OK

  • Response Body:

{
  "success": true,
  "message": "Place multiple orders payload built successfully",
  "data": {
    "function": "0x1ce63c441256263ea2f45dd2d3a1e68e5843107c65c10b79c7a2d5aa2b7a4e3e::perp_market::place_multiple_orders",
    "functionArguments": [
      66,
      [
        true,
        true
      ],
      [
        true,
        true
      ],
      [
        true,
        true
      ],
      [
        1000,
        1000
      ],
      [
        1000,
        1000
      ],
      [
        2,
        2
      ],
      [
        0,
        0
      ],
      [],
      []
    ],
    "typeArguments": [
      "0x197b9c79f40089f150e3c493edb8cf145efec6bd6b0474f3b08ad738549fa1d1::asset::USDC"
    ]
  }
}

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.

import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";
import axios from "axios";


async function main(): Promise<void> {
    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);
    const account = Account.fromPrivateKey({
        privateKey: new Ed25519PrivateKey("your_private_key"),
    });
    const baseURL = 'https://perps-tradeapi.kanalabs.io/placeMultipleOrders';
    const params = {
        marketId: 'your_market_id',
        orderTypes: ['your_order_types'],
        tradeSides: ['your_trade_sides'],
        directions: ['your_directions'],
        sizes: ['your_sizes'],
        prices: ['your_prices'],
        leverage: ['your_leverages']
    };
    const res = await axios.get(baseURL, {
        params, headers: {
            'api_key': "your_api_key",
        },
    });
    const payloadData = res.data.data;
    const transactionPayload = await aptos.transaction.build.simple({
        sender: account.accountAddress,
        data: payloadData
    });
    const committedTxn = await aptos.transaction.signAndSubmitTransaction({
        transaction: transactionPayload,
        signer: account,
    });
    await aptos.waitForTransaction({
        transactionHash: committedTxn.hash,
    });
}

main().catch(error => {
    console.error('An error occurred:', error);
});

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.

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

  • restrictions (Optional) - An array specifying the type of order restriction for each order (Default: 0):

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

  • takeProfits (Optional) - An array of take profit values for each order. Can be null if not applicable.

  • stopLosses (Optional) - An array of stop loss values for each order. Can be null if not applicable.

Example Request:

{
  "marketId": 66,
  "orderIds": ["23434565434567", "454345665456"],
  "cancelTradeSides": [true, true],
  "orderTypes": [true, true],
  "tradeSides": [true, false],
  "directions": [true, true],
  "sizes": [1000, 2000],
  "prices": [5000, 6000],
  "leverages": [2, 2]
}

Example Response:

  • Status Code: 200 OK

  • Response Body:

{
  "message": "Cancel and place multiple orders payload built successfully",
  "data": {
    "function": "0x1ce63c441256263ea2f45dd2d3a1e68e5843107c65c10b79c7a2d5aa2b7a4e3e::perp_market::cancel_and_place_multiple_orders",
    "functionArguments": [
      66,
      [
        "23434565434567",
        "454345665456"
      ],
      [
        true,
        true
      ],
      [
        true,
        true
      ],
      [
        true,
        false
      ],
      [
        true,
        true
      ],
      [
        1000,
        2000
      ],
      [
        5000,
        6000
      ],
      [
        2,
        2
      ],
      [
        0,
        0
      ],
      [],
      []
    ],
    "typeArguments": [
      "0x197b9c79f40089f150e3c493edb8cf145efec6bd6b0474f3b08ad738549fa1d1::asset::USDC"
    ]
  }
}

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.

import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";
import axios from "axios";


async function main(): Promise<void> {
    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);
    const account = Account.fromPrivateKey({
        privateKey: new Ed25519PrivateKey("your_private_key"),
    });
    const baseURL = 'https://perps-tradeapi.kanalabs.io/cancelAndPlaceMultipleOrders';
    const params = {
        marketId: 'your_market_id',
        orderIds: ['your_order_ids'],
        cancelTradeSides: ['your_cancel_trade_sides'],
        orderTypes: ['your_order_types'],
        tradeSides: ['your_trade_sides'],
        directions: ['your_directions'],
        sizes: ['your_sizes'],
        prices: ['your_prices'],
        leverage: ['your_leverages']
    };
    const res = await axios.get(baseURL, {
        params, headers: {
            'api_key': "your_api_key",
        },
    });
    const payloadData = res.data.data;
    const transactionPayload = await aptos.transaction.build.simple({
        sender: account.accountAddress,
        data: payloadData
    });
    const committedTxn = await aptos.transaction.signAndSubmitTransaction({
        transaction: transactionPayload,
        signer: account,
    });
    await aptos.waitForTransaction({
        transactionHash: committedTxn.hash,
    });
}

main().catch(error => {
    console.error('An error occurred:', error);
});

10. Get Open Orders

  • Method: GET

  • Query Parameters:

    • address (Required) - The wallet address to retrieve open orders for.

    • marketId (Required) - The ID of the market to filter open orders.

    • orderType (Required) - The type of order to retrieve. Must be set to 'open' to fetch currently open orders.

Example Request:

GET https://perps-tradeapi.kanalabs.io/openOrders?address=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770&orderType=open&marketId=66

Example Response:

  • Status Code: 200 OK

  • Response Body:

{
  "status": true,
  "message": "Fetched open orders successfully",
  "data": {
    "asks": [],
    "bids": [
      {
        "marketOrderId": "16324187915019748091373328",
        "marketSize": "1000",
        "marketPrice": "10000",
        "counter": "884936",
        "timestamp": "2024-11-21T04:11:24.595485+00:00",
        "leverage": 20,
        "tradeType": 1
      }
    ]
  }
}

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.

import axios from "axios";

async function main(): Promise<void> {
    const baseURL = 'https://perps-tradeapi.kanalabs.io/openOrders';
    const params = {
        address: 'your_wallet_address',
        orderType: 'your_order_type', // open
        marketId: 'your_market_id'
    };
    const res = await axios.get(baseURL, {
        params, 
        headers: {
            'api_key': process.env.API_KEY,
        },
    });
    const getOpenOrders = res.data;
    console.log("getOpenOrders : ", getOpenOrders);
}

main().catch(error => {
    console.error('An error occurred:', error);
});

11. Get Order History

  • Method: GET

  • Query Parameters:

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

    • type (Required) - The type of orders to fetch. Options include:

      • 'limit' for limit orders.

      • 'market' for market orders.

      • 'all' for both limit and market orders.

    • 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:

GET https://perps-tradeapi.kanalabs.io/orderHistory?address=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770&type=all&marketId=66

Example Response:

  • Status Code: 200 OK

  • Response Body:

{
  "status": true,
  "message": "Fetched order history successfully",
  "data": [
    {
      "market_id": 66,
      "order_id": "15308344164217124470915072",
      "created_at": "2024-11-20T11:54:54.672164+00:00",
      "last_updated_at": "2024-11-20T11:54:54.672164+00:00",
      "integrator": "0xfb7e14963ceda75902f2767e38f95305646de7849b96c433b8a8ec31b008aaa1",
      "total_filled": 1000,
      "remaining_size": 0,
      "order_status": "closed",
      "order_type": "market",
      "user": "0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770",
      "direction": "sell",
      "price": 0,
      "average_execution_price": 12792,
      "custodian_id": 28,
      "self_match_behavior": 0,
      "restriction": 0,
      "last_increase_stamp": null,
      "min_base": null,
      "max_base": null,
      "min_quote": null,
      "max_quote": null,
      "total_fees_paid_in_quote_subunits": 6396,
      "leverage": 20,
      "trade_type": 11,
      "timestamp": "1732103694"
    },
    {
      "market_id": 66,
      "order_id": "15308325717473050761363456",
      "created_at": "2024-11-20T11:54:45.957059+00:00",
      "last_updated_at": "2024-11-20T11:54:45.957059+00:00",
      "integrator": "0xee820ab02631dd1a195d3c53fa64f0a8f455dbb9261388e141c3bd3bd3c08363",
      "total_filled": 1000,
      "remaining_size": 0,
      "order_status": "closed",
      "order_type": "market",
      "user": "0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770",
      "direction": "buy",
      "price": 0,
      "average_execution_price": 12813,
      "custodian_id": 28,
      "self_match_behavior": 0,
      "restriction": 0,
      "last_increase_stamp": null,
      "min_base": null,
      "max_base": null,
      "min_quote": null,
      "max_quote": null,
      "total_fees_paid_in_quote_subunits": 6406,
      "leverage": 20,
      "trade_type": 3,
      "timestamp": "1732103685"
    }
  ]
}

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.

import axios from "axios";

async function main(): Promise<void> {
    const baseURL = 'https://perps-tradeapi.kanalabs.io/orderHistory';
    const params = {
        address: 'your_wallet_address',
        type: 'your_type', // all
        marketId: 'your_market_id'
    };
    const res = await axios.get(baseURL, {
        params, 
        headers: {
            'api_key': process.env.API_KEY,
        },
    });
    const getOrderHistory = res.data;
    console.log("getOrderHistory : ", getOrderHistory);
}

main().catch(error => {
    console.error('An error occurred:', error);
});

12. Get Open Position

Example Request:

GET https://perps-tradeapi.kanalabs.io/viewPositions?marketId=66&address=0x2eda5777ed2bf68cbcc67359dd00ae5fa73b1d5fa160b7c3aeb42d748d485387

Example Response:

  • Status Code: 200 OK

  • Response Body:

{
  "success": true,
  "message": "Fetched view position successfully",
  "data": {
    "longPosition": {
      "position": 1,
      "collateral": "216840595355",
      "quote_deposit": "433682330806",
      "entry_price": "938433382911",
      "exit_price": "0",
      "liquidation_price": "4887",
      "oracle_price": "1165049884",
      "leverage": 2,
      "open_size": "4306061800000",
      "close_size": "0",
      "take_profit_price": "",
      "stop_loss_price": "",
      "filled_open_size": "2977447800000",
      "filled_close_size": "0",
      "close_taker_fee":