Building VWAP & Order fills engine in ADAMANT Market-making bot
0
0

In ADAMANT Market-making bot, we already support dynamic order book management, spread control, liquidity provisioning, and volume strategies. But without accurate fill analytics, we only see half theĀ picture.
Issue #87 introduces a major architectural upgrade:
Implementation of a VWAP engine and Order Fills engine (PremiumĀ module)
This is not just a feature. It is a foundation for professional-grade execution analytics.
Overview. WhyĀ VWAP?
Most exchange APIs provide fragmented information:
- Orders may be partially filled
- Status updates canĀ lag
- Some exchanges return incomplete execution data
- Restarts can cause loss of internal execution context
If a bot does not persist and verify fill data correctly:
- PnL becomes inaccurate
- Position tracking becomes unreliable
- Risk management logicĀ breaks
- Spread and liquidity adjustments are based on assumptions, notĀ reality
To operate at an institutional level, weĀ use:
- Persistent execution tracking
- Verified fill reconciliation
- Proper VWAP computation
- Inventory-aware analytics
The solution: Dedicated VWAP & FillsĀ engine
Issue #87 proposes introducing a dedicated subsystem responsible for:
1ļøā£ Raw fill event storage (Append-Only)
A dedicated fillsDb:
- Stores raw execution events
- Works in append-only mode
- Persists acrossĀ restarts
- Does not immediately aggregate data
This ensures no execution data is lost or overwritten.
2ļøā£ Exchange verification layer
Each fill event mustĀ be:
- Verified against exchangeĀ API
- Confirmed as fully or partially executed
- Marked as processed only after confirmation
This prevents false-positive fillsĀ when:
- Bot has no connectivity
- Exchange nodes are unavailable
- API responses are incomplete
Execution verification only happenĀ when:
- Network connectivity exists
- Exchange endpoints are reachable
Otherwise, we risk incorrectly marking valid trades asĀ failed.
Core function:
/**
* Verifies a fill order using exchange API.
*
* Policy "always verify if possible":
* - If api.getOrderDetails() is missing -> cannot disprove -> treat as confirmed
* - If status missing or exception -> return undefined (try again later)
* - If API says 'filled' -> confirmed
* - If API says explicitly not filled ('new'|'part_filled'|'cancelled') -> rejected
* - If API says 'unknown' -> keep (cannot disprove) but warn
*
* @param {FillOrder|Object} order Fill order record or Order object
* @param {any} api API instance (spot first/second account, or other compatible trader api)
* @param {string} callerName Log context id (usually module and method which calls) to quickly find related logs
* @returns {Promise}
*/
async function verifyOrderFilled(order, api, callerName)
3ļøā£ Aggregated execution statistics
A second persistent store filledStatsDb accumulates:
- Total base assetĀ bought
- Total base assetĀ sold
- Total quote asset spent/received
- Counters of full/partial/rejected/missing fills
From this, we compute coreĀ metrics.
Core Metrics
Metrics overview:
/**
* Creates a base FillsEngineStatsResult object with zeroed / default values.
*
* @param {string} statsId Format: `${exchange}:${pair}:${purpose}:${startTs}`
* @param {string} pair Trading pair, e.g., `BTC/USDT`
* @param {FilledStatsRecord | undefined | null} stats Epoch stats (optional)
* @returns {FillsEngineStatsResult}
*/
function createBaseEpochStats(statsId, pair, stats) {
return {
statsId,
pair,
updatedAt: stats?.updatedAt || 0,
buy: stats?.buy ? { ...stats.buy } : emptySide(),
sell: stats?.sell ? { ...stats.sell } : emptySide(),
// Calculated later
boughtVwap: 0,
soldVwap: 0,
hasBothSides: false,
vwapSpread: 0,
vwapSpreadPercent: 0,
pnlQuoteCashflow: 0,
inventoryBase: 0,
markPrice: undefined,
pnlQuoteMtm: undefined,
};
}
š VWAP (Volume Weighted AverageĀ Price)
VWAP per side: Buy VWAP and SellĀ VWAP.
Formula:
VWAP = Total Quote Volume / Total Base Volume
This reflects actual execution quality, not just order placement price.
š VWAPĀ spread
Difference between Buy VWAP and SellĀ VWAP.
This shows real realized trading spread, not theoretical spread.
š¦ Inventory Delta
Difference between Total base bought and Total baseĀ sold.
Used for:
- Risk management
- Position exposureĀ tracking
- Rebalancing logic
š° RealizedĀ PnL
Cashflow-based result from executedĀ trades.
And optional Mark-to-market PnL using current marketĀ price.
Why Fills engineĀ matters
Without proper fill analytics, a trading bot operates in partial darkness. It may place orders efficiently, but it has no real understanding of how those orders are actually executed in theĀ market.
A well-designed VWAP engine changes that dynamic completely. It allows the system to measure execution quality with precision, evaluate real performance instead of theoretical placement, and base its logic on confirmed trading activity.
This becomes critically important in environments where the bot is used for token market making, where execution quality directly impacts perceived liquidity and price stability.
Advanced strategies such as liquidity bucket management or dynamic spread maintenance rely heavily on accurate execution data to function correctly. For premium trading modules, execution analytics is not a bonus featureāāāit is a core requirement for professional-grade operation.
Architectural Impact
The new engine is designed as a fully modular component that integrates cleanly into the existing architecture without disrupting the current order placement logic. It operates alongside existing systems rather than replacing them, preserving stability while adding a deeper analytical layer.
At the same time, this architecture lays the groundwork for future expansion. It transforms TradeBot from an order placement tool into a true execution analytics system.
Simplified diagram representation:
Exchange API
ā
ā¼
Order Placement Engine
ā
ā¼
Fills Collector
ā
ā¼
Verification Engine
ā
ā¼
Aggregation Engine
ā
ā¼
VWAP / Inventory / PnL
ā
ā¼
Risk & Strategy Modules
Conclusion
Issue #87 represents a major step toward institutional-grade trading infrastructure inside ADAMANT TradeBot. We significantly improve robustness, transparency, and strategic capability.
This is a foundational upgradeāāānot a cosmetic enhancement.
The feature is available in the Premium mm botĀ version.
If you want to use the ADAMANT Market-making bot for your token, start with the free basicĀ version.
Building VWAP & Order fills engine in ADAMANT Market-making bot was originally published in ADAMANT on Medium, where people are continuing the conversation by highlighting and responding to this story.
0
0
Securely connect the portfolio youāre using to start.