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 deterministic replay and trading applications. It contains the trade engine, strict raw signals, management-policy resolution, position sizing, and currency-conversion logic, but performs no configuration IO, networking, storage, state lookup, 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 with data and rules |
11//! | [`Rule`] | Composable management rule such as stoploss, trailing, or take profit |
12//! | [`Action`] | Concrete engine input vocabulary |
13//! | [`Effect`] | Observable engine output for the caller |
14//! | [`Signal`] | Timestamped action for replay or 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 for replay, accounting, or other application behavior.
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
35pub use alert_register::PriceAlertRegister;
36pub use currency::{
37    ConversionError, ConversionLeg, ConversionLegAudit, ConversionPriceSide, ConversionQuoteBook,
38    ConversionResult, ConversionRoute, FxPair, FxPairDirection, QuoteValidationError,
39    RunCurrencyPlan, RunCurrencyPlanError, resolve_conversion_route, resolve_fx_pair,
40};
41pub use engine::{FutureApplyError, FutureApplyResult, TradeEngine};
42pub use error::{CoreError, Result};
43pub use execution::{ExecutionError, ExecutionPricer, ExecutionResult};
44pub use position::Position;
45pub use profile::{
46    EntryLevelResolution, EntryResolutionContext, GeneratedTargetResolution, ManagementProfile,
47    PositionRef, PositionResolver, PriceGridSource, ProfileApplicationError,
48    ProfileValidationError, RawSignal, ResolvedEntry, RuleConfigDef, StoplossMode,
49    TargetResolution, TargetResolutionSource, TargetSelection, TargetSource, allocate_target_steps,
50    allocate_target_units, resolve_signal, resolve_unprofiled_entry, validate_profile,
51};
52pub use rules::Rule;
53pub use sizing::{
54    InstrumentSizingError, LotCapStatus, SizingError, SizingPolicy, SizingResult,
55    compute_instrument_native_loss_per_lot, compute_instrument_size,
56    compute_instrument_size_for_spec, compute_instrument_size_for_spec_with_prices, compute_size,
57};
58pub use types::{
59    Action, CloseReason, Effect, EffectiveStop, ExecutionConvention, ExecutionFill, ExecutionModel,
60    Fill, FillModel, FillPurpose, FixedPrice, FutureEffect, FutureFill, GroupId, Lots, OrderType,
61    PositionId, PositionRecord, PositionStatus, PreparedPendingFill, PriceQuote, RuleConfig, Side,
62    Signal, SlippageModel, StopOrigin, TargetSpec, TradeId,
63};
64pub use validation::{
65    RawSignalValidationError, validate_entry_class, validate_raw_signal, validate_raw_signals,
66};