bat_markets/lib.rs
1//! Public facade crate for `bat-markets`.
2//!
3//! `bat-markets` is a futures-first, headless exchange engine for Binance USD-M,
4//! Bybit USDT, and MEXC USDT-M linear futures.
5//!
6//! The root API is grouped by responsibility:
7//!
8//! - `fetch_*` methods read REST snapshots.
9//! - `watch_*` methods return typed websocket watchers.
10//! - `create_*`, `edit_*`, `cancel_*`, `close_*`, and `set_*` methods send commands.
11//! - [`BatMarkets::advanced`] exposes raw ingestion, diagnostics, reconcile, and native adapters.
12//!
13//! # API map
14//!
15//! | Family | Primary methods | Responsibility |
16//! | --- | --- | --- |
17//! | Metadata/cache | [`BatMarkets::markets`], [`BatMarkets::load_markets`] | local bundled metadata and live venue metadata refresh |
18//! | Public REST | `fetch_ticker`, `fetch_tickers`, `fetch_order_book`, `fetch_ohlcv`, `fetch_trades`, `fetch_mark_price`, `fetch_funding_rate`, `fetch_open_interest`, `fetch_liquidations` | unauthenticated market snapshots |
19//! | Private REST | `fetch_balance`, `fetch_positions`, `fetch_open_orders`, `fetch_order`, `fetch_my_trades` | authenticated account, position, order, and execution snapshots |
20//! | Public WS | `watch_ticker`, `watch_tickers`, `watch_trades`, `watch_trades_for_symbols`, `watch_order_book`, `watch_ohlcv`, `watch_ohlcv_for_symbols`, `watch_mark_price`, `watch_funding_rate`, `watch_open_interest`, `watch_liquidations`, `watch_status` | typed live updates over shared websocket hubs |
21//! | Private WS | `watch_balance`, `watch_orders`, `watch_my_trades`, `watch_positions` | authenticated account-stream updates over one shared private hub |
22//! | Commands | `create_order`, `create_orders`, `edit_order`, `edit_orders`, `cancel_order`, `cancel_orders`, `cancel_all_orders`, `close_position`, `validate_order`, `set_leverage`, `set_margin_mode`, `set_position_mode` | write operations with lifecycle-aware [`PendingCommandHandle`] results |
23//! | Advanced | [`BatMarkets::advanced`] | raw lane ingest, subscriptions, command classification, reconcile, diagnostics, and native access |
24//!
25//! # Safety model
26//!
27//! Public market reads do not require secrets. Live authenticated flows read
28//! credentials from explicit config or venue-specific environment variables in
29//! live mode. Command outcomes that cannot be proven are surfaced as
30//! `UnknownExecution` and are resolved through reconciliation evidence instead
31//! of being silently treated as success or failure.
32//!
33//! # Examples
34//!
35//! Static/offline client:
36//!
37//! ```
38//! use bat_markets::{BatMarkets, errors::Result, types::{Product, Venue}};
39//!
40//! fn main() -> Result<()> {
41//! let client = BatMarkets::builder()
42//! .venue(Venue::Binance)
43//! .product(Product::LinearUsdt)
44//! .build()?;
45//!
46//! assert!(!client.markets().is_empty());
47//! Ok(())
48//! }
49//! ```
50//!
51//! Live client:
52//!
53//! ```no_run
54//! use bat_markets::{BatMarkets, errors::Result, types::{Product, Venue}};
55//!
56//! # #[tokio::main]
57//! # async fn main() -> Result<()> {
58//! let client = BatMarkets::builder()
59//! .venue(Venue::Bybit)
60//! .product(Product::LinearUsdt)
61//! .build_live()
62//! .await?;
63//!
64//! println!("{} instruments", client.markets().len());
65//! # Ok(())
66//! # }
67//! ```
68
69#![deny(missing_docs)]
70
71#[cfg(not(any(feature = "binance", feature = "bybit", feature = "mexc")))]
72compile_error!(
73 "bat-markets requires at least one venue feature: enable `binance`, `bybit`, `mexc`, or default features."
74);
75
76/// Low-level advanced facade for custom transports and diagnostics.
77#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
78pub mod advanced;
79/// Re-exported capability contracts from `bat-markets-core`.
80#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
81pub mod capabilities;
82/// Engine facade and builder.
83#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
84pub mod client;
85/// Re-exported runtime config contracts from `bat-markets-core`.
86#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
87pub mod config;
88#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
89mod diagnostics;
90#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
91mod entry;
92/// Re-exported error contracts from `bat-markets-core`.
93#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
94pub mod errors;
95#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
96mod facade;
97#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
98mod health;
99#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
100mod native;
101#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
102mod runtime;
103#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
104mod stream;
105#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
106mod subscriptions;
107#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
108mod transport;
109/// Re-exported domain and request/response types from `bat-markets-core`.
110#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
111pub mod types;
112
113#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
114pub use advanced::AdvancedClient;
115#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
116pub use client::{BatMarkets, BatMarketsBuilder};
117#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
118pub use diagnostics::{LockDiagnosticsSnapshot, RuntimeDiagnosticsSnapshot};
119#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
120pub use entry::PendingCommandHandle;
121#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
122pub use health::StatusWatch;
123#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
124pub use native::NativeClient;
125#[cfg(any(feature = "binance", feature = "bybit", feature = "mexc"))]
126pub use stream::{
127 BalancesWatch, ExecutionsWatch, FundingRateWatch, LiquidationWatch, MarkPriceWatch, OhlcvWatch,
128 OpenInterestWatch, OrderBookWatch, OrdersWatch, PositionsWatch, TickerWatch, TradesWatch,
129};