Example Bots

The SDK ships with four runnable examples in sdk/rust/examples/. Clone the repo and run them directly.

read_markets — Read-Only Market Discovery

Connects to the indexer and chain, fetches all markets, and displays the orderbook for the first active market. No wallet required.

cargo run --example read_markets
use strike_sdk::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();

    let client = StrikeClient::new(StrikeConfig::bsc_testnet()).build()?;

    // Fetch markets from indexer
    let markets = client.indexer().get_markets().await?;
    println!("found {} markets", markets.len());

    for market in &markets {
        println!(
            "  market {} | status: {} | expiry: {} | batch_interval: {}s",
            market.id, market.status, market.expiry_time, market.batch_interval,
        );
    }

    // Read on-chain state
    let active_count = client.markets().active_market_count().await?;
    println!("active markets: {active_count}");

    // Get orderbook for first active market
    let active_markets: Vec<_> = markets.iter().filter(|m| m.status == "active").collect();
    if let Some(market) = active_markets.first() {
        let ob = client.indexer().get_orderbook(market.id as u64).await?;
        println!("\norderbook for market {}:", market.id);
        for level in &ob.bids {
            println!("  bid: tick {} | {} lots", level.tick, level.lots);
        }
        for level in &ob.asks {
            println!("  ask: tick {} | {} lots", level.tick, level.lots);
        }
    }

    Ok(())
}

What it demonstrates: Client setup in read-only mode, indexer queries, on-chain market reads.

place_orders — Full Trading Lifecycle

Connects with a wallet, approves USDT, finds an active market, places a bid and ask, then cancels both.

What it demonstrates: Wallet setup, USDT approval, order placement and cancellation.

stream_events — Event-Driven Architecture

Subscribes to WSS events and prints market creations, batch clearings, and settlements.

What it demonstrates: Event streaming, pattern matching on StrikeEvent, read-only WSS subscription.

simple_bot — Minimal Market Maker Skeleton

Listens for new markets and quotes a fixed 10-tick spread around mid (tick 50). This is a skeleton — a real bot would compute fair value from a price feed.

What it demonstrates: Combining events with order placement, event-driven bot architecture, error handling per-market.

Tips for Building a Real Bot

  • Pricing: Use a Pyth price feed to compute fair value instead of a fixed mid. The strike price and expiry are in MarketCreated.

  • Position tracking: Use scan_orders() on startup to recover open orders, then track fills via OrderSettled events.

  • Risk management: Track net position per market. Consider maximum exposure limits and position sizing.

  • Requoting: Use replace() to atomically cancel stale quotes and place new ones, avoiding temporary unhedged exposure.

  • Nonce management: Enable init_nonce_sender() for rapid transaction sending without nonce collisions.

  • Reconnection: EventStream auto-reconnects on WSS failures, but you may miss events during the gap. Periodically reconcile state via the indexer or scan_orders().

Last updated