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 costs;
24pub mod currency;
25pub mod engine;
26pub mod error;
27pub mod execution;
28pub mod position;
29pub mod position_manager;
30pub mod profile;
31pub mod rules;
32pub mod sizing;
33pub mod types;
34pub mod validation;
35
36pub use alert_register::PriceAlertRegister;
37pub use costs::{
38    CommissionModel, CostBasis, CostCharge, CostKind, CostValidationError, InstrumentCosts,
39    SwapAmount, SwapSchedule, rollover_instants,
40};
41pub use currency::{
42    ConversionError, ConversionLeg, ConversionLegAudit, ConversionPriceSide, ConversionQuoteBook,
43    ConversionResult, ConversionRoute, FxPair, FxPairDirection, QuoteValidationError,
44    RunCurrencyPlan, RunCurrencyPlanError, resolve_conversion_route, resolve_fx_pair,
45};
46pub use engine::{FutureApplyError, FutureApplyResult, TradeEngine};
47pub use error::{CoreError, Result};
48pub use execution::{ExecutionError, ExecutionPricer, ExecutionResult};
49pub use position::Position;
50pub use profile::{
51    EntryLevelResolution, EntryResolutionContext, GeneratedTargetResolution, ManagementProfile,
52    PositionRef, PositionResolver, PriceGridSource, ProfileApplicationError,
53    ProfileValidationError, RawSignal, ResolvedEntry, RuleConfigDef, StoplossMode,
54    TargetResolution, TargetResolutionSource, TargetSelection, TargetSource, allocate_target_steps,
55    allocate_target_units, resolve_signal, resolve_unprofiled_entry, validate_profile,
56};
57pub use rules::Rule;
58pub use sizing::{
59    InstrumentSizingError, LotCapStatus, SizingError, SizingPolicy, SizingResult,
60    compute_instrument_native_loss_per_lot, compute_instrument_size,
61    compute_instrument_size_for_spec, compute_instrument_size_for_spec_with_prices, compute_size,
62};
63pub use types::{
64    Action, CloseReason, Effect, EffectiveStop, ExecutionConvention, ExecutionFill, ExecutionModel,
65    Fill, FillModel, FillPurpose, FixedPrice, FutureEffect, FutureFill, GroupId, Lots, OrderType,
66    PositionId, PositionRecord, PositionStatus, PreparedPendingFill, PriceQuote, RuleConfig, Side,
67    Signal, SlippageModel, StopOrigin, TargetSpec, TradeId,
68};
69pub use validation::{
70    RawSignalValidationError, validate_entry_class, validate_raw_signal, validate_raw_signals,
71};