Skip to main content

Crate bat_markets

Crate bat_markets 

Source
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_*, and set_* methods send commands.
  • BatMarkets::advanced exposes raw ingestion, diagnostics, reconcile, and native adapters.

§API map

FamilyPrimary methodsResponsibility
Metadata/cacheBatMarkets::markets, BatMarkets::load_marketslocal bundled metadata and live venue metadata refresh
Public RESTfetch_ticker, fetch_tickers, fetch_order_book, fetch_ohlcv, fetch_trades, fetch_mark_price, fetch_funding_rate, fetch_open_interest, fetch_liquidationsunauthenticated market snapshots
Private RESTfetch_balance, fetch_positions, fetch_open_orders, fetch_order, fetch_my_tradesauthenticated account, position, order, and execution snapshots
Public WSwatch_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_statustyped live updates over shared websocket hubs
Private WSwatch_balance, watch_orders, watch_my_trades, watch_positionsauthenticated account-stream updates over one shared private hub
Commandscreate_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_modewrite operations with lifecycle-aware PendingCommandHandle results
AdvancedBatMarkets::advancedraw 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§

BalancesWatch
Live private balance watcher with typed updates and stream lifecycle control.
ExecutionsWatch
Live private execution watcher with typed updates and stream lifecycle control.
FundingRateWatch
Live funding-rate watcher with typed updates and stream lifecycle control.
LiquidationWatch
Live liquidation watcher with typed updates and stream lifecycle control.
LockDiagnosticsSnapshot
Snapshot of observed lock wait/hold costs for shared engine state.
MarkPriceWatch
Live mark-price watcher with typed updates and stream lifecycle control.
NativeClient
Access to venue-specific adapter functionality.
OhlcvWatch
Live OHLCV watcher with typed updates and stream lifecycle control.
OpenInterestWatch
Live open-interest watcher with typed updates and stream lifecycle control.
OrderBookWatch
Live order-book watcher with typed updates and stream lifecycle control.
OrdersWatch
Live private order watcher with typed updates and stream lifecycle control.
PendingCommandHandle
Low-latency command handle with lifecycle tracking over the shared command bus.
PositionsWatch
Live private position watcher with typed updates and stream lifecycle control.
RuntimeDiagnosticsSnapshot
Cheap runtime and lock diagnostics for live operator inspection.
StatusWatch
RAII-style watcher for runtime status changes.
TickerWatch
Live ticker watcher with typed updates and stream lifecycle control.
TradesWatch
Live trades watcher with typed updates and stream lifecycle control.