Trade Execution Engine
The Trade Execution Engine is the core of every buy and sell operation on the Predictu platform. It orchestrates pricing, risk assessment, balance management, and position tracking through a multi-step atomic pipeline — ensuring that every trade either completes fully or leaves no trace.
Buying Shares
When a player buys shares in a prediction market outcome, the engine runs a multi-step pipeline that validates, prices, debits, and records the trade atomically.
Selling Shares
Selling follows a similar pipeline with key differences: the engine looks up the player’s existing position, calculates proceeds based on the current bid price, tracks realized profit or loss, and credits the player’s balance.
Players can always exit their positions — even on paused or disabled markets. This ensures players are never locked into a position they want to close. Partial sells are fully supported, reducing the position without closing it entirely.
Real-Time Quotes
Before committing to a trade, players can request a non-binding price preview. The quote engine applies the same pricing logic as a live trade — including spreads, market conditions, and any applicable adjustments — so the quoted price accurately reflects what the player will pay or receive.
Quotes include the execution price, number of shares, total cost, potential payout, and the effective spread. This transparency helps players make informed decisions before confirming a trade.
Atomic Execution
The execution engine is built around the principle that a player’s balance must always be consistent with their positions. Since balance operations are handled by the operator’s external wallet system, the engine uses compensating transactions to maintain this guarantee.
| Scenario | Outcome | Player Impact |
|---|---|---|
| Insufficient funds | Trade rejected | No balance change |
| Balance debited, but internal recording fails | Automatic rollback | Balance fully restored |
| All steps succeed | Trade complete | Balance debited, position updated |
| Rollback itself fails | Critical alert raised | Flagged for manual reconciliation |
High-Throughput Concurrency
The engine supports concurrent trades from the same player across multiple sessions. Optimistic concurrency control detects conflicts when two trades attempt to modify the same position simultaneously. If a conflict is detected, the system automatically retries with fresh data before falling back to a safe rollback.
Position Management
Every player’s holdings are tracked as aggregate positions per market and outcome. When a player buys additional shares in a market they already hold, the engine merges the new purchase using a weighted average price — maintaining an accurate cost basis across multiple trades. Selling reduces or closes the position, with realized profit and loss tracked at every step.
Exposure Tracking
The engine continuously tracks aggregate exposure for every market. This data feeds directly into the risk management system, enabling real-time enforcement of per-market, per-category, and global exposure caps. As trades execute, exposure figures update instantly to reflect the current risk profile.
