Skip to main content

Module market

Module market 

Source
Expand description

Market module for peg and order book health analysis.

Fetches level-2 order book data from exchange APIs and runs configurable health checks for stablecoin markets.

§Market Module

Provides peg and order book health analysis for stablecoin markets. Uses a data-driven architecture: exchange behaviour is described by YAML venue descriptors (see venues/ directory). A VenueRegistry loads all descriptors and creates generic ExchangeClient instances at runtime, so new venues can be added without code changes.

§Supported Venues

Built-in CEX descriptors: Binance, MEXC, Bitget, Gate.io, Bybit, OKX, Coinbase, Kraken, HTX, Crypto.com, and Biconomy. DEX data (Ethereum, Solana) is synthesized from DexScreener liquidity.

§Usage

use scope::market::{VenueRegistry, HealthThresholds, MarketSummary};

#[tokio::main]
async fn main() -> scope::Result<()> {
    let registry = VenueRegistry::load()?;
    let exchange = registry.create_exchange_client("binance")?;
    let pair = exchange.format_pair("USDC");
    let book = exchange.fetch_order_book(&pair).await?;
    let summary = MarketSummary::from_order_book(&book, 1.0, &HealthThresholds::default(), None);
    print!("{}", summary.format_text(Some("binance")));
    Ok(())
}

Re-exports§

pub use configurable_client::ConfigurableExchangeClient;
pub use descriptor::VenueDescriptor;
pub use exchange::ExchangeClient;
pub use orderbook::ExecutionEstimate;
pub use orderbook::ExecutionSide;
pub use orderbook::HealthCheck;
pub use orderbook::HealthThresholds;
pub use orderbook::MarketSnapshot;
pub use orderbook::MarketSummary;
pub use orderbook::OrderBook;
pub use orderbook::OrderBookClient;
pub use orderbook::OrderBookLevel;
pub use orderbook::Ticker;
pub use orderbook::TickerClient;
pub use orderbook::Trade;
pub use orderbook::TradeHistoryClient;
pub use orderbook::TradeSide;
pub use orderbook::order_book_from_analytics;
pub use registry::VenueRegistry;

Modules§

analytics
DEX analytics utilities.
configurable_client
Generic exchange client that interprets a VenueDescriptor at runtime.
descriptor
Venue descriptor schema for data-driven exchange integration.
exchange
ExchangeClient facade: composes OrderBook, Ticker, and TradeHistory capabilities behind a unified interface with capability discovery.
health
Order book health analysis and market summary.
registry
Venue registry: loads and manages venue descriptors.
traits
Market client traits for fetching exchange data.
types
Core market data types.