ostium-rust-sdk 0.1.0

Rust SDK for interacting with the Ostium trading platform on Arbitrum
Documentation
//! Basic usage example for the Ostium Rust SDK
//!
//! This example demonstrates how to:
//! - Create a client
//! - Query market data
//! - Check account balance
//! - Get trading pairs

use ostium_rust_sdk::{Network, OstiumClient, Result};

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

    println!("🚀 Ostium Rust SDK - Basic Usage Example");
    println!("=========================================");

    // Create a client connected to testnet (no private key needed for read-only operations)
    println!("\n📡 Connecting to Ostium testnet...");
    let client = OstiumClient::new(Network::Testnet).await?;

    println!("✅ Connected to network: {:?}", client.config().network);
    println!("🔗 RPC URL: {}", client.config().rpc_url);
    println!("📊 GraphQL URL: {}", client.config().graphql_url);

    // Get available trading pairs
    println!("\n📈 Fetching available trading pairs...");
    match client.get_pairs().await {
        Ok(pairs) => {
            println!("✅ Found {} trading pairs:", pairs.len());
            for pair in pairs.iter().take(5) {
                println!(
                    "  â€ĸ {} ({})",
                    pair.symbol,
                    if pair.is_active { "Active" } else { "Inactive" }
                );
            }
            if pairs.len() > 5 {
                println!("  ... and {} more", pairs.len() - 5);
            }
        }
        Err(e) => {
            println!("âš ī¸  Failed to fetch pairs: {}", e);
        }
    }

    // Get price for BTC/USD
    println!("\n💰 Fetching BTC/USD price...");
    match client.get_price("BTC/USD").await {
        Ok(price) => {
            println!("✅ BTC/USD Price:");
            println!("  â€ĸ Mark Price: ${}", price.mark_price);
            println!("  â€ĸ Index Price: ${}", price.index_price);
            println!("  â€ĸ 24h High: ${}", price.high_24h);
            println!("  â€ĸ 24h Low: ${}", price.low_24h);
            println!("  â€ĸ 24h Volume: ${}", price.volume_24h);
        }
        Err(e) => {
            println!("âš ī¸  Failed to fetch price: {}", e);
        }
    }

    // Check trading hours
    println!("\n🕐 Checking trading hours for BTC/USD...");
    match client.get_trading_hours("BTC/USD").await {
        Ok(hours) => {
            println!("✅ Trading Hours:");
            println!(
                "  â€ĸ Market Open: {}",
                if hours.is_open { "Yes" } else { "No" }
            );
            if let Some(next_open) = hours.next_open {
                println!("  â€ĸ Next Open: {}", next_open);
            }
            if let Some(next_close) = hours.next_close {
                println!("  â€ĸ Next Close: {}", next_close);
            }
        }
        Err(e) => {
            println!("âš ī¸  Failed to fetch trading hours: {}", e);
        }
    }

    // Example of checking balance (requires an address)
    println!("\nđŸ’ŗ Balance check example:");
    println!("â„šī¸  To check balance, you need to provide an address or configure a signer");
    println!("   Example: client.get_balance(Some(address)).await");

    println!("\n✨ Basic usage example completed!");
    println!("\n📚 Next steps:");
    println!("   â€ĸ Check examples/trading.rs for trading operations");
    println!("   â€ĸ Configure a private key to enable trading");
    println!("   â€ĸ Explore the full API documentation");

    Ok(())
}