Skip to main content

ccxt_base/
lib.rs

1// CCXT Rust – library root
2//
3// Hand-written files (never overwritten by the transpiler):
4//   src/error.rs          – ExchangeError enum + From impls
5//   src/value.rs          – CCXT Value type (mirrors transpiler output)
6//   src/types.rs          – Domain types: Order, Trade, Ticker, …
7//   src/exchange.rs       – Exchange base: HTTP, crypto, string utilities
8//   src/precise.rs        – Precise decimal arithmetic (mirrors Precise.ts)
9//
10// Generated files (overwritten on each transpile run):
11//   src/exchange_generated.rs  – Exchange.ts base methods
12//   src/exchange_errors.rs     – error constructor functions
13//   src/exchanges/mod.rs       – pub mod declarations for REST exchanges
14//   src/exchanges/*.rs         – individual REST exchange implementations
15//   src/pro/mod.rs             – pub mod declarations for WS exchanges
16//   src/pro/*.rs               – individual WebSocket exchange implementations
17
18// Hand-written code keeps rustc's naming/dead-code allowances (the transpiled
19// surface uses camelCase) and silences the noisy Clippy *style/complexity/perf*
20// groups, but leaves Clippy's `correctness` and `suspicious` groups ENABLED so
21// real defects in the hand-written runtime aren't masked (review #11). Generated
22// files carry their own blanket `clippy::all` allow.
23#![allow(non_snake_case, dead_code, unused_variables, unused_imports)]
24#![allow(clippy::style, clippy::complexity, clippy::perf)]
25// The base surface (`ExchangeBase`/`ExchangeRuntime`/`PredictionBase`) uses
26// native `async fn` in public traits. This is deliberate (review #1): virtual
27// dispatch boxes these futures as `Pin<Box<dyn Future + 'a>>` WITHOUT a `Send`
28// bound, so callers get non-`Send` futures by design — the exchange objects are
29// driven on a single task, not shared across threads. `async fn` in a trait is
30// exactly the right desugaring for that contract, so silence the auto-trait
31// advisory lint rather than hand-rolling `-> impl Future` signatures.
32#![allow(async_fn_in_trait)]
33
34pub mod error;
35pub mod value;
36pub mod types;
37pub mod params;
38pub mod exchange;
39pub mod precise;
40pub mod runtime;
41
42pub mod exchange_errors;
43pub mod exchange_stubs;
44
45// The transpiled base method surface (now the `ExchangeBase` trait, review #1)
46// compiles and typechecks against the hand-written base; the per-exchange REST
47// Cores are the part gated behind `transpiled-base`.
48// The transpiled base `impl Exchange` methods (describe, safe_market,
49// set_markets, …). The hand-written base (exchange.rs / exchange_stubs.rs)
50// calls these unconditionally, so they are non-optional infrastructure — always
51// compiled, independent of the per-exchange `transpiled-base` feature (which
52// gates only the heavy `exchanges`/`prediction` venue modules). This keeps a
53// no-default-features consumer build compiling instead of failing with missing
54// base methods.
55pub mod exchange_generated;
56
57// Prediction-market tier (ts/src/base/PredictionExchange.ts + ts/src/prediction/*).
58// `prediction_exchange` is the hand-written base struct; the `_generated` module
59// holds its transpiled methods (now a `trait PredictionBase: ExchangeBase`). Both
60// gated behind the same `transpiled-base` feature as the rest of the transpiled
61// surface. The prediction tier is a second inheritance layer (Core →
62// PredictionExchange → Exchange) wired with its own static ExchangeBase dispatch
63// (review #1 pointer removal).
64#[cfg(feature = "transpiled-base")]
65pub mod prediction_exchange;
66
67#[cfg(feature = "transpiled-base")]
68pub mod prediction_exchange_generated;
69
70// Transpiled prediction-market venue Cores (ts/src/prediction/*.ts). Kept in
71// their own module so an id that also exists as a regular exchange (hyperliquid)
72// doesn't collide under `exchanges`.
73#[cfg(feature = "transpiled-base")]
74pub mod prediction;
75
76#[cfg(feature = "transpiled-base")]
77pub mod exchanges;
78
79#[cfg(not(feature = "transpiled-base"))]
80pub mod exchanges {
81    // empty until transpiled-base feature is enabled
82}
83
84// The per-exchange typed unified-method wrappers (`Binance`, `Kraken`, … with
85// `fetch_ticker(..) -> Result<Ticker>`) plus the `TypedExchange` /
86// `TypedExchangeExt` traits now live in the sibling `ccxt-typed` crate (import
87// as `ccxt_typed::Binance`). They were split out so the base `ccxt` crate's
88// single `rustc` invocation stays under the CI runner's memory ceiling.
89
90pub mod pro;
91
92// ── top-level re-exports ──────────────────────────────────────────────────────
93
94pub use error::ExchangeError;
95pub use params::{Config, Params};
96pub use value::{Value, get_value, set_value, safe_string, safe_number, safe_integer, safe_bool};
97pub use exchange::Exchange;
98
99/// Convenience Result alias used throughout the crate.
100pub type Result<T> = std::result::Result<T, ExchangeError>;