API Documentation
Advanced integrations and direct contract calls. Examples show parameter encodings, decimals, and GraphQL lookups for common integration tasks.
Contract Integration
The contract exposes pair metadata, order and trade entry points, and administrative configs. Below are the commonly used methods and the parameter shapes for direct interaction (ethers.js / web3).
Contract Address
Open Market Trade
openMarketTradeSend a tuple matching OpenDataInput. For market fills supply a worst acceptable price.
View parameters & example
struct OpenDataInput {
address pairBase;
bool isLong;
address tokenIn;
uint256 amountIn; // token decimals
uint256 qty; // 1e10
uint256 price; // 1e8
uint256 stopLoss; // 1e8
uint256 takeProfit;//1e8
uint256 broker;
}
Example tuple:
["0x7130...ead9c", true, "0x55d3...7955", "100000000000000000000", "10000000", "2000000000000", "1900000000000", "2500000000000", 1]Limit Order
createLimitOrderSame OpenDataInput tuple — use price as the limit price. Limit orders are stored and executed by background processes.
Close Trade
closeTradePass the bytes32 tradeHash to close a trade from the caller's perspective.
Manage Trade
addMargin, updateTradeTpAndSlAdd margin (amount in 1e10 units), update TP/SL (prices in 1e8), or cancel limit orders by hash.
Response Structures
Compact reference of the important fields returned by contract methods.
PairView Struct
struct PairView {
string name; // BTC/USD
address base;
uint16 basePosition;
PairType pairType;
PairStatus status;
uint256 maxLongOiUsd;
uint256 maxShortOiUsd;
uint256 fundingFeePerBlockP; // 1e18
LibPairsManager.LeverageMargin[] leverageMargins;
LibPairsManager.SlippageConfig slippageConfig;
LibFeeManager.FeeConfig feeConfig;
}GraphQL Integration
Fetch user order and trade history via our subgraph endpoints for comprehensive data analysis.
Query Example
query OrderAndTradeHistorys {
orderAndTradeHistories(
skip: 0
first: 1000
orderBy: timestamp
orderDirection: desc
where: { user: "0x04e5...b28f" }
) {
id
orderOrTradeHash
actionType
timestamp
limitOrder { id pair { name } isLong token { symbol } amountIn limitPrice qty }
trade { id pair { name } isLong token { symbol } entryPrice qty pnl }
}
}Decimals & Conventions
Important decimal precision standards used throughout the contract system.
Margin Decimals
USDT / USDC margin amounts
Price Decimals
All price values and oracle feeds
Quantity Decimals
Contract quantity amounts
Developer Resources
External Tools
Documentation
⚠️Important Notes
- • Always double-check decimals when building amounts
- • Market calls accept a worst price to protect against slippage
- • Test with small amounts on testnet before mainnet deployment