README.md is the user-facing contract. This note is a compact map of the implementation.
engine/
data_loader.py validated UTC OHLCV loading and conservative resampling
broker.py one-position, next-open order simulation and trade ledger
reporter.py report, equity curve, and JSON export
core.py event loop and dynamic strategy loading
strategies/base.py optional base class for Strategy modules
scripts/test_strategy.py runnable example strategy
examples/ committed small CSV for the README quick start
tests/ standard-library regression suite
main.py CLI entry point
For each source or resampled candle, the engine:
- Marks the broker to the candle open, settles any funding due since the previous open on the position held (when
funding_ratesis configured), and fills any order queued by the prior candle. - Marks the broker to the candle close.
- Calls
Strategy.update(candle), which may queue one order for the next open. - Records marked-to-market equity at the close.
The engine cancels an order queued on the final candle, because there is no next open. It then liquidates an existing position at that final close so reports contain realized final equity.
The broker intentionally supports a single net position and market orders only. It validates positive finite prices, quantities, balances, and leverage; slippage and commission are non-negative decimal rates. Position P&L is net of both entry and exit fees.
The broker checks entry affordability and supports optional equity-based sizing and maintenance liquidation on observed opens and closes. The README defines the timing and accounting rules. Each repeat run starts with a fresh broker, strategy instance and reporter.
python -m pip install -e .
python -m unittest discover -vKeep changes small and add a regression test whenever a simulation rule changes. The test suite is deliberately based on unittest, so no development-only test dependency is required.