Skip to main content

opendeviationbar_core/
lib.rs

1//! Core open deviation bar processing algorithms
2//!
3//! Non-lookahead bias open deviation bar construction with temporal integrity guarantees.
4//!
5//! ## Features
6//!
7//! - Non-lookahead bias: Thresholds computed only from bar open price
8//! - Breach inclusion: Breaching trade included in closing bar
9//! - Fixed thresholds: Never recalculated during bar lifetime
10//! - Temporal integrity: Guaranteed correct historical simulation
11//! - **Cross-file checkpoints**: Seamless continuation across file boundaries (v6.1.0+)
12//! - **Arrow export**: Zero-copy streaming to Python via Arrow RecordBatch (v8.0.0+)
13
14// Issue #147 (Phase 9): Use Mimalloc for high-performance memory allocation
15// Expected 2-5x speedup on multithreaded workloads (entropy cache, trade accumulation)
16#[cfg(not(target_env = "msvc"))]
17#[global_allocator]
18static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
19
20pub mod checkpoint;
21pub mod entropy_cache_global; // Issue #145: Multi-symbol entropy cache sharing (Phase 1)
22pub mod errors;
23pub mod export_processor; // Export-oriented processor (extracted Phase 2d)
24pub mod fixed_point;
25pub mod interbar; // Issue #59: Inter-bar microstructure features (lookback window BEFORE bar)
26pub mod interbar_cache; // Issue #96 Task #144 Phase 4: Inter-bar feature result caching for streaming
27pub mod interbar_math; // Issue #59: Inter-bar math helpers (extracted Phase 2e) - public for profiling/benchmarking
28pub mod interbar_types; // Issue #59: Inter-bar type definitions (extracted Phase 2b)
29pub mod intrabar; // Issue #59: Intra-bar features (trades WITHIN bar)
30pub mod processor;
31pub mod timestamp;
32pub mod trade; // Trade/DataSource types (extracted Phase 2c)
33pub mod types;
34
35// Arrow export (only available with arrow feature)
36#[cfg(feature = "arrow")]
37pub mod arrow_export;
38
39// Test utilities (only available in test builds or with test-utils feature)
40#[cfg(any(test, feature = "test-utils"))]
41pub mod test_utils;
42
43#[cfg(any(test, feature = "test-utils"))]
44pub mod test_data_loader;
45
46/// Feature manifest TOML, embedded at compile time.
47/// SSoT for all microstructure feature metadata (Issue #95).
48/// Exposed to Python via PyO3 `get_feature_manifest_raw()`.
49pub const FEATURE_MANIFEST_TOML: &str = include_str!("../data/feature_manifest.toml");
50
51// Re-export commonly used types
52pub use checkpoint::{AnomalySummary, Checkpoint, CheckpointError, PositionVerification};
53pub use entropy_cache_global::{
54    create_local_entropy_cache, get_global_entropy_cache, GLOBAL_ENTROPY_CACHE_CAPACITY,
55}; // Issue #145: Global entropy cache API
56pub use fixed_point::FixedPoint;
57pub use interbar::{InterBarConfig, InterBarFeatures, LookbackMode, TradeHistory, TradeSnapshot};
58pub use interbar_cache::{
59    InterBarCacheKey, InterBarFeatureCache, INTERBAR_FEATURE_CACHE_CAPACITY,
60}; // Issue #96 Task #144 Phase 4: Inter-bar feature result cache API
61pub use interbar_math::EntropyCache; // Issue #145 Phase 2: Export for external cache parameters
62pub use intrabar::{IntraBarConfig, IntraBarFeatures, compute_intra_bar_features};
63pub use processor::{ExportOpenDeviationBarProcessor, ProcessingError, OpenDeviationBarProcessor};
64pub use timestamp::{
65    create_aggtrade_with_normalized_timestamp, normalize_timestamp, validate_timestamp,
66};
67pub use types::{AggTrade, DataSource, OpenDeviationBar};
68
69// Arrow export re-exports (only available with arrow feature)
70#[cfg(feature = "arrow")]
71pub use arrow_export::{
72    ArrowImportError,
73    aggtrade_schema,
74    aggtrades_to_record_batch,
75    opendeviationbar_schema,
76    opendeviationbar_vec_to_record_batch,
77    // Issue #88: Arrow-native input path
78    record_batch_to_aggtrades,
79};