kiloex-ts-sdk
v1.1.6
Published
KiloEx contract interaction SDK
Downloads
374
Readme
KiloEx TS SDK
Introduction
The Kilo SDK provides a set of TypeScript interfaces and functions for interacting with the Kilo protocol. allowing users to manage their positions, orders, and trade history on supported chains.
Installation
To install the SDK, you can use npm:
npm install kiloex-ts-sdk
Getting started
Initialization
import { create, ChainId } from 'kiloex-ts-sdk';
const kiloClient = create(ChainId.BSC, {
env?: 'WEB' | 'NODE', // WEB
brokerId?: number
});
env In the code snippet, env is used for environment detection. node refers to the Node.js environment, while web refers to usage within a web browser.
Functions
Supported Chains
Get a list of supported chains:
import { supportedChains } from 'kiloex-ts-sdk';
const chains = supportedChains();
Supported Products by Chain
Get all supported products for a specific chain:
const products = await kiloClient.supportedProductsByChain(chainId);
Get Products Info
Retrieve information about specific products:
const productIds = [1, 2, 3]; // Example product IDs
const productsInfo = await kiloClient.getProductsInfo(productIds);
Get Product Prices
Retrieve prices of specific products:
const productPrices = await kiloClient.getProductPrices(productIds);
Set Approve
Set approval for a spender:
const spender = '0x456def...'; // Example spender address
const isApproved = await kiloClient.setApprove(walletAddress, spender);
Increase Position
Increase a position:
const walletAddress = '0x123abc...'; // Example wallet address
const type = 'Market'; // Example trade type
const position = {
// Example position data
};
const transactionReceipt = await kiloClient.increasePosition(walletAddress, type, position);
Close Position
Close a position:
const positionToClose = {
// Example position data
};
const transactionReceipt = await kiloClient.closePosition(walletAddress, positionToClose);
Update Position Margin
Update the margin of a position:
const positionToUpdate = {
// Example position data
};
const transactionReceipt = await kiloClient.updatePositionMargin(walletAddress, positionToUpdate);
Cancel Order
Cancel a buy/sell limit order:
const orderIndex = 123; // Example order index
const transactionReceipt = await kiloClient.cancelOrder(walletAddress, 'Increase', orderIndex);
Update Order
Update a limit order:
const orderToUpdate = {
// Example order data
};
const transactionReceipt = await kiloClient.updateOrder(walletAddress, orderToUpdate);
Get All Positions
Retrieve all positions associated with a wallet address:
const positions = await kiloClient.getAllPositions(walletAddress);
Get All Orders
Retrieve all orders associated with a wallet address:
const orders = await kiloClient.getAllOrders(walletAddress);
Get Trades History
Retrieve trade history associated with a wallet address:
const tradeHistory = await kiloClient.getTradesHistory(walletAddress);
Cancel Position
The order price is not within the executable price range; the margin needs to be withdrawn
const orderIndex = 123; // Example order index
const transactionReceipt = await kiloClient.cancelPosition(walletAddress, 'Increase', orderIndex);
Quote and Candlestick
We using pyth network as our Oracle, So you can get price and candlestick history from the pyth network, we use this too
https://benchmarks.pyth.network/docs#/TradingView/tradingview_streaming_route_v1_shims_tradingview_streaming_get