qs-backtest-server 0.4.1

Transport-neutral retained-job backtest service and CLI
Documentation

quant-system

A Rust workspace for deterministic historical replay and real-time market-data infrastructure.

quant-system is intended for Rust developers and quantitative researchers who want to import historical market data, replay normalized trading actions against explicit instrument specifications, embed trading-domain and backtest libraries, or operate a local CTrader quote service. The workspace is preparing a synchronized 0.4.1 release; publication has not yet been verified.

It is not a complete automated trading platform. It does not currently execute live broker orders, provide restart-safe live strategy orchestration, or implement general cryptocurrency economics.

Choose a workflow

Goal Start here Readiness
Run a deterministic signal backtest Five-minute quick start Available; a synthetic fixture is included
Import, resample, and manage historical data qs-data-preprocess guide Available for supported tick and bar exports; stored bars can be built from stored ticks
Embed the pure trade engine or strict raw-signal contracts quant-system-core Library-only
Compile and evaluate reusable configured strategy behavior qs-strategy Library-only; synchronous core
Prepare broker-neutral execution requests and project reports qs-execution Library-only; no broker adapter or live scheduler
Build an in-process historical strategy simulation qs-backtest Library-only
Replay stored Parquet market data through the engine qs-market-loader Library-only
Search parameters or bounded typed structures and compare explicit split roles qs-research guide Library or service; configured/direct factories, tick or stored-bar input
Run a configured strategy or a search through the running service Backtesting guide Available through strategy_backtest and the typed client
Parse Telegram message exports Signal ingestion guide Compatibility CLI and public adapter library
Operate a CTrader quote service Market-data guide Requires CTrader FIX credentials

Five-minute backtest

Prerequisites

  • Rust 1.88 or newer;
  • Linux shared memory (/dev/shm) for the provided shm:// example;
  • two terminals after the data import finishes.

Import the repository-owned EURUSD fixture:

cargo run -p qs-data-preprocess --bin data-preprocess -- \
  --data-dir target/quickstart/market_data \
  input tick \
  --exchange demo \
  --symbol EURUSD \
  --tz-offset +00:00 \
  examples/backtest-quickstart/EURUSD_ticks.csv

Start the backtest server:

cargo run -p qs-backtest-server --bin backtest_server -- \
  --config examples/backtest-quickstart/backtest-server.toml

In another terminal, submit the matching signal stream:

cargo run -p qs-backtest-server --bin tg_backtest -- \
  --input examples/backtest-quickstart/signals.jsonl \
  --endpoint shm://backtest-quickstart \
  --all-symbols \
  --exchange demo \
  --data-type tick \
  --balance 10000 \
  --account-currency USD \
  --base-lot 0.02 \
  --output target/quickstart/result.json

The fixture opens a EURUSD long position and closes it one minute later. See the getting-started guide for expected results, endpoint alternatives, and troubleshooting.

Architecture at a glance

historical tick/bar export -> qs-data-preprocess -> partitioned Parquet
                                                        |
instrument catalog or symbol compatibility snapshot ----+
                                                        |
external producer or qs-signal-parser -> RawSignal -----+
                                                        v
                                               Backtest Service
                                                        |
                                                        v
                                             deterministic replay
                                                        |
                                                        v
                               result with pinned instrument manifest

RawSignal + current application facts -> qs-execution -> broker-neutral requests/reports

CTrader FIX -> Market Data Service -> snapshots, subscriptions, and alerts

RawSignal remains the compatibility boundary accepted by current replay endpoints. qs-instruments provides source-neutral asset IDs, broker- or exchange-qualified instrument identities, exact decimal grids, effective-dated specifications, and immutable catalog snapshots. CTrader is modeled as a trading platform rather than an instrument listing venue. Source-neutral ingestion libraries, strict JSONL codecs, Telegram adapters, and an authenticated webhook provider edge are also available; see Signal ingestion and Architecture.

