Expand description
Public facade crate for bat-markets.
bat-markets is a futures-first, headless exchange engine for Binance USD-M,
Bybit USDT, and MEXC USDT-M linear futures.
The root API is grouped by responsibility:
fetch_*methods read REST snapshots.watch_*methods return typed websocket watchers.create_*,edit_*,cancel_*,close_*, andset_*methods send commands.BatMarkets::advancedexposes raw ingestion, diagnostics, reconcile, and native adapters.
§API map
| Family | Primary methods | Responsibility |
|---|---|---|
| Metadata/cache | BatMarkets::markets, BatMarkets::load_markets | local bundled metadata and live venue metadata refresh |
| 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 |
| Private REST | fetch_balance, fetch_positions, fetch_open_orders, fetch_order, fetch_my_trades | authenticated account, position, order, and execution snapshots |
| 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 |
| Private WS | watch_balance, watch_orders, watch_my_trades, watch_positions | authenticated account-stream updates over one shared private hub |
| 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 |
| Advanced | BatMarkets::advanced | raw lane ingest, subscriptions, command classification, reconcile, diagnostics, and native access |
§Safety model
Public market reads do not require secrets. Live authenticated flows read
credentials from explicit config or venue-specific environment variables in
live mode. Command outcomes that cannot be proven are surfaced as
UnknownExecution and are resolved through reconciliation evidence instead
of being silently treated as success or failure.
§Examples
Static/offline client:
use bat_markets::{BatMarkets, errors::Result, types::{Product, Venue}};
fn main() -> Result<()> {
let client = BatMarkets::builder()
.venue(Venue::Binance)
.product(Product::LinearUsdt)
.build()?;
assert!(!client.markets().is_empty());
Ok(())
}Live client:
use bat_markets::{BatMarkets, errors::Result, types::{Product, Venue}};
let client = BatMarkets::builder()
.venue(Venue::Bybit)
.product(Product::LinearUsdt)
.build_live()
.await?;
println!("{} instruments", client.markets().len());Re-exports§
pub use advanced::AdvancedClient;pub use client::BatMarkets;pub use client::BatMarketsBuilder;
Modules§
- advanced
- Low-level advanced facade for custom transports and diagnostics.
- capabilities
- Re-exported capability contracts from
bat-markets-core. - client
- Engine facade and builder.
- config
- Re-exported runtime config contracts from
bat-markets-core. - errors
- Re-exported error contracts from
bat-markets-core. - types
- Re-exported domain and request/response types from
bat-markets-core.
Structs§
- Balances
Watch - Live private balance watcher with typed updates and stream lifecycle control.
- Executions
Watch - Live private execution watcher with typed updates and stream lifecycle control.
- Funding
Rate Watch - Live funding-rate watcher with typed updates and stream lifecycle control.
- Liquidation
Watch - Live liquidation watcher with typed updates and stream lifecycle control.
- Lock
Diagnostics Snapshot - Snapshot of observed lock wait/hold costs for shared engine state.
- Mark
Price Watch - Live mark-price watcher with typed updates and stream lifecycle control.
- Native
Client - Access to venue-specific adapter functionality.
- Ohlcv
Watch - Live OHLCV watcher with typed updates and stream lifecycle control.
- Open
Interest Watch - Live open-interest watcher with typed updates and stream lifecycle control.
- Order
Book Watch - Live order-book watcher with typed updates and stream lifecycle control.
- Orders
Watch - Live private order watcher with typed updates and stream lifecycle control.
- Pending
Command Handle - Low-latency command handle with lifecycle tracking over the shared command bus.
- Positions
Watch - Live private position watcher with typed updates and stream lifecycle control.
- Runtime
Diagnostics Snapshot - Cheap runtime and lock diagnostics for live operator inspection.
- Status
Watch - RAII-style watcher for runtime status changes.
- Ticker
Watch - Live ticker watcher with typed updates and stream lifecycle control.
- Trades
Watch - Live trades watcher with typed updates and stream lifecycle control.