trading-bot
0/37 complete

Module 6: Paper Execution Engine — Synthetic Fills Only · 35 min

Synthetic Fill Engine — Complete Flow With Error Handling

// sabak

Turn this lesson into one checked practice output

By the end, you should be able to explain the core idea behind “Synthetic Fill Engine — Complete Flow With Error Handling” in your own words, apply it to one small real or sample task, and identify what still needs human review.

  1. 1

    Learn

    Read the 35-minute lesson without copying an output blindly.

  2. 2

    Try

    Use a small, non-sensitive example that you can inspect line by line.

  3. 3

    Review

    Check facts, fit, and risk; save one improvement note for next time.

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

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 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

  • Every fill traces to approved decision and snapshot hashes.
  • Assumptions and intermediate values are stored explicitly.
  • Duplicate processing is database-idempotent.
  • All invalid states abstain with typed errors.
  • Output is labelled synthetic and has no currency value.

Sources

Key takeaway: A synthetic fill is an auditable scenario calculation whose failures are as important as its outputs.

Self-check

Before you mark Lesson 6.3 complete

  • Can I explain “Synthetic Fill Engine — Complete Flow With Error Handling” without reading the lesson back word for word?
  • Did I complete the lesson’s practice step on a real or clearly labelled sample task?
  • Did I check the result for invented facts, private data, unsafe actions, and mismatch with the brief?