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=66
Example Response:
Copy {
"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.
Copy 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
Query Parameters :
marketId
(Required) - The ID of the market you want information about.
address (Required) - The wallet address for which the account balance is being fetched.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getWalletAccountBalance?marketId=66&address=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770
Example Response:
Copy {
"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.
Copy 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
Query Parameters :
marketId
(Required) - The ID of the market you want information about.
address (Required) - The wallet address for which the account balance is being fetched.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getTradingAccountBalance?marketId=66&address=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770
Example Response:
Copy {
"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.
Copy 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
Query Parameters :
marketId
(Required) - The ID of the market you want to deposit.
amount
(Required) - The amount of the quote coin to deposit.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/deposit?marketId=66&amount=50000000
Example Response:
Copy {
"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.
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 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
Query Parameters :
marketId
(Required) - The ID of the market you want to withdraw.
amount
(Required) - The amount of the quote coin to withdraw.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/withdraw?marketId=66&amount=50000000
Example Response:
Copy {
"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.
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 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
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 (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:
Copy GET https://perps-tradeapi.kanalabs.io/limitOrder/?marketId=66&tradeSide=true&direction=false&size=10000&price=3000&leverage=3
Example Response:
Copy {
"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.
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 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
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 (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:
Copy GET https://perps-tradeapi.kanalabs.io/marketOrder?marketId=66&tradeSide=false&direction=true&size=1000&leverage=20
Example Response:
Copy {
"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.
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 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
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:
Copy {
"marketId" : 66 ,
"orderIds" : [ "1077898597726583798162207" , "1077880153515406921884445" ] ,
"tradeSides" : [ true , false ]
}
Example Response:
Copy {
"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.
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 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:
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.
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:
Copy {
"marketId" : 66 ,
"orderTypes" : [ true , true ] ,
"tradeSides" : [ true , true ] ,
"directions" : [ true , true ] ,
"sizes" : [ 1000 , 1000 ] ,
"prices" : [ 1000 , 1000 ] ,
"leverages" : [ 2 , 2 ]
}
Example Response:
Copy {
"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.
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 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:
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.
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:
Copy {
"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:
Copy {
"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.
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 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
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:
Copy GET https://perps-tradeapi.kanalabs.io/openOrders?address=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770&orderType=open&marketId=66
Example Response:
Copy {
"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.
Copy 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
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:
Copy GET https://perps-tradeapi.kanalabs.io/orderHistory?address=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770&type=all&marketId=66
Example Response:
Copy {
"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.
Copy 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
Query Parameters :
address (Required) - The wallet address of the user to view positions for.
marketId (Required) - The ID of the market to filter the positions.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/viewPositions?marketId=66&address=0x2eda5777ed2bf68cbcc67359dd00ae5fa73b1d5fa160b7c3aeb42d748d485387
Example Response:
Copy {
"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" : "0" ,
"kana_contribution" : "216840595363" ,
"market_id" : "66" ,
"open_taker_fee" : "1140088" ,
"trade_id" : "996124179980315787330"
} ,
"shortPosition" : {
"position" : 2 ,
"collateral" : "229533344459" ,
"base_deposit" : "4582833800000" ,
"entry_price" : "486295172045" ,
"exit_price" : "0" ,
"liquidation_price" : "7012" ,
"oracle_price" : "1165049884" ,
"leverage" : 2 ,
"open_size" : "4582833800000" ,
"close_size" : "0" ,
"filled_open_size" : "3326206300000" ,
"filled_close_size" : "0" ,
"take_profit_price" : "" ,
"stop_loss_price" : "" ,
"close_taker_fee" : "0" ,
"collateral_cover" : "229533344459" ,
"market_id" : "66" ,
"open_taker_fee" : "0" ,
"trade_id" : "866996971464348926018" ,
"trade_value" : "459066688929"
}
}
}
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" ;
async function main () : Promise < void > {
const baseURL = 'https://perps-tradeapi.kanalabs.io/viewPositions' ;
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 getOpenPosition = res .data;
console .log ( "getOpenPosition : " , getOpenPosition);
}
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 {
"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 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" ;
async function main () : Promise < void > {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getAllTrades' ;
const params = {
marketId : 'your_market_id'
};
const res = await axios .get (baseURL , {
params ,
headers : {
'api_key' : process . env . API_KEY ,
} ,
});
const getAllTrades = res .data;
console .log ( "getAllTrades : " , getAllTrades);
}
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" ;
async function main () : Promise < void > {
const baseURL = 'https://perps-tradeapi.kanalabs.io/getOrderStatusByOrderId' ;
const params = {
marketId : 'your_market_id' ,
orderId : 'your_order_id'
};
const res = await axios .get (baseURL , {
params ,
headers : {
'api_key' : process . env . API_KEY ,
} ,
});
const getOrderStatusByOrderId = res .data;
console .log ( "getOrderStatusByOrderId : " , getOrderStatusByOrderId);
}
main () .catch (error => {
console .error ( 'An error occurred:' , error);
});
14. Get Fills
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 : {
'api_key' : process . env . API_KEY ,
} ,
});
const getFillsData = res .data;
console .log ( "getFillsData : " , getFillsData);
}
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 {
"price" : {
"status" : true ,
"message" : "Fetched Market Price Successfully" ,
"bestBidPriceValue" : 11683 ,
"bestAskPriceValue" : 11692
}
}
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/getMarketPrice' ;
const params = {
marketId : 'your_market_id'
};
const res = await axios .get (baseURL , {
params ,
headers : {
'api_key' : process . env . API_KEY ,
} ,
});
const getMarketPrice = res .data;
console .log ( "getMarketPrice : " , getMarketPrice);
}
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 {
"price" : {
"status" : true ,
"message" : "Fetched last execution price successfully" ,
"getLastExecutionPrice" : {
"tickPrice" : 11711 ,
"usdcPrice" : 11.711
}
}
}
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 : 'your_market_id'
};
const res = await axios .get (baseURL , {
params ,
headers : {
'api_key' : process . env . API_KEY ,
} ,
});
const getLastExecutionPrice = res .data;
console .log ( "getLastExecutionPrice : " , getLastExecutionPrice);
}
main () .catch (error => {
console .error ( 'An error occurred:' , error);
});
16. Get Open Order Ids
Query Parameters :
address (Required) - The address associated with the orders.
marketId (Required) - The ID of the market for which open order IDs are being retrieved.
orderType (Required) - Specifies the type of order:
open
- Get current open orders.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/openOrderIds?marketId=66&address=0x3a6b332c7889784fe57ea61f507b5056e386db8f56c6323b4d898485f468f0c2&orderType=open
Example Response:
Copy {
"status" : true ,
"message" : "Fetched open order IDs successfully" ,
"data" : {
"orderIds" : [
"16393455439016527457691408"
]
}
}
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/openOrderIds' ;
const params = {
address : 'your_wallet_address' ,
marketId : 'your_market_id' ,
orderType : 'your_order_type' // open
};
const res = await axios .get (baseURL , {
params ,
headers : {
'api_key' : process . env . API_KEY ,
} ,
});
const getOpenOrderIds = res .data;
console .log ( "getOpenOrderIds : " , getOpenOrderIds);
}
main () .catch (error => {
console .error ( 'An error occurred:' , error);
});
17. Get Long Position Open Orders
Query Parameters :
address (Required) - The address of the user for which the long position open orders are being retrieved.
marketId (Required) - The ID of the market for which the long position open orders are being retrieved.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/longPositionOpenOrders?marketId=66&address=0x3a6b332c7889784fe57ea61f507b5056e386db8f56c6323b4d898485f468f0c2
Example Response:
Copy {
"success" : true ,
"message" : "Fetched long position open orders successfully" ,
"data" : [
{
"collateral" : "500000" ,
"filled_size" : "0" ,
"leverage" : 20 ,
"order_id" : "16393455439016527457691408" ,
"order_price" : "10000" ,
"order_side" : false ,
"order_size" : "100000000" ,
"trade_type" : 1
}
]
}
Example Code to Fetch Long Position Open Orders:
The following TypeScript/Node.js script demonstrates how to call the Get Long Position Open OrderAPI using the axios
library.
Copy import axios from "axios" ;
async function main () : Promise < void > {
const baseURL = 'https://perps-tradeapi.kanalabs.io/longPositionOpenOrders' ;
const params = {
address : 'your_wallet_address' ,
marketId : 'your_market_id'
};
const res = await axios .get (baseURL , {
params ,
headers : {
'api_key' : process . env . API_KEY ,
} ,
});
const getLongPositionOpenOrders = res .data;
console .log ( "getLongPositionOpenOrders : " , getLongPositionOpenOrders);
}
main () .catch (error => {
console .error ( 'An error occurred:' , error);
});
18. Get Short Position Open Orders
Query Parameters :
address (Required) - The address of the user for which the short position open orders are being retrieved.
marketId (Required) - The ID of the market for which the short position open orders are being retrieved.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/shortPositionOpenOrders?marketId=66&address=0x3a6b332c7889784fe57ea61f507b5056e386db8f56c6323b4d898485f468f0c2
Example Response:
Copy {
"success" : true ,
"message" : "Fetched short position open orders successfully" ,
"data" : [
{
"collateral" : "500000" ,
"filled_size" : "0" ,
"leverage" : 20 ,
"order_id" : "16393455439016527457691408" ,
"order_price" : "10000" ,
"order_side" : false ,
"order_size" : "100000000" ,
"trade_type" : 1
}
]
}
Example Code to Fetch Short Position Open Orders:
The following TypeScript/Node.js script demonstrates how to call the Get Short Position Open OrderAPI using the axios
library.
Copy import axios from "axios" ;
async function main () : Promise < void > {
const baseURL = 'https://perps-tradeapi.kanalabs.io/shortPositionOpenOrders' ;
const params = {
address : 'your_wallet_address' ,
marketId : 'your_market_id'
};
const res = await axios .get (baseURL , {
params ,
headers : {
'api_key' : process . env . API_KEY ,
} ,
});
const getShortPositionOpenOrders = res .data;
console .log ( "getshortPositionOpenOrders : " , getShortPositionOpenOrders);
}
main () .catch (error => {
console .error ( 'An error occurred:' , error);
});
19. Update Take Profit And Stop Loss
Query Parameters :
marketId (Required) - The ID of the market for which the take profit and stop loss 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.
newStopLossPrice (Required) - The new stop loss price to be set for the trade.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/updateTakeProfitAndStop?marketId=66&tradeSide=true&newTakeProfitPrice=6000&newStopLossPrice=4000
Example Response:
Copy {
"status" : true ,
"message" : "Update TPSL payload built successfully" ,
"data" : {
"function" : "0x1ce63c441256263ea2f45dd2d3a1e68e5843107c65c10b79c7a2d5aa2b7a4e3e::perp_market::update_tpsl" ,
"functionArguments" : [ 66 , true , 6000 , 4000 ] ,
"typeArguments" : [
"0x197b9c79f40089f150e3c493edb8cf145efec6bd6b0474f3b08ad738549fa1d1::asset::USDC"
]
}
}
Example Code to Update take profit and stop loss price:
The following TypeScript/Node.js script demonstrates how to call the Get Update Take Profit And 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 account = Account .fromPrivateKey ({
privateKey : new Ed25519PrivateKey ( "your_private_key" ) ,
});
const baseURL = 'https://perps-tradeapi.kanalabs.io/updateTakeProfitAndStop' ;
const params = {
marketId : 'your_market_id' ,
tradeSide : 'your_trade_side' ,
newTakeProfitPrice : 'your_tp_price' ,
newStopLossPrice : 'your_sl_price'
};
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);
});
20. Get Account Aptos Balance
marketId (Required) - The ID of the market for which the account's balance is being retrieved.
address (Required) - The address of the account whose balance will be
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/getAccountAptBalance?marketId=66&address=0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770
Example Response:
Copy {
"status" : true ,
"message" : "Fetched wallet account aptos balance successfully" ,
"data" : 611899
}
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 = {
marketId : 'your_market_id' ,
address : 'your_wallet_address'
};
const res = await axios .get (baseURL , {
params ,
headers : {
'api_key' : process . env . API_KEY ,
} ,
});
const getWalletAccountAptosBalance = res .data;
console .log ( "getWalletAccountAptosBalance : " , getWalletAccountAptosBalance);
}
main () .catch (error => {
console .error ( 'An error occurred:' , error);
});
21. Get User Open Orders
Query Parameters :
address (Required) - The wallet address to retrieve open orders for.
marketId (Required) - The ID of the market to filter open orders.
Example Request:
Copy GET https://perps-tradeapi.kanalabs.io/userOpenOrders?marketId=66&address=0x037d5a65c13e855b49f3b8657589ee2de09d9948a5daedf1ca739fb8a6d50558
Example Response:
Copy {
"status" : true ,
"message" : "Fetched user open orders successfully" ,
"data" : [
{
"marketOrderId" : "31367931982243526919339648" ,
"orderSide" : true , // false -> buy & true -> asks
"marketPrice" : "16000" ,
"marketSize" : "50000000" ,
"leverage" : 10 ,
"tradeType" : 7 ,
"timestamp" : null
}
]
}
Note : Trade Types 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 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" ;
async function main () : Promise < void > {
const baseURL = 'https://perps-tradeapi.kanalabs.io/userOpenOrders' ;
const params = {
address : 'your_wallet_address' ,
marketId : 'your_market_id'
};
const res = await axios .get (baseURL , {
params ,
headers : {
'api_key' : process . env . API_KEY ,
} ,
});
const getUserOpenOrders = res .data;
console .log ( "getUserOpenOrders : " , getUserOpenOrders);
}
main () .catch (error => {
console .error ( 'An error occurred:' , error);
});