trades / Trading-system architecture / 2026
Separating trading decisions from authority to execute them.
The Python engine records risk-adjusted order plans, while a separate FastAPI control path checks whether live execution is authorized and ready.
- ROLE
- Software engineering
- STATE OF THE BUILD
- In progress
- RECORD UPDATED
THE WORK
The project.
trades makes a strategy's proposed action available for inspection before execution. The decision service evaluates the market snapshot, applies risk rules and records explicit order intents. Paper, shadow and live runtimes can then handle execution separately, while the saved cycle preserves what the strategy and risk layer decided.
Live activation has its own authorization path. Administrative access, approval, readiness and control state are checked before a session can start. Execution records also feed back into later planning: recent rejection clusters and longer latency and slippage history determine a saved degradation mode, which can limit new order intents until the checks recover.
IMPLEMENTATION
Design choices.
- Order intents are data before they become execution work. Logging the complete decision cycle preserves the strategy and risk result even if execution later fails or produces a different outcome. A recorded intent is still not proof of an executed order.
- Live arming sits outside strategy evaluation. The API and control service check authority and operational readiness, keeping a valid trading proposal separate from permission to act on it.
- Recent rejection and cancellation clusters use a shorter lookback than latency and slippage. The recorded correction lets an old failure burst age out while retaining the wider quality history. When the checks pass, the evaluator clears the active degradation state that later planning reads.
- apply_actions=false disables operational actions, not persistence. Evaluation still saves policy state and incident history, making its result available to later plans. An action-disabled call therefore remains a write and must not be used as a read-only diagnostic.
HOW IT FITS TOGETHER
Architecture.
- DecisionService passes the strategy result through risk_engine.apply and execution_planner.build, then appends a DecisionCycleResult containing the order intents. The recorded plan remains distinct from the exchange or runtime result, so later inspection can compare the proposal with what happened during execution.
- Paper, shadow and live runtimes consume those intents through separate execution modes. The strategy can propose a trade without owning the permission to start a live session; activation comes through the control path.
- The FastAPI live-arm route resolves authentication and role, checks promotion readiness and approval, then calls the control service. Stop, maintenance and readiness conditions can refuse activation before session creation. These checks govern the inspected arming path, not every possible application route.
- Execution events feed a longer quality summary for latency and slippage and a shorter summary for rejection or cancellation clusters. The evaluator combines those checks, saves the current degradation mode and updates incident history. Later order adaptation reads that saved mode when adjusting new intents.
- SQLAlchemy repositories persist records in PostgreSQL, with Alembic managing schema changes. Policy state, incidents and optional operational actions are updated through separate calls, so testing recovery has to follow all of them rather than only the evaluator's return value.
Explore the architecture map9 components · 12 connections
Decision planning and live-control authority
Execution records feed policy adaptation, while an administrative control path separately authorizes live runtime state.
Decision pipeline
Execution and evidence
Control and policy
Scroll or drag the background to move. Use the zoom buttons to resize.Arrow keys move between components. Enter selects.
Choose a component to explore
Select a numbered component on the map or use the component menu. Its details and connections will appear here.
No component selected.
All connections (12)
- 01 · Strategy evaluation → 02 · Risk processingDecision · Direct call
- 02 · Risk processing → 03 · Order-intent plannerRisk-adjusted result · Direct call
- 03 · Order-intent planner → 04 · Paper / shadow / live runtimesOrder intents · Direct call
- 03 · Order-intent planner → 05 · Decision and execution recordsDecision cycle · Direct call
- 04 · Paper / shadow / live runtimes → 06 · Exchange executionEnabled live orders · Async task
- 06 · Exchange execution → 05 · Decision and execution recordsExecution evidence · Async task
- 04 · Paper / shadow / live runtimes → 05 · Decision and execution recordsRuntime records · Direct call
- 05 · Decision and execution records → 09 · Degradation evaluatorWindowed summaries · Direct call
- 09 · Degradation evaluator → 03 · Order-intent plannerAdapt planning · Response / return
- 07 · Administrative API boundary → 08 · Readiness and control gateAuthorized arm request · Direct call
- 08 · Readiness and control gate → 04 · Paper / shadow / live runtimesStart permitted session · Direct call
- 09 · Degradation evaluator → 08 · Readiness and control gateOptional control actions · Direct call
MADE WITH
Python · FastAPI · Pydantic · PostgreSQL · SQLAlchemy · Alembic · HTTPX · WebSockets · Prometheus
ACCESS & INPUT
Security controls.
- The inspected live-arm route checks configured authentication and administrative authority, followed by approval, readiness and control state. A strategy result that passes risk checks does not by itself authorize live activation.
- This account covers the reviewed route-to-service path. It does not establish a full API security audit, the state of a current deployment or the safety of live trading.
CHECKS & RESULTS
What was checked.
A source review shows what the code does. It is not a fresh test of the running app.
Code and development records reviewedReviewed
The code, tests and available development records were checked. Reported test results keep their original scope. No fresh app or live deployment check was run for this write-up.
- Scope of this check
- Code review, not a fresh run of the app
NEXT
Still to work through.
The source shows how decision planning, live authorization and execution-quality recovery connect; it doesn't establish profitability or current live behavior. The regression definitions still need a fresh run against this checkout. Recovery should also be replayed across incident state, policy state and control actions, because those changes happen through separate calls.