AsterDEX API Documentation - Complete Guide to BNB Smart Chain Perpetual Futures Trading
Overviewβ
AsterDEX is a leading perpetual decentralized exchange (Perp DEX) built on BNB Smart Chain (BSC) that revolutionizes cryptocurrency futures trading through automated market-making mechanisms. This comprehensive API documentation provides developers with everything needed to integrate AsterDEX's perpetual futures data, liquidation events, and trading analytics into their DeFi applications.
What is AsterDEX?β
AsterDEX operates as a decentralized futures exchange on BNB Smart Chain, enabling users to:
- Trade perpetual futures contracts with leverage
- Provide liquidity to automated market makers
- Earn fees through liquidity provision
- Access margin trading with advanced risk management
- Monitor funding rates and market dynamics
Why Use Bitquery for AsterDEX Data?β
Bitquery provides comprehensive blockchain data infrastructure that indexes the entire BSC chain in real-time. All AsterDEX trading data β including perpetual futures trades, liquidation events, margin calls, and smart contract interactions β is automatically captured and made available through powerful GraphQL APIs and streaming services.
Key advantages:
- β Real-time data access without running blockchain nodes
- β Historical data for backtesting and analytics
- β GraphQL API for flexible data queries
- β Streaming capabilities for live trading applications
- β Complete order lifecycle tracking from creation to settlement
What You Can Build with AsterDEX API Integrationβ
With Bitquery's AsterDEX integration, developers can build:
- Query all trades, swaps, and liquidity pool activity on AsterDEX
- Monitor trader, token pairs, and pool performance in real-time
- Stream realβtime onβchain events (swaps, stop loss & take profit updates, liquidations) as they occur
Quick Start Guideβ
Prerequisites for AsterDEX API Integrationβ
Before integrating AsterDEX APIs, ensure you have:
- Bitquery Account: Sign up at ide.bitquery.io for API access
- GraphQL Knowledge: Basic understanding of GraphQL query syntax
- BNB Smart Chain Familiarity: Knowledge of BSC addresses and transactions
- Development Environment: Any programming language with HTTP request capabilities
5-Minute Setupβ
// Example: Fetch latest AsterDEX trades
const query = `
{
EVM(dataset: realtime, network: bsc) {
Events(
where: {LogHeader: {Address: {is: "0x1b6F2d3844C6ae7D56ceb3C3643b9060ba28FEb0"}}}
orderBy: {descending: Block_Time}
limit: {count: 10}
) {
Block {
Time
}
Transaction {
Hash
}
Log {
Signature {
Name
}
}
}
}
}
`;
fetch('https://streaming.bitquery.io/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({ query })
});
Smart Contract Informationβ
| Contract Type | Address | Network | Purpose |
|---|---|---|---|
| AsterDEX Main Contract | 0x1b6F2d3844C6ae7D56ceb3C3643b9060ba28FEb0 | BNB Smart Chain (BSC) | Core perpetual futures trading logic |
| Network ID | 56 | BNB Smart Chain | Main BSC network identifier |
| Block Explorer | bscscan.com | BSC Explorer | Contract verification and transactions |
AsterDEX Order Lifecycleβ
The AsterDEX Order Lifecycle is defined by the sequence of smart contract events emitted during the creation, execution, modification, and closing of trades on the AsterDEX protocol deployed on BNB Smart Chain (BSC). Using the ABI, we can trace the major steps of a trade as follows:
1. Order Creationβ
A trader begins by opening a position using one of the following contract calls:
openMarketTradeoropenMarketTradeBNBβ for immediate market ordersopenLimitOrderoropenLimitOrderBNBβ for pending limit orders
These functions emit events like:
OpenMarketTrade(user, tradeHash, trade)β signals a new market tradeOpenLimitOrder(user, orderHash, data)β logs the creation of a limit order
These events include key parameters:
- Pair base (trading pair symbol)
- isLong flag (direction)
- tokenIn, amountIn (input asset and margin)
- qty (position size)
- price, stopLoss, takeProfit
- broker (affiliate ID)
2. Trade Pending / Validationβ
After the trade is created, AsterDEX emits MarketPendingTrade or PredictAndBetPending events to indicate the trade or bet is awaiting price validation or oracle callback. For limit orders, this pending state continues until market conditions are met.
3. Trade Executionβ
When the trade conditions are satisfied (for market or limit execution), the contract emits:
ExecuteLimitOrderSuccessful(user, orderHash)β for executed limit ordersExecuteLimitOrderRejected(user, orderHash, refund)β if conditions are invalidMarketTradeCallbackβ finalizes market trade once the external price feed confirms execution
Once executed, the trader's position is stored, and Bitquery indexes these on-chain records as open trades.
4. Margin Update (Optional)β
Traders can adjust their position margin using the addMargin or updateMargin functions, which emit:
UpdateMargin(user, tradeHash, beforeMargin, margin)β updates collateral
These events help Bitquery track capital movement within an active position.
5. Stop-Loss / Take-Profit / Liquidationβ
During the trade's lifecycle, risk management parameters can trigger automatically. The following events define these actions:
UpdateTradeSl/UpdateTradeTp/UpdateTradeTpAndSlβ manual stop-loss or take-profit updatesExecuteTpSlOrLiqβ executed close due to stop-loss, take-profit, or liquidation conditionExecuteCloseRejectedβ if the closing execution fails or is invalid
These events are captured by Bitquery and can be used to determine close reason and realized PnL.
6. Trade Closingβ
A trade is closed manually or automatically, resulting in:
CloseTradeSuccessful(user, tradeHash, closeInfo)β main closing event, includes closePrice, fundingFee, closeFee, pnl, holdingFeeCloseTradeReceivedβ indicates funds have been distributed to the traderCloseTradeAddLiquidity/CloseTradeRemoveLiquidityβ if closing affects liquidity pools
Bitquery records these closing events, linking them with the original tradeHash and calculating total realized profit or loss.
7. Settlement and Fee Distributionβ
When a trade closes, associated fees are emitted as separate events:
OpenFee/CloseFeeβ show DAO, broker, and pool fee splitsFundingFeeAddLiquidityβ transfers funding fees into liquidity poolsWithdrawRevenueβ shows DAO or broker withdrawals of earned fees
These events help reconstruct the entire economic flow of a trade β from initiation to settlement.
8. Post-Trade State Updatesβ
Finally, market-level updates are emitted periodically:
UpdatePairAccFundingFeePerShareβ funding rate updatesUpdatePairPositionInfoβ updates aggregate long/short positions for a pair
These allow Bitquery to display aggregate market metrics, such as open interest, funding rates, and average entry prices.
Summary of Core Eventsβ
| Stage | Key Events | Description |
|---|---|---|
| Order Open | OpenMarketTrade, OpenLimitOrder | Creation of new orders |
| Pending | MarketPendingTrade, PredictAndBetPending | Waiting for oracle / validation |
| Execution | ExecuteLimitOrderSuccessful, MarketTradeCallback | Order filled |
| Margin Update | UpdateMargin | Margin increased or decreased |
| Risk Triggers | ExecuteTpSlOrLiq, UpdateTradeSl, UpdateTradeTp | Stop-loss/TP triggered |
| Close | CloseTradeSuccessful, CloseTradeReceived | Trade settled |
| Fees | OpenFee, CloseFee, FundingFeeAddLiquidity | Fee settlements |
| Market Updates | UpdatePairPositionInfo, UpdatePairAccFundingFeePerShare | Aggregate pair data refresh |
Bitquery indexes all of these events in real-time, linking them to transactions, blocks, and tradersβenabling complete lifecycle tracking of each AsterDEX trade via API or stream.
AsterDEX API Examplesβ
1. All Events of AsterDEXβ
Monitor all events emitted by the AsterDEX contract to track all platform activities.
Query Link: All events of AsterDEX
{
EVM(dataset: realtime, network: bsc) {
Events(
limit: {count: 20}
where: {LogHeader: {Address: {is: "0x1b6F2d3844C6ae7D56ceb3C3643b9060ba28FEb0"}}}
) {
count
Log {
Signature {
Name
Signature
}
}
}
}
}
2. OpenMarketTrade Eventsβ
OpenMarketTrade is when a user opens a market trade. The following API provides all newly opened market trades on AsterDEX.
Query Link: AsterDEX - OpenMarketTrade
Similarly, we can get all newly created Limit Orders by following the OpenLimitOrder event.
Difference between OpenLimitOrder and OpenMarketTradeβ
| Feature | OpenLimitOrder | OpenMarketTrade |
|---|---|---|
| Purpose | Creates a limit order β an instruction to open a trade only when price conditions are met. | Opens a market trade immediately at the current market price. |
| Function Call | openLimitOrder() or openLimitOrderBNB() | openMarketTrade() or openMarketTradeBNB() |
| Emitted Event | OpenLimitOrder(address user, bytes32 orderHash, IBook.OpenDataInput data) | OpenMarketTrade(address user, bytes32 tradeHash, IBook.OpenDataInput trade) |
| Execution Timing | Delayed β waits for trigger (price crossing limit, oracle validation). | Immediate β executes as soon as transaction is confirmed. |
| Order State After Creation | Becomes pending β monitored by AsterDEX Keeper or Chainlink callback. | Becomes active trade instantly. |
| Follow-up Events | β’ ExecuteLimitOrderSuccessful (when executed)β’ ExecuteLimitOrderRejected (if canceled/invalid)β’ CancelLimitOrder (if user cancels) | β’ MarketPendingTrade (waiting oracle)β’ MarketTradeCallback (execution confirmation)β’ PendingTradeRefund (if failed) |
| Event Parameters (data struct) | pairBase, isLong, tokenIn, amountIn, qty, price, stopLoss, takeProfit, broker | Same struct, but price acts as execution price instead of limit trigger. |
3. All Recent Liquidations on AsterDEXβ
When there is a liquidation event on AsterDEX, it emits ExecuteCloseSuccessful event with executionType 2.
Query Link: AsterDEX - All latest Liquidations
ExecutionTypes Explainedβ
There are 4 executionTypes:
- 0 β TakeProfit (TP) β closed because TP hit (handled by
executeTpSlOrLiq) - 1 β StopLoss (SL) β closed because SL hit (your sample shows
executionType = 1with negative PnL, consistent with SL) - 2 β Liquidation (LIQ) β closed by liquidation (also through
executeTpSlOrLiq) - 3 β Manual/Market close β user (or UI) explicitly requested a close via
closeTrade(...); still emitsExecuteCloseSuccessfulwith this code. (This path does not go throughexecuteTpSlOrLiqbut the event includes the same enum.)
4. Getting All the Details of a Tradeβ
In AsterDEX every trade has an Order Hash, using which you can track the whole lifecycle of that trade.
For example, for this OrderHash 5d5a2a37ef2afff8ce95101930507af4a255e271f5201658ea2660bc3baf6605
You can check all related events using the following query. This query takes time as we are querying arguments which are not indexed inside our database. You can use any latest trade to make it fast.
Query Link: All details of trade - 5d5a2a37ef2afff8ce95101930507af4a255e271f5201658ea2660bc3baf6605
Example Trade Lifecycleβ
Here are all the emitted events for this trade and related transactions:
- OpenLimitOrder -
0x67b7fe335e05599ae6b316b348c23055e152282638bd4e9e6219283a46789613 - UpdateOrderSl -
0x1b22bb4787efb3c40aca9093aedd70a59a9767ad7c3f3b19a29048f6514ca5dc - OpenMarketTrade -
0x0b318a469ebc6f648d0c3a7e95705aa72c807f9248b21b451963970936ee48a0 - ExecuteLimitOrderSuccessful -
0x0b318a469ebc6f648d0c3a7e95705aa72c807f9248b21b451963970936ee48a0 - UpdateTradeSl -
0x6cb3d98e95f78e3708665c35481c04a96080b0ce4a3afd2b53cf4a49c164209d - CloseTradeReceived -
0x2e24c951abbfb2cdea92b4f7157f52727b21761bc26368614a40a3d86137ba2e - ExecuteCloseSuccessful -
0x2e24c951abbfb2cdea92b4f7157f52727b21761bc26368614a40a3d86137ba2e
Similarly, you can query any event using our events API. You can check this API to see the complete list of events: All events of AsterDEX
5. Following a Specific AsterDEX Traderβ
Using Bitquery's APIs you can follow specific traders on AsterDEX to check all their latest activities.
Query Link: Traders data - 0x2b7363708984aa25a90450cfca7bedaf6804115c
This is a very interesting address (0x2b7363708984aa25a90450cfca7bedaf6804115c), it looks like it's market making on AsterDEX.
You can look for Transaction -> From or in some cases the address might be in arguments, for example: Traders specific event
You can actually merge these two queries. Here is an example: Combined Traders data - 0x01554d63537d3c62715826a268d4eab645d64b92
Complete List of AsterDEX Eventsβ
Here is the complete list of all events emitted by the AsterDEX smart contract with their signatures:
| Event Name | Signature |
|---|---|
| PendingPredictionRefund | PendingPredictionRefund(address,uint256,uint8) |
| MarketPendingTrade | MarketPendingTrade(address,bytes32,(address,bool,address,uint96,uint80,uint64,uint64,uint64,uint24)) |
| OpenFee | OpenFee(address,uint256,uint256,uint24,uint256,uint256) |
| CloseTradeAddLiquidity | CloseTradeAddLiquidity(address,uint256) |
| ExecuteLimitOrderSuccessful | ExecuteLimitOrderSuccessful(address,bytes32) |
| CloseTradeReceived | CloseTradeReceived(address,bytes32,address,uint256) |
| UnStake | UnStake(address,uint256) |
| BurnFee | BurnFee(address,address,uint256,uint256,uint256,uint256) |
| FundingFeeAddLiquidity | FundingFeeAddLiquidity(address,uint256) |
| OpenLimitOrder | OpenLimitOrder(address,bytes32,(address,bool,address,uint96,uint80,uint64,uint64,uint64,uint24)) |
| CloseTradeRemoveLiquidity | CloseTradeRemoveLiquidity(address,uint256) |
| SettlePredictionSuccessful | SettlePredictionSuccessful(uint256,bool,uint256,address,uint256,uint256) |
| MintAlp | MintAlp(address,address,uint256,uint256) |
| ExecuteCloseRejected | ExecuteCloseRejected(address,bytes32,uint8,uint64,uint64) |
| UpdatePairAccFundingFeePerShare | UpdatePairAccFundingFeePerShare(address,uint256,int256,uint256) |
| UpdateOrderSl | UpdateOrderSl(address,bytes32,uint256,uint256) |
| CloseFee | CloseFee(address,uint256,uint256,uint24,uint256,uint256) |
| CloseTradeSuccessful | CloseTradeSuccessful(address,bytes32,(uint64,int96,uint96,int96,uint96)) |
| UpdateMargin | UpdateMargin(address,bytes32,uint256,uint256) |
| MintFee | MintFee(address,address,uint256,uint256,uint256,uint256) |
| PredictAndBet | PredictAndBet(address,uint256,(address,uint96,address,uint96,address,uint96,uint32,uint64,uint40,uint24,bool,uint8)) |
| BurnRemoveLiquidity | BurnRemoveLiquidity(address,address,uint256) |
| UpdateSlippageConfig | UpdateSlippageConfig(uint16,uint8,uint256,uint256,uint16,uint16,uint256,uint256) |
| PendingTradeRefund | PendingTradeRefund(address,bytes32,uint8) |
| PredictionCloseFee | PredictionCloseFee(address,uint256,uint256,uint24,uint256,uint256) |
| PredictAndBetPending | PredictAndBetPending(address,uint256,(address,uint96,address,uint96,address,uint64,uint24,bool,uint128,uint8)) |
| UpdatePairPositionInfo | UpdatePairPositionInfo(address,uint256,uint256,uint256,int256,uint64,uint64) |
| OpenMarketTrade | OpenMarketTrade(address,bytes32,(address,uint32,uint64,address,address,uint96,uint64,uint64,uint24,bool,uint96,int256,uint96,uint40,uint80,uint40,uint256)) |
| ExecuteCloseSuccessful | ExecuteCloseSuccessful(address,bytes32,uint8,(uint64,int96,uint96,int96,uint96)) |
| CancelLimitOrder | CancelLimitOrder(address,bytes32) |
| UpdateTradeTp | UpdateTradeTp(address,bytes32,uint256,uint256) |
| UpdateTradeSl | UpdateTradeSl(address,bytes32,uint256,uint256) |
| MintAddLiquidity | MintAddLiquidity(address,address,uint256) |
| BurnAlp | BurnAlp(address,address,address,uint256,uint256) |
Developer Integration Guideβ
Getting Started with AsterDEX APIsβ
-
Access Bitquery GraphQL IDE: All AsterDEX APIs are accessible through Bitquery's GraphQL IDE
-
Use the Contract Address: The main AsterDEX contract address is
0x1b6F2d3844C6ae7D56ceb3C3643b9060ba28FEb0on BNB Smart Chain -
Choose Your Network: Always specify
network: bscfor BNB Smart Chain queries -
Filter by Events: Use the event signatures from the complete list above to track specific trading activities
Common Use Casesβ
Trading Dashboard:
- Track
OpenMarketTradeandOpenLimitOrderfor new positions - Monitor
CloseTradeSuccessfulfor position closures - Display
UpdateMarginevents for margin changes
Risk Management:
- Monitor
ExecuteCloseSuccessfulwithexecutionType: 2for liquidations - Track
UpdateTradeSlandUpdateTradeTpfor stop-loss and take-profit updates - Alert on funding rate changes via
UpdatePairAccFundingFeePerShare
Analytics Platform:
- Aggregate trading volumes from all position opening/closing events
- Analyze trader behavior using specific trader addresses
- Calculate platform fees from
OpenFeeandCloseFeeevents
Arbitrage Monitoring:
- Watch for price discrepancies in
MarketPendingTradeevents - Monitor funding rates for cross-platform opportunities
- Track liquidation events for potential arbitrage
Best Practices for AsterDEX API Integrationβ
Performance Optimizationβ
Efficient Query Design:
- Use specific event names instead of querying all events
- Implement proper pagination for large datasets
- Cache frequently accessed data to reduce API calls
- Use GraphQL field selection to minimize response size
Real-time Data Handling:
// Optimized query for high-frequency trading applications
const optimizedQuery = `{
EVM(dataset: realtime, network: bsc) {
Events(
where: {
Log: {Signature: {Name: {in: ["OpenMarketTrade", "ExecuteCloseSuccessful"]}}}
LogHeader: {Address: {is: "0x1b6F2d3844C6ae7D56ceb3C3643b9060ba28FEb0"}}
}
orderBy: {descending: Block_Time}
limit: {count: 50}
) {
Block { Time Number }
Arguments { Name Value }
}
}
}`;
Security Considerationsβ
API Key Management:
- Store API keys securely using environment variables
- Implement API key rotation for production applications
- Use read-only permissions when possible
- Monitor API usage and set up alerts for unusual activity
Data Validation:
- Always validate contract addresses and event signatures
- Implement checksum verification for address fields
- Cross-reference critical data with multiple sources
- Set up monitoring for data anomalies
Error Handling and Reliabilityβ
Robust Integration Pattern:
async function fetchAsterDEXData(retries = 3) {
try {
const response = await fetch(BITQUERY_ENDPOINT, {
method: 'POST',
headers: { 'Authorization': `Bearer ${API_KEY}` },
body: JSON.stringify({ query })
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
return await response.json();
} catch (error) {
if (retries > 0) {
console.log(`Retrying... ${retries} attempts remaining`);
await new Promise(resolve => setTimeout(resolve, 1000));
return fetchAsterDEXData(retries - 1);
}
throw error;
}
}
Scaling Your Applicationβ
Production Deployment:
- Implement connection pooling for high-throughput applications
- Use caching layers (Redis/Memcached) for frequently accessed data
- Set up monitoring and alerting for API performance
- Plan for rate limit management and backoff strategies
Data Processing Pipeline:
- Process events in chronological order for accurate state tracking
- Implement event deduplication for reliability
- Use event sourcing patterns for complex trading logic
- Set up data backup and recovery procedures
Additional Resourcesβ
- Bitquery Documentation
- GraphQL Query Guide
- BNB Smart Chain Explorer
- Production Deployment Guide
- API Rate Limits
Frequently Asked Questions (FAQ)β
General AsterDEX API Questionsβ
Q: What is AsterDEX and how does it work?
A: AsterDEX is a perpetual decentralized exchange on BNB Smart Chain that allows users to trade cryptocurrency futures with leverage, provide liquidity, and earn trading fees. It uses automated market-making mechanisms for decentralized derivatives trading.
Q: How do I access AsterDEX trading data without running a BSC node?
A: Use Bitquery's GraphQL APIs to access complete AsterDEX data including trades, liquidations, and smart contract events without infrastructure setup. All data is indexed in real-time from BNB Smart Chain.
Q: What contract address does AsterDEX use on BSC?
A: The main AsterDEX contract address is 0x1b6F2d3844C6ae7D56ceb3C3643b9060ba28FEb0 on BNB Smart Chain (BSC).
API Integration Questionsβ
Q: How can I track AsterDEX liquidations in real-time?
A: Use our liquidation API to monitor ExecuteCloseSuccessful events with executionType: 2. These events indicate liquidation occurrences with detailed position and price information.
Q: Can I track a specific trader's activity on AsterDEX?
A: Yes, use our trader-specific APIs to monitor all trading activities for any wallet address, including position openings, closures, margin updates, and P&L calculations.
Q: How do I differentiate between limit orders and market orders?
A: Monitor OpenLimitOrder events for limit orders and OpenMarketTrade events for market orders. Each has different execution timing and follow-up events.
Q: What are the different execution types in AsterDEX?
A: There are 4 execution types: 0 (TakeProfit), 1 (StopLoss), 2 (Liquidation), and 3 (Manual/Market close). Each indicates how a position was closed.
Technical Implementation Questionsβ
Q: How do I track the complete lifecycle of an AsterDEX trade?
A: Use the order hash to track all related events from OpenLimitOrder/OpenMarketTrade through ExecuteLimitOrderSuccessful, margin updates, and final CloseTradeSuccessful events.
Q: Can I get real-time funding rate data for AsterDEX pairs?
A: Yes, monitor UpdatePairAccFundingFeePerShare events to track funding rate changes and FundingFeeAddLiquidity events for funding payments.
Q: How do I monitor margin calls and position health?
A: Track UpdateMargin events for margin changes and ExecuteTpSlOrLiq events for automated risk management triggers like stop-loss and take-profit executions.
Q: Is there rate limiting on Bitquery APIs for AsterDEX data?
A: Bitquery offers different plans with varying rate limits. Check the Bitquery pricing page for current API limits and upgrade options.
Data Analysis Questionsβ
Q: How can I calculate trading volumes on AsterDEX?
A: Aggregate OpenMarketTrade and CloseTradeSuccessful events, extracting position sizes and values to calculate daily, weekly, or monthly trading volumes.
Q: Can I track AsterDEX market maker activity?
A: Yes, analyze trading patterns using our trader APIs to identify market makers based on trading frequency, position sizes, and profit patterns.
Q: How do I analyze liquidation patterns and market stress?
A: Monitor liquidation events frequency, amounts, and market conditions during high volatility periods using our historical data APIs.
Getting Started Questionsβ
Q: Do I need special permissions to access AsterDEX data via Bitquery?
A: Create a free Bitquery account to start exploring data. Production applications may require paid plans for higher limits and additional features.
Q: Are there code examples for different programming languages?
A: Yes, all GraphQL queries work with any language that supports HTTP requests. Common implementations include JavaScript, Python, and Go clients.
Q: How fresh is the AsterDEX data provided by Bitquery?
A: Data is indexed in real-time with typical latency of 1-3 seconds from block confirmation on BNB Smart Chain.
Related Resourcesβ
Bitquery Platformβ
Supportβ
For technical support and questions:
- Bitquery Support: Telegram Community
This comprehensive AsterDEX API documentation provides complete coverage of perpetual futures trading data on BNB Smart Chain. From order lifecycle tracking to liquidation monitoring, developers have access to all the tools needed to build sophisticated DeFi trading applications. All API examples include real contract addresses and working GraphQL queries for immediate implementation.