Skip to main content

qs_core/
lib.rs

1//! `quant-system-core` package (`qs_core` library) - Core trade engine for the quant-system workspace.
2//!
3//! This crate provides the **synchronous, side-effect-free** trading domain used by backtesting and future live integrations. It contains the trade engine, normalized signal intent, management-policy resolution, position sizing, and currency-conversion logic, but performs no configuration IO, networking, storage, or broker calls.
4//!
5//! # Key types
6//!
7//! | Type | Purpose |
8//! |------|---------|
9//! | [`TradeEngine`] | Main entry point — processes actions and price updates |
10//! | [`Position`] | Atomic unit of market exposure (data + rules) |
11//! | [`Rule`] | Composable management rule (stoploss, trailing, TP, …) |
12//! | [`Action`] | Input vocabulary — what a strategy can request |
13//! | [`Effect`] | Output vocabulary — observable side-effects for the caller |
14//! | [`Signal`] | Timestamped action for replay / backtesting |
15//!
16//! # Design principle
17//!
18//! **Effects out, logic pure.**  The engine never performs IO.  It takes inputs
19//! (`Action`, `PriceQuote`) and returns `Vec<Effect>`.  The caller decides how
20//! to handle effects (simulate fills for backtest, send broker orders for live).
21
22pub mod alert_register;
23pub mod currency;
24pub mod engine;
25pub mod error;
26pub mod execution;
27pub mod position;
28pub mod position_manager;
29pub mod profile;
30pub mod rules;
31pub mod sizing;
32pub mod types;
33pub mod validation;
34
35// ── Convenience re-exports ──────────────────────────────────────────────────
36
37pub use alert_register::PriceAlertRegister;
38pub use currency::{
39    ConversionError, ConversionLeg, ConversionLegAudit, ConversionPriceSide, ConversionQuoteBook,
40    ConversionResult, ConversionRoute, FxPair, FxPairDirection, QuoteValidationError,
41    RunCurrencyPlan, RunCurrencyPlanError, resolve_conversion_route, resolve_fx_pair,
42};
43pub use engine::{FutureApplyError, FutureApplyResult, TradeEngine};
44pub use error::{CoreError, Result};
45pub use execution::{ExecutionError, ExecutionPricer, ExecutionResult};
46pub use position::Position;
47pub use profile::{
48    ManagementProfile, PositionRef, PositionResolver, ProfileApplicationError,
49    ProfileValidationError, RawSignal, ResolvedEntry, RuleConfigDef, StoplossMode,
50    TargetResolution, TargetSelection, allocate_target_steps, allocate_target_units,
51    resolve_signal, resolve_unprofiled_entry, validate_profile,
52};
53pub use rules::Rule;
54pub use sizing::{LotCapStatus, SizingError, SizingPolicy, SizingResult, compute_size};
55pub use types::{
56    Action, CloseReason, Effect, EffectiveStop, ExecutionConvention, ExecutionFill, ExecutionModel,
57    Fill, FillModel, FillPurpose, FixedPrice, FutureEffect, FutureFill, GroupId, Lots, OrderType,
58    PositionId, PositionRecord, PositionStatus, PreparedPendingFill, PriceQuote, RuleConfig, Side,
59    Signal, SlippageModel, StopOrigin, TargetSpec, TradeId,
60};
61pub use validation::{RawSignalValidationError, validate_raw_signal, validate_raw_signals};