Professional Paper Trading Bot Course
0/37 complete

Module 06 · Paper Execution Engine — Synthetic Fills Only

Synthetic Fill Engine — Complete Flow With Error Handling

35 minfocused lesson0copyable prompts5completion checks3source links
Open lesson + course map

On this lesson

Course outline

A synthetic fill estimates what a fictional action might look like under declared assumptions. It is not evidence that a real order would fill. The engine consumes an approved paper decision and a validated snapshot, applies latency, spread, slippage, capacity, and stale-data rules, then appends either a synthetic fill or an abstention.

Inputs include decision hash, snapshot hash, observed time, simulated decision time, direction, requested paper points, fill-policy version, and configuration hash. Reject missing provenance, expired approval, non-integer or excessive points, invalid quotes, unknown direction, and incomplete runs.

For a simple conservative policy, choose the adverse quote side, add a fixed stress increment, clamp within zero and one, and reject if simulated latency exceeds freshness. Document that the formula is an exercise, not a market model. Use deterministic arithmetic precision and record every intermediate value.

Idempotency uses a unique key derived from decision hash and fill-policy version. Repeating the job returns the original event ID. If the same decision arrives with a new policy, append a new scenario event linked to the prior one; never overwrite.

Error categories include STALE_SNAPSHOT, INVALID_QUOTE, POINT_LIMIT, APPROVAL_EXPIRED, DUPLICATE, and POLICY_ERROR. Unexpected exceptions append a sanitized failure event and stop the run. Partial database writes are wrapped in a transaction, while the append-only audit record preserves attempt history.

Validate conservation rules after every event: starting points equal unused plus committed synthetic points after resolved adjustments; no case exceeds its approved cap; a resolution can apply once per version; and a failed fill changes no portfolio state. Run these invariants during replay and dashboard generation. Any mismatch quarantines the portfolio and blocks fresh status until corrected by an appended event.

Use golden fixtures for arithmetic boundaries: zero and one quotes, smallest point unit, maximum permitted points, rounding edge, and adverse price clamp. Compare exact decimal strings rather than binary floating approximations. A policy upgrade replays the same fixtures and publishes a scenario diff before adoption.

// pakistan_angle

Pakistan Angle

Simulation points are intentionally detached from rupees and personal affordability. This avoids turning a coding exercise into individualized financial guidance. Learners demonstrate validation, idempotency, and audit design—skills transferable to logistics, inventory, and workflow systems.

// hands_on

Hands-On Exercise

Implement the flow on synthetic fixtures. Test valid fill, stale quote, missing ask, point overflow, duplicate delivery, expired approval, and database interruption. Produce a trace showing input hashes, intermediate price assumptions, outcome code, and event hash. Run twice and reconcile counts.

// completion_rubric

Completion Rubric

5 checks — tick as you verify

0/5

// sources

Sources