Predictu
Trading Engine

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.

Zero-loss guarantee: The execution engine uses a compensating transaction pattern. If any step fails after a player’s balance has been adjusted, the system automatically reverses the operation. No money is ever lost in transit.

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.

1
Validate and assess — The engine confirms the market is open and tradeable, then runs the full risk assessment to ensure the trade falls within all applicable limits.
2
Price the trade — The spread engine calculates a real-time execution price based on current market conditions, operator settings, and any applicable adjustments. Players see a transparent quote before confirming.
3
Debit the player — The cost is debited from the player’s balance through the operator’s wallet system via a server-to-server callback. If the debit fails, the trade is cleanly rejected.
4
Record and update — The trade is recorded, the player’s position is updated (using weighted averaging for repeat purchases), and exposure tracking is refreshed.
Validation first, money second: All checks run before any balance changes. Once validations pass, the wallet is debited. If any internal step fails after the debit, a compensating transaction automatically reverses the balance change.

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.

ScenarioOutcomePlayer Impact
Insufficient fundsTrade rejectedNo balance change
Balance debited, but internal recording failsAutomatic rollbackBalance fully restored
All steps succeedTrade completeBalance debited, position updated
Rollback itself failsCritical alert raisedFlagged for manual reconciliation
Operator confidence: The compensating transaction pattern ensures that the operator’s wallet system is always in sync with Predictu’s internal state. If something goes wrong, the system self-heals or immediately escalates for human review.

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.