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, strict raw signals, canonical trade intent and execution facts, 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//! | [`TradeIntent`] | Source-neutral and strategy-neutral desired economic action |
11//! | [`ExecutionCommandEnvelope`] | Immutable identity envelope for a typed gateway command |
12//! | [`ExecutionReport`] | Venue-neutral economic execution fact |
13//! | [`Position`] | Atomic unit of market exposure with data and rules |
14//! | [`Rule`] | Composable management rule such as stoploss, trailing, or take profit |
15//! | [`Action`] | Concrete engine input vocabulary |
16//! | [`Effect`] | Observable engine output for the caller |
17//! | [`Signal`] | Timestamped action for replay or backtesting |
18//!
19//! # Design principle
20//!
21//! **Effects out, logic pure.**  The engine never performs IO.  It takes inputs
22//! (`Action`, `PriceQuote`) and returns `Vec<Effect>`.  The caller decides how
23//! to handle effects (simulate fills for backtest, send broker orders for live).
24
25pub mod alert_register;
26pub mod canonical;
27pub mod currency;
28pub mod engine;
29pub mod error;
30pub mod execution;
31pub mod execution_events;
32pub mod intent;
33pub mod position;
34pub mod position_manager;
35pub mod profile;
36pub mod rules;
37pub mod sizing;
38pub mod types;
39pub mod validation;
40
41pub use alert_register::PriceAlertRegister;
42pub use canonical::{
43    CanonicalDomainError, DateTimeUtc, DurationMillis, ExecutionCapability, ExecutionCommandId,
44    FillId, IntentCampaignRef, IntentCorrelationId, IntentIdentityNamespace, IntentPositionRef,
45    IntentProducerId, IntentStateRef, OpaquePayloadRef, OpaqueProvenanceRef, OperatingMode,
46    PositiveFraction, PriceDistance, TradeIntentId, VenueOrderRef, VenuePositionRef,
47};
48pub use currency::{
49    ConversionError, ConversionLeg, ConversionLegAudit, ConversionPriceSide, ConversionQuoteBook,
50    ConversionResult, ConversionRoute, FxPair, FxPairDirection, QuoteValidationError,
51    RunCurrencyPlan, RunCurrencyPlanError, resolve_conversion_route, resolve_fx_pair,
52};
53pub use engine::{FutureApplyError, FutureApplyResult, TradeEngine};
54pub use error::{CoreError, Result};
55pub use execution::{ExecutionError, ExecutionPricer, ExecutionResult};
56pub use execution_events::*;
57pub use intent::*;
58pub use position::Position;
59pub use profile::{
60    ManagementProfile, PositionRef, PositionResolver, ProfileApplicationError,
61    ProfileValidationError, RawSignal, ResolvedEntry, RuleConfigDef, StoplossMode,
62    TargetResolution, TargetSelection, allocate_target_steps, allocate_target_units,
63    resolve_signal, resolve_unprofiled_entry, validate_profile,
64};
65pub use rules::Rule;
66pub use sizing::{
67    InstrumentSizingError, LotCapStatus, SizingError, SizingPolicy, SizingResult,
68    compute_instrument_native_loss_per_lot, compute_instrument_size,
69    compute_instrument_size_for_spec, compute_size,
70};
71pub use types::{
72    Action, CloseReason, Effect, EffectiveStop, ExecutionConvention, ExecutionFill, ExecutionModel,
73    Fill, FillModel, FillPurpose, FixedPrice, FutureEffect, FutureFill, GroupId, Lots, OrderType,
74    PositionId, PositionRecord, PositionStatus, PreparedPendingFill, PriceQuote, RuleConfig, Side,
75    Signal, SlippageModel, StopOrigin, TargetSpec, TradeId,
76};
77pub use validation::{RawSignalValidationError, validate_raw_signal, validate_raw_signals};