Non-critical path: if QuestDB is unavailable, metrics buffer locally (up to 10,000 entries) and flush when connection is restored. Feature-gated under `questdb` feature. 6 tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
122 lines
4.0 KiB
Rust
122 lines
4.0 KiB
Rust
//! Common utilities and shared types for Foxhunt HFT Trading System
|
|
//!
|
|
//! This crate contains shared utilities that are used across multiple services
|
|
//! in the Foxhunt HFT trading system, eliminating code duplication and providing
|
|
//! a consistent interface for common operations.
|
|
//!
|
|
//! # Modules
|
|
//!
|
|
//! - [`database`] - Database connection utilities and configurations
|
|
//! - [`error`] - Common error types and utilities
|
|
//! - [`traits`] - Shared traits used across services
|
|
//! - [`constants`] - Shared constants and configuration values
|
|
//! - [`types`] - Common data types
|
|
|
|
#![allow(missing_docs)] // Internal implementation details
|
|
#![warn(missing_debug_implementations)]
|
|
#![allow(clippy::float_arithmetic)] // Financial calculations require float arithmetic
|
|
#![warn(rust_2018_idioms)]
|
|
#![deny(
|
|
clippy::unwrap_used,
|
|
clippy::expect_used,
|
|
clippy::panic,
|
|
clippy::unimplemented,
|
|
clippy::unreachable
|
|
)]
|
|
|
|
pub mod constants;
|
|
pub mod database;
|
|
pub mod error;
|
|
pub mod model_types;
|
|
pub mod features; // Wave D: Shared feature extraction (225 features)
|
|
pub mod market_data;
|
|
pub mod metrics; // Wave 5: Prometheus metrics infrastructure (W5-3)
|
|
pub mod ml_strategy;
|
|
pub mod observability; // Wave 5: Structured logging and observability
|
|
pub mod regime_persistence;
|
|
pub mod resilience; // Wave 5: Circuit breaker and retry patterns
|
|
pub mod thresholds;
|
|
pub mod tls;
|
|
pub mod traits;
|
|
pub mod types;
|
|
#[cfg(feature = "questdb")]
|
|
pub mod questdb;
|
|
|
|
// Re-export database types for external use
|
|
pub use database::{DatabaseConfig, DatabaseError, DatabasePool};
|
|
|
|
// Re-export commonly used types at crate root for convenience
|
|
pub use types::{
|
|
AccountId, Aggregate, BarEvent, BrokerType, CommonTypeError, ConfigVersion, ConnectionEvent,
|
|
ConnectionInfo, ConnectionStatus, Currency, DataType, ErrorEvent, Execution, GenericTimestamp,
|
|
HftTimestamp, Level2Update, MarketDataEvent, MarketRegime, MarketStatus, Money, Order,
|
|
OrderBookEvent, OrderEvent, OrderEventType, OrderId, OrderSide, OrderStatus, OrderType,
|
|
Position, PositionMap, Price, PriceLevel, Quantity, QuoteEvent, RequestId, ResourceLimits,
|
|
ServiceId, ServiceStatus, Subscription, Symbol, TimeInForce, Timestamp, TradeEvent, TradeId,
|
|
Volume,
|
|
};
|
|
|
|
// Re-export error types
|
|
pub use error::{CommonError, CommonResult};
|
|
|
|
// Re-export model types
|
|
pub use model_types::ModelType;
|
|
|
|
// Re-export common traits for convenience
|
|
pub use traits::{
|
|
CircuitBreaker, Configurable, DetailedHealth, GracefulShutdown, HealthCheck, HealthStatus,
|
|
Metrics, RateLimitStatus, RateLimited, Reloadable, Service,
|
|
};
|
|
|
|
// Market data types: use common::market_data::{MarketDataEvent, TradeEvent, QuoteEvent, BarEvent, etc.}
|
|
// (Not re-exported at crate root to avoid name collisions with types:: re-exports)
|
|
pub mod trading;
|
|
|
|
// Re-export shared ML strategy types
|
|
pub use ml_strategy::{
|
|
MLFeatureExtractor, MLModelAdapter, MLModelPerformance, MLPrediction,
|
|
SharedMLStrategy, SimpleDQNAdapter,
|
|
};
|
|
|
|
// Re-export regime persistence manager
|
|
pub use regime_persistence::RegimePersistenceManager;
|
|
|
|
// Re-export feature extraction types and functions
|
|
pub use features::{
|
|
BarData,
|
|
// Technical indicators (streaming + batch)
|
|
RSI, EMA, MACD, BollingerBands, ATR, ADX,
|
|
rsi_batch, ema_batch, macd_batch, bollinger_batch, atr_batch, adx_batch,
|
|
};
|
|
|
|
// Re-export resilience patterns (Wave 5: Error handling and fault tolerance)
|
|
pub use resilience::{
|
|
BoundedExecutor,
|
|
BoundedExecutorError,
|
|
CircuitBreakerConfig,
|
|
CircuitBreakerState,
|
|
retry_with_backoff,
|
|
RetryConfig,
|
|
RetryContext,
|
|
RetryError,
|
|
};
|
|
|
|
// Re-export observability infrastructure (Wave 5: Structured logging and observability)
|
|
pub use crate::observability::{
|
|
init_observability,
|
|
CorrelationId,
|
|
CorrelationIdExt,
|
|
JsonLoggerConfig,
|
|
LogLevel,
|
|
TracingConfig,
|
|
CORRELATION_ID_HEADER,
|
|
};
|
|
|
|
// Test utilities module (available for all tests)
|
|
#[cfg(test)]
|
|
pub mod test_utils;
|
|
|
|
// Test module for database features
|
|
#[cfg(all(test, feature = "database"))]
|
|
mod sqlx_test;
|