ccxt_core/
lib.rs

1//! CCXT Core Library
2//!
3//! This is the core library for CCXT Rust implementation, providing fundamental
4//! data structures, error types, and traits for cryptocurrency exchange integration.
5//!
6//! # Features
7//!
8//! - **Type Safety**: Leverages Rust's type system for compile-time guarantees
9//! - **Precision**: Uses `rust_decimal::Decimal` for accurate financial calculations
10//! - **Async/Await**: Built on tokio for high-performance async operations
11//! - **Error Handling**: Comprehensive error types with `thiserror`
12//!
13//! # Example
14//!
15//! ```rust,no_run
16//! use ccxt_core::prelude::*;
17//!
18//! # async fn example() -> Result<()> {
19//! // Create a market
20//! let market = Market::new_spot(
21//!     "btc/usdt".to_string(),
22//!     "BTC/USDT".to_string(),
23//!     "BTC".to_string(),
24//!     "USDT".to_string(),
25//! );
26//!
27//! // Create an order
28//! let order = Order::new(
29//!     "12345".to_string(),
30//!     "BTC/USDT".to_string(),
31//!     OrderType::Limit,
32//!     OrderSide::Buy,
33//!     rust_decimal_macros::dec!(0.1),
34//!     Some(rust_decimal_macros::dec!(50000.0)),
35//!     OrderStatus::Open,
36//! );
37//! # Ok(())
38//! # }
39//! ```
40
41#![warn(missing_docs)]
42#![warn(clippy::all)]
43#![warn(clippy::pedantic)]
44// Allow common patterns that are acceptable in this codebase
45#![allow(clippy::module_name_repetitions)]
46#![allow(clippy::missing_errors_doc)]
47#![allow(clippy::missing_panics_doc)]
48#![allow(clippy::must_use_candidate)]
49#![allow(clippy::doc_markdown)]
50#![allow(clippy::similar_names)]
51#![allow(clippy::uninlined_format_args)]
52#![allow(clippy::should_implement_trait)]
53#![allow(clippy::match_same_arms)]
54#![allow(clippy::redundant_closure_for_method_calls)]
55#![allow(clippy::cast_possible_truncation)]
56#![allow(clippy::cast_sign_loss)]
57#![allow(clippy::cast_possible_wrap)]
58#![allow(clippy::cast_lossless)]
59#![allow(clippy::cast_precision_loss)]
60#![allow(clippy::struct_excessive_bools)]
61#![allow(clippy::too_many_arguments)]
62#![allow(clippy::too_many_lines)]
63#![allow(clippy::wildcard_imports)]
64#![allow(clippy::needless_pass_by_value)]
65#![allow(clippy::unnecessary_wraps)]
66#![allow(clippy::items_after_statements)]
67#![allow(clippy::collapsible_if)]
68#![allow(clippy::if_not_else)]
69#![allow(clippy::if_same_then_else)]
70#![allow(clippy::derivable_impls)]
71#![allow(clippy::from_over_into)]
72#![allow(clippy::map_unwrap_or)]
73#![allow(clippy::unnecessary_map_or)]
74#![allow(clippy::clone_on_copy)]
75#![allow(clippy::explicit_iter_loop)]
76#![allow(clippy::ref_option)]
77#![allow(clippy::ignored_unit_patterns)]
78#![allow(clippy::manual_midpoint)]
79#![allow(clippy::manual_pattern_char_comparison)]
80#![allow(clippy::return_self_not_must_use)]
81#![allow(clippy::format_push_string)]
82#![allow(clippy::redundant_closure)]
83#![allow(clippy::unused_self)]
84#![allow(clippy::match_wildcard_for_single_variants)]
85
86// Re-exports of external dependencies
87pub use rust_decimal;
88pub use serde;
89pub use serde_json;
90
91// Core modules
92pub mod auth;
93pub mod base_exchange;
94pub mod error;
95pub mod exchange;
96pub mod http_client;
97pub mod logging;
98pub mod precision;
99pub mod rate_limiter;
100pub mod retry_strategy;
101pub mod symbol;
102pub mod time;
103pub mod types;
104pub mod ws_client;
105pub mod ws_exchange;
106
107// Test utilities (available in dev-dependencies context)
108#[cfg(any(test, feature = "test-utils", debug_assertions))]
109pub mod test_config;
110
111// Note: Macros from test_config are automatically exported to crate root via #[macro_export]
112// No explicit pub use required here
113
114// Re-exports of core types for convenience
115pub use base_exchange::{BaseExchange, ExchangeConfig, ExchangeConfigBuilder, MarketCache};
116// Re-export unified Exchange trait and capabilities from exchange module
117pub use exchange::{ArcExchange, BoxedExchange, Exchange, ExchangeCapabilities};
118// Re-export WebSocket exchange trait
119pub use error::{
120    ContextExt, Error, ExchangeErrorDetails, NetworkError, OrderError, ParseError, Result,
121};
122pub use ws_exchange::{FullExchange, MessageStream, WsExchange};
123// Re-export deprecated ErrorContext for backwards compatibility
124#[allow(deprecated)]
125pub use error::ErrorContext;
126pub use types::{
127    Amount, Balance, BalanceEntry, Cost, Currency, CurrencyNetwork, Fee, Market, MarketLimits,
128    MarketPrecision, MarketType, MinMax, Ohlcv, Order, OrderBook, OrderBookEntry, OrderBookSide,
129    OrderSide, OrderStatus, OrderType, PrecisionMode, Price, TakerOrMaker, Ticker, TickerParams,
130    TickerParamsBuilder, Timeframe, Trade, TradingLimits,
131};
132// Re-export symbol types for unified symbol format
133pub use symbol::{SymbolError, SymbolFormatter, SymbolParser};
134pub use types::symbol::{ContractType, ExpiryDate, ParsedSymbol, SymbolMarketType};
135pub use ws_client::{Subscription, WsClient, WsConfig, WsConnectionState, WsMessage};
136
137/// Prelude module for convenient imports
138///
139/// Import everything you need with:
140/// ```rust
141/// use ccxt_core::prelude::*;
142/// ```
143pub mod prelude {
144    pub use crate::auth::{
145        DigestFormat, HashAlgorithm, base64_to_base64url, base64url_decode, eddsa_sign, hash,
146        hmac_sign, jwt_sign,
147    };
148    pub use crate::base_exchange::{
149        BaseExchange, ExchangeConfig, ExchangeConfigBuilder, MarketCache,
150    };
151    pub use crate::error::{ContextExt, Error, Result};
152    // Re-export unified Exchange trait and capabilities
153    pub use crate::exchange::{ArcExchange, BoxedExchange, Exchange, ExchangeCapabilities};
154    // Re-export WebSocket exchange trait
155    pub use crate::ws_exchange::{FullExchange, MessageStream, WsExchange};
156    // Re-export deprecated ErrorContext for backwards compatibility
157    #[allow(deprecated)]
158    pub use crate::error::ErrorContext;
159    pub use crate::http_client::{HttpClient, HttpConfig};
160    pub use crate::logging::{LogConfig, LogFormat, LogLevel, init_logging, try_init_logging};
161    pub use crate::precision::{
162        CountingMode, PaddingMode, RoundingMode, decimal_to_precision, number_to_string,
163        precision_from_string,
164    };
165    pub use crate::rate_limiter::{MultiTierRateLimiter, RateLimiter, RateLimiterConfig};
166    pub use crate::retry_strategy::{RetryConfig, RetryStrategy, RetryStrategyType};
167    pub use crate::time::{
168        iso8601, microseconds, milliseconds, parse_date, parse_iso8601, seconds, ymd, ymdhms,
169        yymmdd, yyyymmdd,
170    };
171    pub use crate::types::{
172        Amount, Balance, BalanceEntry, Currency, Fee, Market, MarketLimits, MarketPrecision,
173        MarketType, Ohlcv, Order, OrderBook, OrderBookEntry, OrderBookSide, OrderSide, OrderStatus,
174        OrderType, PrecisionMode, Price, Symbol, TakerOrMaker, Ticker, TickerParams,
175        TickerParamsBuilder, Timeframe, Timestamp, Trade, TradingLimits,
176    };
177    // Symbol types for unified symbol format
178    pub use crate::symbol::{SymbolError, SymbolFormatter, SymbolParser};
179    pub use crate::types::symbol::{ContractType, ExpiryDate, ParsedSymbol, SymbolMarketType};
180    pub use crate::ws_client::{Subscription, WsClient, WsConfig, WsConnectionState, WsMessage};
181    pub use rust_decimal::Decimal;
182    pub use serde::{Deserialize, Serialize};
183}
184
185/// Library version
186pub const VERSION: &str = env!("CARGO_PKG_VERSION");
187
188/// Library name
189pub const NAME: &str = env!("CARGO_PKG_NAME");
190
191#[cfg(test)]
192mod tests {
193    use super::*;
194
195    #[test]
196    fn test_version() {
197        assert!(!VERSION.is_empty());
198        assert_eq!(NAME, "ccxt-core");
199    }
200}