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:
Example code:
✅ Testnet API Endpoint URL
Copy https://perps-tradeapi.kanalabs.io
✅ Mainnet API Endpoint URL
Copy https://perps-tradeapi.kana.trade
Please ensure that the correct network is passed : use Network.TESTNET
for Testnet and Network.MAINNET
for Mainnet
1. Get Market Info
Query Parameters :
marketId
(Required) - The ID of the market you want information about.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getMarketInfo?marketId=501
Example Response:
Copy {
"success": true,
"message": "Market information fetched successfully",
"data": [
{
"__variant__": "V1",
"base_decimals": 8,
"base_name": "APT/USDC",
"counter": "0",
"creator": "0xb61d7b57333abf8ac036e752f19d0ba0c4baa5404db1cbf868c57dac3628f2bf",
"custodian_id": "75",
"fee_address": "0x7724a4a23b25b460abc2a5d9fe1fe3c47e2a0e10a156dd713a221f129579c388",
"is_recognised": false,
"lot_size": "100000",
"maintenance_margin": "250",
"market_address": "0xcfa0086c26787035de6b4a312875c7a70b2f9a29fa880d0cf633ef3dd0acd2c3",
"market_id": "1338",
"market_status": 1,
"max_leverage": "20",
"max_lots": "150000000",
"max_position_value": "125000000",
"min_lots": "500",
"quote_decimals": 6,
"quote_precision": 3,
"tick_size": "1",
"timestamp": "1745079291",
"underwriter_id": "73"
}
]
}
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.
Copy import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getMarketInfo';
const params = {
marketId: 501
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getMarketInfo: ", res.data);
}
main().catch(error => {
console.error('An error occurred:', error);
});
2. Get Wallet Account Balance
Query Parameters :
userAddress
(Required) - The wallet address for which the account balance is being fetched.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getWalletAccountBalance?userAddress=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770
Example Response:
Copy {
"success": true,
"message": "Fetched wallet account balance successfully",
"data": 16391.60
}
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.
Copy import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getWalletAccountBalance';
const params = {
userAddress: '0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770'
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getWalletAccountBalance: ", res.data);
}
main().catch(error => {
console.error('An error occurred:', error);
});
3. Get Profile Balance Snapshot
Query Parameters :
userAddress
(Required) - The wallet address for which the account balance is being fetched.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getProfileBalanceSnapshot?userAddress=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770
Example Response:
Copy {
"success": true,
"message": "Profile balance snapshot fetched successfully",
"data": 44.321972
}
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.
Copy import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getProfileBalanceSnapshot';
const params = {
userAddress: '0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770'
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getProfileBalanceSnpashot: ", res.data);
}
main().catch(error => {
console.error('An error occurred:', error);
});
4. Deposit
Query Parameters:
amount
(Required) - The amount of the quote coin to deposit.
userAddress
(Required) - The address of the user making the deposit.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/deposit?userAddress=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770&amount=50000000
Example Response:
Copy {
"success": true,
"message": "Deposit payload has been built successfully",
"data": {
"function": "0xabbf40e0c31cbedf182f3e6e9c3570f3f91629424723da876becb514bf5d9fc6::perpetual_scripts::deposit",
"functionArguments": [
"0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770",
50000000
],
"typeArguments": []
}
}
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.
Copy import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey, PrivateKey, PrivateKeyVariants } from "@aptos-labs/ts-sdk";
import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
const formattedPrivateKey = PrivateKey.formatPrivateKey(
process.env.APTOS_PRIVATEKEY || '',
'ed25519' as PrivateKeyVariants
);
const account = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});
const baseURL = 'https://perps-tradeapi.kanalabs.io/deposit';
const params = {
userAddress: '0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770',
amount: 1000
};
const res = await axios.get(baseURL, {
params, headers: {
'x-api-key': process.env.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,
});
console.log(`Submitted transaction: ${committedTxn.hash}`);
const response = await aptos.waitForTransaction({
transactionHash: committedTxn.hash,
});
console.log("response", response.success);
}
main().catch(error => {
console.error('An error occurred:', error);
});
5. Withdraw Specific Market
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:
Copy GET https://perps-tradeapi.kanalabs.io/withdrawSpecifiMarket?marketId=501&userAddress=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770&amount=50
Example Response:
Copy {
"success": true,
"message": "Withdraw specific market payload has been built successfully",
"data": {
"function": "0xabbf40e0c31cbedf182f3e6e9c3570f3f91629424723da876becb514bf5d9fc6::perpetual_scripts::withdraw_specific_market",
"functionArguments": [
"0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770",
501,
50000000
],
"typeArguments": []
}
}
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.
Copy import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey, PrivateKey, PrivateKeyVariants } from "@aptos-labs/ts-sdk";
import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
const formattedPrivateKey = PrivateKey.formatPrivateKey(
process.env.APTOS_PRIVATEKEY || '',
'ed25519' as PrivateKeyVariants
);
const account = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});
const baseURL = 'https://perps-tradeapi.kanalabs.io/withdrawSpecifiMarket';
const params = {
userAddress: '0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770',
marketId: 501,
amount: 1000
};
const res = await axios.get(baseURL, {
params, headers: {
'x-api-key': process.env.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,
});
console.log(`Submitted transaction: ${committedTxn.hash}`);
const response = await aptos.waitForTransaction({
transactionHash: committedTxn.hash,
});
console.log("response", response.success);
}
main().catch(error => {
console.error('An error occurred:', error);
});
6. Place Limit Order
Query Parameters :
marketId (Required) - The ID of the market where the limit order will be placed.
tradeSide (Required) - Indicates the trade 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:
Copy GET https://perps-tradeapi.kanalabs.io/placeLimitOrder/?marketId=501&tradeSide=true&direction=false&size=10000&price=3000&leverage=3
Example Response:
Copy {
"success": true,
"message": "Limit Order payload has been built successfully",
"data": {
"function": "0xabbf40e0c31cbedf182f3e6e9c3570f3f91629424723da876becb514bf5d9fc6::perpetual_scripts::place_limit_order",
"functionArguments": [
"501",
"true",
"false",
1000000,
8000000,
"5",
0,
0,
0
],
"typeArguments": []
}
}
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.
Copy import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey, PrivateKey, PrivateKeyVariants } from "@aptos-labs/ts-sdk";
import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
const formattedPrivateKey = PrivateKey.formatPrivateKey(
process.env.APTOS_PRIVATEKEY || '',
'ed25519' as PrivateKeyVariants
);
const account = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});
const baseURL = 'https://perps-tradeapi.kanalabs.io/placeLimitOrder';
const params = {
marketId: 501,
tradeSide: true,
direction: false,
size: 1.5,
price: 5.7,
leverage: 2
};
const res = await axios.get(baseURL, {
params, headers: {
'x-api-key': process.env.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,
});
console.log(`Submitted transaction: ${committedTxn.hash}`);
const response = await aptos.waitForTransaction({
transactionHash: committedTxn.hash,
});
console.log("response", response.success);
}
main().catch(error => {
console.error('An error occurred:', error);
});
7. Place Market Order
Query Parameters :
marketId (Required) - The ID of the market where the limit order will be placed.
tradeSide (Required) - Indicates the trade 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:
Copy GET https://perps-tradeapi.kanalabs.io/placeMarketOrder?marketId=66&tradeSide=false&direction=true&size=1000&leverage=20
Example Response:
Copy {
"success": true,
"message": "Market Order payload has been built successfully",
"data": {
"function": "0xabbf40e0c31cbedf182f3e6e9c3570f3f91629424723da876becb514bf5d9fc6::perpetual_scripts::place_market_order",
"functionArguments": [
"501",
"true",
"false",
1000000,
"5",
0,
0
],
"typeArguments": []
}
}
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.
Copy import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey, PrivateKey, PrivateKeyVariants } from "@aptos-labs/ts-sdk";
import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
const formattedPrivateKey = PrivateKey.formatPrivateKey(
process.env.APTOS_PRIVATEKEY || '',
'ed25519' as PrivateKeyVariants
);
const account = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});
const baseURL = 'https://perps-tradeapi.kanalabs.io/placeMarketOrder';
const params = {
marketId: 501,
tradeSide: true,
direction: false,
size: 5.7,
leverage: 2
};
const res = await axios.get(baseURL, {
params, headers: {
'x-api-key': process.env.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,
});
console.log(`Submitted transaction: ${committedTxn.hash}`);
const response = await aptos.waitForTransaction({
transactionHash: committedTxn.hash,
});
console.log("response", response.success);
}
main().catch(error => {
console.error('An error occurred:', error);
});
8. Cancel Multiple Orders
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:
Copy {
"marketId": "501",
"cancelOrderIds": ["1077898597726583798162207", "1077880153515406921884445"],
"orderSides": ["true", "false"]
}
Example Response:
Copy {
"success": true,
"message": "Cancel Multiple Orders payload has been built successfully",
"data": {
"function": "0xabbf40e0c31cbedf182f3e6e9c3570f3f91629424723da876becb514bf5d9fc6::perpetual_scripts::cancel_multiple_orders",
"functionArguments": [
501,
[
'1077898597726583798162207',
'1077880153515406921884445'
],
[
true,
false
]
],
"typeArguments": []
}
}
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.
Copy import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey, PrivateKey, PrivateKeyVariants } from "@aptos-labs/ts-sdk";
import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
const formattedPrivateKey = PrivateKey.formatPrivateKey(
process.env.APTOS_PRIVATEKEY || '',
'ed25519' as PrivateKeyVariants
);
const account = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});
const baseURL = 'https://perps-tradeapi.kanalabs.io/cancelMultipleOrders';
const body = {
marketId: 501,
cancelOrderIds: ['82346266390151563318384'],
orderSides: [true]
};
const res = await axios.post(baseURL, body, {
headers: {
'x-api-key': process.env.API_KEY,
'Content-Type': 'application/json',
},
});
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,
});
console.log(`Submitted transaction: ${committedTxn.hash}`);
const response = await aptos.waitForTransaction({
transactionHash: committedTxn.hash,
});
console.log("response", response.success);
}
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:
tradeSides (Required) - An array indicating the trade sides for each order:
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:
Copy {
"marketId": 501,
"orderTypes": [true, true],
"tradeSides": [true, true],
"directions": [true, true],
"sizes": [1.6, 1.8],
"prices": [4.67, 6.78],
"leverages": [2, 2]
}
Example Response:
Copy {
"success": true,
"message": "Multiple Orders payload has been built successfully",
"data": {
"function": "0xabbf40e0c31cbedf182f3e6e9c3570f3f91629424723da876becb514bf5d9fc6::perpetual_scripts::place_multiple_orders",
"functionArguments": [
501,
[
true,
true
],
[
true,
true
],
[
true,
true
],
[
1000,
1000
],
[
4670,
6780
],
[
2,
2
],
[
0,
0
],
[
4600
],
[
0,
0
]
],
"typeArguments": []
}
}
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.
Copy import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey, PrivateKey, PrivateKeyVariants } from "@aptos-labs/ts-sdk";
import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
const formattedPrivateKey = PrivateKey.formatPrivateKey(
process.env.APTOS_PRIVATEKEY || '',
'ed25519' as PrivateKeyVariants
);
const account = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});
const baseURL = 'https://perps-tradeapi.kanalabs.io/placeMultipleOrders';
const body = {
marketId: 501,
orderTypes: [true, true],
tradeSides: [true, true],
directions: [false, false],
sizes: [1.7, 1.8],
prices: [4.1, 4.2],
leverages: [2, 2]
};
const res = await axios.post(baseURL, body, {
headers: {
'x-api-key': process.env.API_KEY,
'Content-Type': 'application/json',
},
});
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,
});
console.log(`Submitted transaction: ${committedTxn.hash}`);
const response = await aptos.waitForTransaction({
transactionHash: committedTxn.hash,
});
console.log("response", response.success);
}
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.
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:
orderTypes (Required) - An array of order types for each order:
tradeSides (Required) - An array indicating the trade sides for each order:
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:
Copy {
"marketId": 501,
"cancelOrderIds": ['23434565434567', '454345665456'],
"orderSides": [true, true],
"orderTypes": [true, true],
"tradeSides": [true, false],
"directions": [true, true],
"sizes": [1000, 2000],
"prices": [5000, 6000],
"leverages": [2, 2]
}
Example Response:
Copy {
"success": true,
"message": "Cancel and place multiple Orders payload has been built successfully",
"data": {
"function": "0xabbf40e0c31cbedf182f3e6e9c3570f3f91629424723da876becb514bf5d9fc6::perpetual_scripts::cancel_and_place_multiple_orders",
"functionArguments": [
501,
[
'23434565434567',
'454345665456'
],
[
"true",
"true"
],
[
true,
true
],
[
true,
false
],
[
true,
true
],
[
1000,
2000
],
[
5000,
6000
],
[
2,
2
],
[
0,
0
],
[
0,
0
],
[
0,
0
]
],
"typeArguments": []
}
}
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
Query Parameters :
userAddress (Required) - The wallet address to retrieve open orders for.
marketId (Optional) - The ID of the market to filter open orders. // Optional
Copy Note : order_type Explanation:
OPEN_LONG (1): Opens a new long position.
OPEN_SHORT (2): Opens a new short position.
INCREASE_LONG (3): Increases the size of an existing long position.
INCREASE_SHORT (4): Increases the size of an existing short position.
DECREASE_LONG (5): Reduces the size of an existing long position.
DECREASE_SHORT (6): Reduces the size of an existing short position.
CLOSE_LONG (7): Closes an existing long position.
CLOSE_SHORT (8): Closes an existing short position.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getOpenOrders?userAddress=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770&marketId=66
Example Response:
Copy {
"success": true,
"message": "Fetched open orders successfully",
"data": [
{
"address": "0x3c78886aa67752706b3502b12959edf92e68d85ae64b24226783d26ce6efc1e",
"market_id": "501",
"leverage": 2,
"order_type": 3,
"timestamp": 1741444213,
"price": "7",
"total_size": "2",
"remaining_size": "2",
"order_value": "14",
"order_id": "645636324063400958808",
"trade_id": "295147905179352826357",
"last_updated": 1741444214,
"transaction_version": 6703807706
},
{
"address": "0x3c78886aa67752706b3502b12959edf92e68d85ae64b24226783d26ce6efc1e",
"market_id": "501",
"leverage": 2,
"order_type": 3,
"timestamp": 1741445758,
"price": "7",
"total_size": "2",
"remaining_size": "2",
"order_value": "14",
"order_id": "682529812245179800408",
"trade_id": "295147905179352826357",
"last_updated": 1741445758,
"transaction_version": 6703807706
}
]
}
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.
Copy import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getOpenOrders';
const params = {
userAddress: '0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770'
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getOpenOrders: ", res.data);
}
main().catch(error => {
console.error('An error occurred:', error);
});
11. Get Order History
Query Parameters :
userAddress (Required) - The wallet address to retrieve the order history for.
marketId (optional) - The ID of the market to filter the order history.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getOrderHistory?userAddress=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770&marketId=66
Example Response:
Copy {
"success": true,
"message": "Fetched order history successfully",
"data": [
{
"address": "0x3c78886aa67752706b3502b12959edf92e68d85ae64b24226783d26ce6efc1e",
"market_id": "501",
"leverage": 2,
"order_type": 1,
"timestamp": 1741167151,
"is_market_order": false,
"size": "1.50",
"price": "4.678",
"order_value": "7.01700",
"status": "Open",
"order_id": "18446884819787846214",
"trade_id": "18446744073709552117",
"last_updated": 1741262093,
"transaction_version": 6703807706
},
{
"address": "0x3c78886aa67752706b3502b12959edf92e68d85ae64b24226783d26ce6efc1e",
"market_id": "501",
"leverage": 2,
"order_type": 1,
"timestamp": 1741236277,
"is_market_order": false,
"size": "1.50",
"price": "4.678",
"order_value": "7.01700",
"status": "Cancelled",
"order_id": "18446884819787846214",
"trade_id": "18446744073709552117",
"last_updated": 1741262168,
"transaction_version": 6703807706
},
{
"address": "0x3c78886aa67752706b3502b12959edf92e68d85ae64b24226783d26ce6efc1e",
"market_id": "501",
"leverage": 2,
"order_type": 1,
"timestamp": 1741236468,
"is_market_order": false,
"size": "1.50",
"price": "4.50",
"order_value": "6.7500",
"status": "Open",
"order_id": "36893628893497397652",
"trade_id": "36893488147419103733",
"last_updated": 1741262168,
"transaction_version": 6703807706
}
}
]
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.
Copy import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getOrderHistory';
const params = {
userAddress: '0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770'
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getOrderHistory: ", res.data);
}
main().catch(error => {
console.error('An error occurred:', error);
});
12. Get Positions
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:
Copy GET https://perps-tradeapi.kanalabs.io/getPositions?marketId=66&userAddress=0x2eda5777ed2bf68cbcc67359dd00ae5fa73b1d5fa160b7c3aeb42d748d485387
Example Response:
Copy {
"success": true,
"message": "Fetched positions successfully",
"data": [
{
"address": "0x3c78886aa67752706b3502b12959edf92e68d85ae64b24226783d26ce6efc1e",
"market_id": "501",
"leverage": 2,
"trade_side": true,
"size": "1",
"available_order_size": "1",
"value": "5.678",
"entry_price": "5.678",
"liq_price": "2.9117948717948717990163355253",
"margin": "2.839",
"tp": "6.012",
"sl": null,
"trade_id": "295147905179352826357",
"last_updated": 1741262185,
"transaction_version": 6703807706
}
]
}
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.
Copy import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getPositions';
const params = {
userAddress: '0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770'
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getPositions: ", res.data);
}
main().catch(error => {
console.error('An error occurred:', error);
});
12. Get All Trades
Query Parameters :
marketId (Required) - The ID of the market to retrieve all trades information.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getAllTrades?marketId=66
Example Response:
Copy {
"success": true,
"message": "Recent trades fetched successfully",
"data": [
{
"txn_version": 6297687196,
"event_idx": 5,
"emit_address": "0x2eda5777ed2bf68cbcc67359dd00ae5fa73b1d5fa160b7c3aeb42d748d485387",
"time": "2024-11-20T20:33:38.600241+00:00",
"maker_address": "0x2eda5777ed2bf68cbcc67359dd00ae5fa73b1d5fa160b7c3aeb42d748d485387",
"maker_custodian_id": 28,
"maker_order_id": "15951655917465922493754983",
"maker_side": true,
"market_id": 66,
"price": 11879,
"sequence_number_for_trade": 0,
"size": 10000,
"taker_address": "0x13eb7ea6b62c6cd791b5c4e0e2ef1dfbe59d1cf4823929343a273274c288bc8a",
"taker_custodian_id": 28,
"taker_order_id": "15951748150764039921729536",
"taker_quote_fees_paid": 59395
},
{
"txn_version": 6297687196,
"event_idx": 4,
"emit_address": "0x13eb7ea6b62c6cd791b5c4e0e2ef1dfbe59d1cf4823929343a273274c288bc8a",
"time": "2024-11-20T20:33:38.600241+00:00",
"maker_address": "0x2eda5777ed2bf68cbcc67359dd00ae5fa73b1d5fa160b7c3aeb42d748d485387",
"maker_custodian_id": 28,
"maker_order_id": "15951655917465922493754983",
"maker_side": true,
"market_id": 66,
"price": 11879,
"sequence_number_for_trade": 0,
"size": 10000,
"taker_address": "0x13eb7ea6b62c6cd791b5c4e0e2ef1dfbe59d1cf4823929343a273274c288bc8a",
"taker_custodian_id": 28,
"taker_order_id": "15951748150764039921729536",
"taker_quote_fees_paid": 59395
}
]
}
Example Code to Fetch All trades:
The following TypeScript/Node.js script demonstrates how to call the Get Open Position API using the axios
library.
Copy import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getAllTrades';
const params = {
marketId: 501
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getAllTrades: ", res.data);
}
main().catch(error => {
console.error('An error occurred:', error);
});
13. Get Order Status By Order Id
Query 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:
Copy GET https://perps-tradeapi.kanalabs.io/getOrderStatusByOrderId?marketId=66&orderId=15308325717473050761363456
Example Response:
Copy {
"status": true,
"message": "Fetched order status for a given order Id successfully",
"data": {
"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
}
}
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.
Copy import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getOrderStatusByOrderId';
const params = {
marketId: 501,
orderId : '85094831257134286508036'
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getAllTrades: ", res.data);
}
main().catch(error => {
console.error('An error occurred:', error);
});
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.
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:
Copy GET https://perps-tradeapi.kanalabs.io/getFills?marketId=66&address=0x3a6b332c7889784fe57ea61f507b5056e386db8f56c6323b4d898485f468f0c2&from=2024-11-20T00:00:00Z&to=2024-11-21T23:59:59Z
Example Response:
Copy {
"success": true,
"message": "Fetched fill trades for a given time range Successfully",
"data": [
{
"txn_version": 6296434935,
"event_idx": 1,
"emit_address": "0x3a6b332c7889784fe57ea61f507b5056e386db8f56c6323b4d898485f468f0c2",
"time": "2024-11-20T19:23:14.67535+00:00",
"maker_address": "0x2eda5777ed2bf68cbcc67359dd00ae5fa73b1d5fa160b7c3aeb42d748d485387",
"maker_custodian_id": 28,
"maker_order_id": "15891335065048614061485282",
"maker_side": true,
"market_id": 66,
"price": 11490,
"sequence_number_for_trade": 0,
"size": 1000,
"taker_address": "0x3a6b332c7889784fe57ea61f507b5056e386db8f56c6323b4d898485f468f0c2",
"taker_custodian_id": 28,
"taker_order_id": "15891427297643009687945216",
"taker_quote_fees_paid": 5745
},
{
"txn_version": 6295302625,
"event_idx": 4,
"emit_address": "0x3a6b332c7889784fe57ea61f507b5056e386db8f56c6323b4d898485f468f0c2",
"time": "2024-11-20T18:19:35.70863+00:00",
"maker_address": "0x2eda5777ed2bf68cbcc67359dd00ae5fa73b1d5fa160b7c3aeb42d748d485387",
"maker_custodian_id": 28,
"maker_order_id": "15812401447297883953966476",
"maker_side": false,
"market_id": 66,
"price": 11660,
"sequence_number_for_trade": 0,
"size": 1000,
"taker_address": "0x3a6b332c7889784fe57ea61f507b5056e386db8f56c6323b4d898485f468f0c2",
"taker_custodian_id": 28,
"taker_order_id": "15812549019983827645235200",
"taker_quote_fees_paid": 5830
}
]
}
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.
Copy import axios from "axios";
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getFills';
const params = {
marketId: 'your_market_id',
address: 'your_address',
from: 'your_from_time',
to: 'your_to_time'
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getFillsData : ", res);
}
main().catch(error => {
console.error('An error occurred:', error);
});
14. Get Market Price
Query Parameters :
marketId (Required) - The ID of the market for which the price information is being retrieved.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getMarketPrice?marketId=66
Example Response:
Copy {
"success": true,
"message": "Fetched Market Price Successfully",
"data": {
"bestAskPrice": 6.400,
"bestBidPrice": 9.880
}
}
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.
Copy import axios from "axios";
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getLastPlacedPrice';
const params = {
marketId: 501
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getLastExecutionPrice : ", res);
}
main().catch(error => {
console.error('An error occurred:', error);
});
15. Get Last Execution Price
Query Parameters :
marketId (Required) - The ID of the market for which the last execution price information is being retrieved.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getLastPlacedPrice?marketId=66
Example Response:
Copy {
"success": true,
"message": "Fetched last execution price Successfully",
"data": 8.989
}
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.
Copy import axios from "axios";
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getLastPlacedPrice';
const params = {
marketId: 501
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getLastExecutionPrice : ", res);
}
main().catch(error => {
console.error('An error occurred:', error);
});
16. Get All Open Order Ids
Query 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:
Copy GET https://perps-tradeapi.kanalabs.io/getAllOpenOrderIds?marketId=66&userAddress=0x3a6b332c7889784fe57ea61f507b5056e386db8f56c6323b4d898485f468f0c2
Example Response:
Copy {
"success": true,
"message": "Open order IDs fetched successfully",
"data": [
"645636324063400958808",
"682529812245179800408",
"700976556301709482840",
"719423300401188838232",
"737869903703050289159",
"756316647793939709959"
]
}
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.
Copy import axios from "axios";
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getAllOpenOrderIds';
const params = {
userAddress: '0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770',
marketId: 501
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getOpenOrderIds : ", res);
}
main().catch(error => {
console.error('An error occurred:', error);
});
17. Update Take Profit
Query Parameters :
marketId (Required) - The ID of the market for which the take profit values will be updated.
tradeSide (Required) - The trade side:
false
for the short side.
newTakeProfitPrice (Required) - The new take profit price to be set for the trade.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/updateTakeProfit?marketId=66&tradeSide=true&newTakeProfitPrice=6000
Example Response:
Copy {
"success": true,
"message": "Update take profit payload built succesfully",
"data": {
"function": "0xabbf40e0c31cbedf182f3e6e9c3570f3f91629424723da876becb514bf5d9fc6::perpetual_scripts::update_take_profit",
"functionArguments": [
"501",
"true",
7590
],
"typeArguments": []
}
}
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.
Copy 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 formattedPrivateKey = PrivateKey.formatPrivateKey(
process.env.APTOS_PRIVATEKEY || '',
'ed25519' as PrivateKeyVariants
);
const account = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});
const baseURL = 'https://perps-tradeapi.kanalabs.io/updateTakeProfit';
const params = {
marketId: 501,
tradeSide: true,
newTakeProfitPrice: 6.7
};
const res = await axios.get(baseURL, {
params, headers: {
'x-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);
});
18. Get Account Aptos Balance
userAddress (Required) - The address of the account whose balance will be
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getAccountAptBalance?userAddress=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770
Example Response:
Copy {
"success": true,
"message": "Fetched Account Apt Balance Successfully",
"data": 8.2344617
}
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.
Copy import axios from "axios";
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getAccountAptBalance';
const params = {
userAddress: '0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770'
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getWalletAccountAptosBalance : ", res);
}
main().catch(error => {
console.error('An error occurred:', error);
});
19. Update Stop Loss
Query Parameters :
marketId (Required) - The ID of the market for which the take profit values will be updated.
tradeSide (Required) - The trade side:
false
for the short side.
newStopLossPrice (Required) - The new stop loss price to be set for the trade.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/updateStopLoss?marketId=66&tradeSide=true&newStopLossPrice=6000
Example Response:
Copy {
"success": true,
"message": "Update stop loss payload built succesfully",
"data": {
"function": "0xabbf40e0c31cbedf182f3e6e9c3570f3f91629424723da876becb514bf5d9fc6::perpetual_scripts::update_stop_loss",
"functionArguments": [
"501",
"true",
7590
],
"typeArguments": []
}
}
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.
Copy 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 formattedPrivateKey = PrivateKey.formatPrivateKey(
process.env.APTOS_PRIVATEKEY || '',
'ed25519' as PrivateKeyVariants
);
const account = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});
const baseURL = 'https://perps-tradeapi.kanalabs.io/updateStopLoss';
const params = {
marketId: 501,
tradeSide: true,
newStopLossPrice: 4.6
};
const res = await axios.get(baseURL, {
params, headers: {
'x-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);
});
20. Get Profile Address
Query Parameters :
userAddress
(Required) - The address of the user to get the profile address.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getProfileAddress?userAddress=0xd01e3a233632a41463bd6d289e99e69e1b50815c7afff710e1c992659a8722f3
Example Response:
Copy {
"success": true,
"message": "Profile address fetched successfully",
"data": "0x56ad3b670c9193414e5f3dbc1d9caf7a08368c4ab0b4b29c00ce13c463f6d934"
}
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.
Copy import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getProfileAddress';
const params = {
userAddress: "0x56ad3b670c9193414e5f3dbc1d9caf7a08368c4ab0b4b29c00ce13c463f6d934"
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getProfileAddress: ", res.data);
}
main().catch(error => {
console.error('An error occurred:', error);
});
21. Collapse position
Query Parameters :
marketId
(Required) - The ID of the market you want to collapse a position.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/collapsePosition?marketId=501
Example Response:
Copy {
"success": true,
"message": "collapse position payload built succesfully",
"data": {
"function": "0xabbf40e0c31cbedf182f3e6e9c3570f3f91629424723da876becb514bf5d9fc6::perpetual_scripts::collapse_position",
"functionArguments": [
"624"
],
"typeArguments": []
}
}
Example Code to collapse a position:
The following TypeScript/Node.js script demonstrates how to call the collapse position API using the axios
library.
Copy import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey, PrivateKey, PrivateKeyVariants } from "@aptos-labs/ts-sdk";
import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
const formattedPrivateKey = PrivateKey.formatPrivateKey(
process.env.APTOS_PRIVATEKEY || '',
'ed25519' as PrivateKeyVariants
);
const account = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});
const baseURL = 'https://perps-tradeapi.kanalabs.io/collapsePosition';
const params = {
marketId: 624
};
const res = await axios.get(baseURL, {
params, headers: {
'x-api-key': process.env.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,
});
console.log(`Submitted transaction: ${committedTxn.hash}`);
const response = await aptos.waitForTransaction({
transactionHash: committedTxn.hash,
});
console.log("response", response.success);
}
main().catch(error => {
console.error('An error occurred:', error);
});
22. Get All Trades
Query Parameters :
marketId (Required) - The ID of the market to retrieve all trades information.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getAllTrades?marketId=66
Example Response:
Copy {
"success": true,
"message": "Recent trades fetched successfully",
"data": [
{
"txn_version": 6297687196,
"event_idx": 5,
"emit_address": "0x2eda5777ed2bf68cbcc67359dd00ae5fa73b1d5fa160b7c3aeb42d748d485387",
"time": "2024-11-20T20:33:38.600241+00:00",
"maker_address": "0x2eda5777ed2bf68cbcc67359dd00ae5fa73b1d5fa160b7c3aeb42d748d485387",
"maker_custodian_id": 28,
"maker_order_id": "15951655917465922493754983",
"maker_side": true,
"market_id": 66,
"price": 11879,
"sequence_number_for_trade": 0,
"size": 10000,
"taker_address": "0x13eb7ea6b62c6cd791b5c4e0e2ef1dfbe59d1cf4823929343a273274c288bc8a",
"taker_custodian_id": 28,
"taker_order_id": "15951748150764039921729536",
"taker_quote_fees_paid": 59395
},
{
"txn_version": 6297687196,
"event_idx": 4,
"emit_address": "0x13eb7ea6b62c6cd791b5c4e0e2ef1dfbe59d1cf4823929343a273274c288bc8a",
"time": "2024-11-20T20:33:38.600241+00:00",
"maker_address": "0x2eda5777ed2bf68cbcc67359dd00ae5fa73b1d5fa160b7c3aeb42d748d485387",
"maker_custodian_id": 28,
"maker_order_id": "15951655917465922493754983",
"maker_side": true,
"market_id": 66,
"price": 11879,
"sequence_number_for_trade": 0,
"size": 10000,
"taker_address": "0x13eb7ea6b62c6cd791b5c4e0e2ef1dfbe59d1cf4823929343a273274c288bc8a",
"taker_custodian_id": 28,
"taker_order_id": "15951748150764039921729536",
"taker_quote_fees_paid": 59395
}
]
}
Example Code to Fetch All trades:
The following TypeScript/Node.js script demonstrates how to call the Get Open Position API using the axios
library.
Copy import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getAllTrades';
const params = {
marketId: 501
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getAllTrades: ", res.data);
}
main().catch(error => {
console.error('An error occurred:', error);
});
23. Get Account Apt Balance
Query Parameters :
userAddress
(Required) - The wallet address for which the account balance is being fetched.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getAccountAptBalance?userAddress=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770
Example Response:
Copy {
"success": true,
"message": "Fetched wallet apt balance successfully",
"data": 91.60
}
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.
Copy import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getAccountAptBalance';
const params = {
userAddress: '0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770'
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getAccountAptBalance: ", res.data);
}
main().catch(error => {
console.error('An error occurred:', error);
});
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:
Copy GET https://perps-tradeapi.kanalabs.io/getPerpetualAssetsInfo?marketId=1338
Example Response:
Copy {
"success": true,
"message": "Fetched market infos successfully",
"data": [
{
"__variant__": "V1",
"base_decimals": 8,
"base_name": "APT/USDC",
"counter": "9473",
"creator": "0xb61d7b57333abf8ac036e752f19d0ba0c4baa5404db1cbf868c57dac3628f2bf",
"fee_address": "0x7724a4a23b25b460abc2a5d9fe1fe3c47e2a0e10a156dd713a221f129579c388",
"is_recognised": false,
"last_updated": "1745235856",
"lot_size": "100000",
"maintenance_margin": "250",
"market_address": "0xcfa0086c26787035de6b4a312875c7a70b2f9a29fa880d0cf633ef3dd0acd2c3",
"market_id": "1338",
"market_status": 1,
"max_leverage": "20",
"max_lots": "150000000",
"max_position_value": "125000000000",
"min_lots": "500",
"quote_decimals": 6,
"quote_precision": 3,
"tick_size": "1"
}
]
}
Example Code:
Copy import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getPerpetualAssetsInfo';
const params = {
marketId: '1338'
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("Perpetual Asset Info:", res.data);
}
main().catch(error => {
console.error('An error occurred:', error);
});
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:
Copy GET https://perps-tradeapi.kanalabs.io/getPerpetualAssetsInfo/allMarkets
Example Response:
Copy {
"success": true,
"message": "Fetched market infos successfully",
"data": [
{
"__variant__": "V1",
"base_decimals": 8,
"base_name": "APT/USDC",
"counter": "9473",
"creator": "0xb61d7b57333abf8ac036e752f19d0ba0c4baa5404db1cbf868c57dac3628f2bf",
"fee_address": "0x7724a4a23b25b460abc2a5d9fe1fe3c47e2a0e10a156dd713a221f129579c388",
"is_recognised": false,
"last_updated": "1745235856",
"lot_size": "100000",
"maintenance_margin": "250",
"market_address": "0xcfa0086c26787035de6b4a312875c7a70b2f9a29fa880d0cf633ef3dd0acd2c3",
"market_id": "1338",
"market_status": 1,
"max_leverage": "20",
"max_lots": "150000000",
"max_position_value": "125000000000",
"min_lots": "500",
"quote_decimals": 6,
"quote_precision": 3,
"tick_size": "1"
},
{
"__variant__": "V1",
"base_decimals": 8,
"base_name": "BTC/USDC",
"counter": "4813",
"creator": "0xb61d7b57333abf8ac036e752f19d0ba0c4baa5404db1cbf868c57dac3628f2bf",
"fee_address": "0x7724a4a23b25b460abc2a5d9fe1fe3c47e2a0e10a156dd713a221f129579c388",
"is_recognised": false,
"last_updated": "1745235864",
"lot_size": "1000",
"maintenance_margin": "250",
"market_address": "0xc4de5894f6a97168998719c10f517572cbe10fe6911ca25004fbe87a88247ed4",
"market_id": "1339",
"market_status": 1,
"max_leverage": "20",
"max_lots": "6000000",
"max_position_value": "125000000000",
"min_lots": "10",
"quote_decimals": 6,
"quote_precision": 0,
"tick_size": "10"
},
{
"__variant__": "V1",
"base_decimals": 8,
"base_name": "ETH/USDC",
"counter": "3377",
"creator": "0xb61d7b57333abf8ac036e752f19d0ba0c4baa5404db1cbf868c57dac3628f2bf",
"fee_address": "0x7724a4a23b25b460abc2a5d9fe1fe3c47e2a0e10a156dd713a221f129579c388",
"is_recognised": false,
"last_updated": "1745235871",
"lot_size": "10000",
"maintenance_margin": "250",
"market_address": "0x9e173d4330b94718fd09c3d1d18b707f2713a1cd92e79403ee150429c3125718",
"market_id": "1340",
"market_status": 1,
"max_leverage": "20",
"max_lots": "10000000",
"max_position_value": "125000000000",
"min_lots": "10",
"quote_decimals": 6,
"quote_precision": 1,
"tick_size": "10"
}
]
}
Example Code:
Copy import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getPerpetualAssetsInfo/allMarkets';
const res = await axios.get(baseURL, {
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("All Perpetual Markets Info:", res.data);
}
main().catch(error => {
console.error('An error occurred:', error);
});
25. Add Margin
Query Parameters :
marketId (Required) – The unique identifier of the market where the margin is being added.
tradeSide (Required) - Indicates the trade side:
false
for the short side.
amount (Required) – The amount of additional margin to be added to the position.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/addMargin?marketId=1338&tradeSide=true&amount=1
Example Response:
Copy {
"success": true,
"message": "Add Margin payload built successfully",
"data": {
"function": "0x732f891290449af5e9369866537a51a8e7dc566791aec61a468223ed840b1eb4::perpetual_scripts::add_margin",
"functionArguments": [
"1338",
"true",
1000000
],
"typeArguments": []
}
}
Example Code to add a margin:
The following TypeScript/Node.js script demonstrates how to call the Get Add Margin API using the axios
library.
Copy import { AptosConfig, Aptos, Network, Account, Ed25519PrivateKey, PrivateKey, PrivateKeyVariants } from "@aptos-labs/ts-sdk";
import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
const formattedPrivateKey = PrivateKey.formatPrivateKey(
process.env.APTOS_PRIVATEKEY || '',
'ed25519' as PrivateKeyVariants
);
const account = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});
const baseURL = 'https://perps-tradeapi.kanalabs.io/addMargin';
const params = {
marketId: 1338,
tradeSide: true,
amount: 100
};
const res = await axios.get(baseURL, {
params, headers: {
'x-api-key': process.env.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,
});
console.log(`Submitted transaction: ${committedTxn.hash}`);
const response = await aptos.waitForTransaction({
transactionHash: committedTxn.hash,
});
console.log("response", response.success);
}
main().catch(error => {
console.error('An error occurred:', error);
});
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:
Copy GET https://perps-tradeapi.kanalabs.io/settlePnl?userAddress=0xd0ff27c8411015f386ffc464e3baaa12fca10f1bef1ec6af36c27ed96b65f6c6&marketId=1338=6000
Example Response:
Copy {
"success": true,
"message": "Update position payload built succesfully",
"data": {
"function": "0x732f891290449af5e9369866537a51a8e7dc566791aec61a468223ed840b1eb4::perpetual_scripts::update_position",
"functionArguments": [
"0xd0ff27c8411015f386ffc464e3baaa12fca10f1bef1ec6af36c27ed96b65f6c6",
"1338"
],
"typeArguments": []
}
}
Example Code to Get Settle Pnl:
The following TypeScript/Node.js script demonstrates how to call the Get Settle pnl API using the axios
library.
Copy 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 formattedPrivateKey = PrivateKey.formatPrivateKey(
process.env.APTOS_PRIVATEKEY || '',
'ed25519' as PrivateKeyVariants
);
const account = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});
const baseURL = 'https://perps-tradeapi.kanalabs.io/settlePnl';
const params = {
marketId: 1338,
userAddress: "0xd0ff27c8411015f386ffc464e3baaa12fca10f1bef1ec6af36c27ed96b65f6c6"
};
const res = await axios.get(baseURL, {
params, headers: {
'x-api-key': "your_api_key",
},
});
const payloadData = res.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);
});
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.
Query Parameters :
userAddress
(Required) - The wallet address for which the account balance is being fetched.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getNetProfileBalance?userAddress=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770
Example Response:
Copy {
"success": true,
"message": "Net Profile Balance fetched successfully",
"data": 49443.432113
}
Example Code to Fetch Net Profile Balance Information:
The following TypeScript/Node.js script demonstrates how to call the Get Net Profile Balance API using the axios
library.
Copy import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
async function main(): Promise<void> {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getNetProfileBalance';
const params = {
userAddress: '0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770'
};
const res = await axios.get(baseURL, {
params,
headers: {
'x-api-key': process.env.API_KEY,
},
});
console.log("getNetProfileBalance: ", res.data);
}
main().catch(error => {
console.error('An error occurred:', error);
});
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:
Copy GET https://perps-tradeapi.kanalabs.io/settlePnl?userAddress=0xd0ff27c8411015f386ffc464e3baaa12fca10f1bef1ec6af36c27ed96b65f6c6&marketId=1338=6000
Example Response:
Copy {
"success": true,
"message": "Update position payload built succesfully",
"data": {
"function": "0x732f891290449af5e9369866537a51a8e7dc566791aec61a468223ed840b1eb4::perpetual_scripts::update_position",
"functionArguments": [
"0xd0ff27c8411015f386ffc464e3baaa12fca10f1bef1ec6af36c27ed96b65f6c6",
"1338"
],
"typeArguments": []
}
}
Example Code to Get Settle Pnl:
The following TypeScript/Node.js script demonstrates how to call the Get Settle pnl API using the axios
library.
Copy 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 formattedPrivateKey = PrivateKey.formatPrivateKey(
process.env.APTOS_PRIVATEKEY || '',
'ed25519' as PrivateKeyVariants
);
const account = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});
const baseURL = 'https://perps-tradeapi.kanalabs.io/settlePnl';
const params = {
marketId: 1338,
userAddress: "0xd0ff27c8411015f386ffc464e3baaa12fca10f1bef1ec6af36c27ed96b65f6c6"
};
const res = await axios.get(baseURL, {
params, headers: {
'x-api-key': "your_api_key",
},
});
const payloadData = res.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);
});