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;
33
34// ── Convenience re-exports ──────────────────────────────────────────────────
35
36pub use alert_register::PriceAlertRegister;
37pub use currency::{
38    ConversionError, ConversionLeg, ConversionLegAudit, ConversionPriceSide, ConversionQuoteBook,
39    ConversionResult, ConversionRoute, FxPair, FxPairDirection, QuoteValidationError,
40    RunCurrencyPlan, RunCurrencyPlanError, resolve_conversion_route, resolve_fx_pair,
41};
42pub use engine::{FutureApplyError, FutureApplyResult, TradeEngine};
43pub use error::{CoreError, Result};
44pub use execution::{ExecutionError, ExecutionPricer, ExecutionResult};
45pub use position::Position;
46pub use profile::{
47    ManagementProfile, PositionRef, PositionResolver, ProfileApplicationError,
48    ProfileValidationError, RawSignal, ResolvedEntry, RuleConfigDef, StoplossMode,
49    TargetResolution, TargetSelection, allocate_target_steps, allocate_target_units,
50    resolve_signal, resolve_unprofiled_entry, validate_profile,
51};
52pub use rules::Rule;
53pub use sizing::{LotCapStatus, SizingError, SizingPolicy, SizingResult, compute_size};
54pub use types::{
55    Action, CloseReason, Effect, EffectiveStop, ExecutionConvention, ExecutionFill, ExecutionModel,
56    Fill, FillModel, FillPurpose, FixedPrice, FutureEffect, FutureFill, GroupId, Lots, OrderType,
57    PositionId, PositionRecord, PositionStatus, PreparedPendingFill, PriceQuote, RuleConfig, Side,
58    Signal, SlippageModel, StopOrigin, TargetSpec, TradeId,
59};