Trading Engine is a deterministic OCaml engine for replaying trading strategies.
It accepts a strict scenario, runs strategy decisions through risk, order management, execution, financing, settlement, and accounting, then writes a hash-bound JSON Lines audit journal. The same reducer supports scheduled intents and supervised external strategy processes.
- Exact fixed-point prices, quantities, money, weights, and FX rates
- Completed-bar, conservative-bar, quote/trade, and order-book execution models
- Market, limit, stop, stop-limit, IOC, GTC, GTD, DAY, and FOK orders
- Instrument and portfolio risk, margin, short locates, recalls, and liquidation
- Multi-currency accounting, financing, settlement, fees, and corporate actions
- Deterministic event IDs, causal references, transcripts, and durable artifact publication
- Strict v1 JSON Schemas for scenarios, journals, strategy messages, diagnostics, and CLI results
The repository uses a local opam switch.
make bootstrap
make checkValidate the canonical scenario:
opam exec -- dune exec trading-engine -- \
--input contracts/v1/fixtures/demo.scenario.json \
--validate-onlyReplay it to a journal:
opam exec -- dune exec trading-engine -- \
--input contracts/v1/fixtures/demo.scenario.json \
--journal demo.journal.jsonlUse --input-format jsonl for bounded-memory stream input. Use --capabilities for the
machine-readable runtime surface and --output-format json for structured success and failure
output.
External strategies exchange one synchronous JSON Lines message at a time:
opam exec -- dune exec trading-engine -- \
--input contracts/strategy/v1/fixtures/external.scenario.json \
--journal external.journal.jsonl \
--strategy-executable ./my-strategy \
--strategy-transcript external.strategy.jsonlThe child process is supervised but not sandboxed. Protocol output belongs on standard output; strategy logs belong on standard error.
- Architecture
- Execution model
- Scenario and journal
- Replay contract v1
- Strategy protocol v1
- Diagnostics
- Persistra integration
- Contributing
- Security
The complete documentation site is published at fallblu.github.io/trading-engine.