Current boundaries

  • Bars are replayed with the spread recorded while the bar formed, or with a configured per-symbol fallback; a bar that supplies neither executes at a zero spread and the run counts how often that happened. Waiting orders fill at a bar's open, stops, targets, and pending orders inside its range fill at their level with each side meeting its adverse extreme first, and the close only marks. The real intrabar order is unknown, so use ticks when the ordering of stop, target, and management events matters.
  • Source-neutral ingestion is available as embeddable library APIs for JSONL, Telegram, and authenticated webhook sources. A webhook 202 Accepted response confirms admission only; it does not confirm normalization, committed-batch publication, or trading activity. Hosted application processing is not restart-safe, and the committed-batch trading bridge is not implemented.
  • qs-strategy provides a reusable synchronous configured strategy core with typed parameter templates, factory-declared material schemas, branch pruning, bounded logical bar sources, derived source-specific input requirements, a named causal numeric catalog with semantic units and strict validity, source-clocked temporal/setup materials, typed bounded expressions, deterministic material and finite-state evaluation, total vacant/pending/open trade-slot facts including open-position time, excursion, and initial risk, calendar materials, generic decisions and notes, and validated command-correlated strict RawSignal values, where an Entry may carry an optional entry class for adapter-owned profile routing. It remains library-only and owns no historical feeds, services, live runtime, persistence, or management-profile composition.
  • qs-backtest provides validated historical strategy contracts and a configured-strategy adapter over the existing FutureQuote scheduler. The adapter performs complete logical-source binding from ticks or stored bars, named-input projection, total trade-slot projection, ordered command provenance and feedback, and profile selection shared with raw-signal replay. Document-driven historical calendar inputs default to one full_day analytical session for an explicitly selected timezone and support explicitly configured named sessions, independent day/week aggregates, actual reveal times, bounded history and strict coverage. Calendar sessions do not automatically restrict Entries, close positions, or change swap, sizing, or risk-reset behavior.
  • Configured historical execution is available through materialized and streaming in-process library APIs. Current conformance verifies neutral no-op, EMA crossover, EMA/ATR lifecycle, declared parameter binding, parameterized custom materials, compositional rolling indicators, pending cancellation, direct-signal economic parity, aligned-EOD materialized/streaming parity, final feedback handling, and strict research-output deserialization.
  • FutureQuote Market Entry sizing can use the actual fill price or an explicit signal Entry price, with fill-price default and fallback. The option changes quantity calculation only; profile resolution, actual fills, P&L, MTM, and actual risk remain execution-price based, while pending order quantity remains fixed at placement.
  • Direct RawSignal replay can map optional exact Entry classes to immutable per-run management-profile snapshots. Profiles can scale the directional signal-stop distance and generate targets from multiples of the final grid-adjusted stop distance; pending levels and quantity remain frozen at placement.
  • qs-execution is a runtime-neutral library boundary that prepares concrete Market, Limit, Stop, full-close, original-entered-size ratio-close, pending-cancel, and stop-modification requests from strict RawSignal intent and caller-supplied current facts. It provides explicit automatic or entry-approval gating, separates accepted submission from committed reports, and projects validated fills, cancellation, modification, rejection, and failure observations into existing configured command feedback. Its local scripted example requires no credentials or network. It owns no broker adapter, connection, scheduler, persistence, P&L, or recovery, and preparation-time quantity is not silently resized when a later fill price differs.
  • qs-backtest replays several configured strategy instances against one account, and qs-risk supplies a synchronous portfolio supervisor that approves or rejects new exposure under position-count limits, correlation-group risk caps, a daily loss halt, and a drawdown kill switch, without ever blocking risk reduction.
  • The backtest service accepts strict RawSignal runs, configured strategy documents, portfolios, and parameter or bounded structural searches as retained jobs. Supported strategy rules, parameters, calendars, and sessions are supplied as documents rather than registered strategy IDs. The optional trusted direct-Rust path remains server-compiled code selected by exact name/revision; its shipped no-op entry is conformance evidence, not a production strategy catalog, and arbitrary code/plugin upload remains prohibited. Compatible checkpoints retain complete runs, and protected selected reruns authorize final access before the service opens the selected market view.
  • Actual live order submission, a live strategy scheduler, restart-safe strategy state, account reconciliation, and broker order adapters are not included. The broker-neutral qs-execution contract does not claim those operational capabilities.
  • Direct signal replay skips and reports unavailable selected instruments by default; --on-unavailable error requests strict failure. Existing aliases connect canonical names to stored datasets without renaming them. Configurable lot-linear BTCUSD/ETHUSD simulation specifications are available through the server's linear_instruments settings; they are operator assumptions, not certified broker contracts. Bare registry crypto rows still have no executable compatibility economics. General spot/inventory, inverse/perpetual, funding, margin, and liquidation models remain unsupported.
  • Shipped backtest clients use provider-neutral retained-job, artifact, synchronous-execution, and discovery capabilities through the typed xrpc facade; RPC method names and provider error mapping remain inside the API provider module.
  • Market-data snapshots and streams use service quote-observation timestamps rather than unavailable CTrader source timestamps. Reconnect invalidates prior-session quote cache entries, source-state events carry transition timestamps, and the combined event stream exposes detected receiver lag or subscription rejection without claiming replay or exactly-once delivery.
  • Internal service TCP endpoints have no built-in authentication or TLS and are restricted to loopback by default.
  • Historical import accepts the documented MetaTrader-style tab-delimited tick and bar formats, not arbitrary CSV layouts.

Documentation

Development

cargo fmt --all -- --check
cargo test --workspace --all-features --all-targets
cargo clippy --workspace --all-features --all-targets -- -D warnings

License

Licensed under either of: