ostium-rust-sdk 0.1.0

Rust SDK for interacting with the Ostium trading platform on Arbitrum
Documentation
//! Account management functionality tests
//!
//! This test module validates account information queries including
//! Run this test with the following command:
//! cargo test --test account_functionality_test -- --test-threads=1 --nocapture

use ostium_rust_sdk::{Network, OstiumClient};

/// Helper function to create a test client
async fn create_test_client() -> Result<OstiumClient, Box<dyn std::error::Error>> {
    Ok(OstiumClient::new(Network::Mainnet).await?)
}

#[tokio::test]
async fn test_account_management_functionality() {
    // Initialize logging
    tracing_subscriber::fmt::init();

    println!("🏦 Ostium Account Management Test");
    println!("=================================\n");

    // Create client
    let client = create_test_client().await.unwrap();

    // Test with a sample address (you can replace this with a real address)
    let test_address = "0xd4f68b3479fa08f11adf37362637ba6061829a1f".parse().ok();

    println!("📊 Testing account queries for address: {:?}", test_address);
    println!();

    // Test balance query
    println!("💰 Testing balance query...");
    match client.get_balance(test_address).await {
        Ok(balance) => {
            println!("  ✅ Balance retrieved:");
            println!("    Asset: {}", balance.asset);
            println!("    Available: ${}", balance.available);
            println!("    Locked: ${}", balance.locked);
            println!("    Total: ${}", balance.total);
        }
        Err(e) => {
            println!("  ❌ Error fetching balance: {}", e);
        }
    }
    println!();

    // Test positions query
    println!("📈 Testing positions query...");
    match client.get_positions(test_address).await {
        Ok(positions) => {
            if positions.is_empty() {
                println!("  ✅ No open positions found");
            } else {
                println!("  ✅ Found {} open position(s):", positions.len());
                for (i, position) in positions.iter().enumerate() {
                    println!("    Position {}:", i + 1);
                    println!("      ID: {}", position.id);
                    println!("      Symbol: {}", position.symbol);
                    println!("      Side: {:?}", position.side);
                    println!("      Size: ${}", position.size);
                    println!("      Entry Price: ${}", position.entry_price);
                    println!("      Leverage: {}x", position.leverage);
                    if let Some(tp) = position.take_profit {
                        println!("      Take Profit: ${}", tp);
                    }
                    if let Some(sl) = position.stop_loss {
                        println!("      Stop Loss: ${}", sl);
                    }
                    println!("      Created: {}", position.created_at);
                    println!();
                }
            }
        }
        Err(e) => {
            println!("  ❌ Error fetching positions: {}", e);
        }
    }

    // Test orders query
    println!("📋 Testing orders query...");
    match client.get_orders(test_address).await {
        Ok(orders) => {
            if orders.is_empty() {
                println!("  ✅ No open orders found");
            } else {
                println!("  ✅ Found {} open order(s):", orders.len());
                for (i, order) in orders.iter().enumerate() {
                    println!("    Order {}:", i + 1);
                    println!("      ID: {}", order.id);
                    println!("      Symbol: {}", order.symbol);
                    println!("      Type: {:?}", order.order_type);
                    println!("      Side: {:?}", order.side);
                    println!("      Size: ${}", order.size);
                    if let Some(price) = order.price {
                        println!("      Price: ${}", price);
                    }
                    println!("      Status: {:?}", order.status);
                    println!("      Created: {}", order.created_at);
                    println!();
                }
            }
        }
        Err(e) => {
            println!("  ❌ Error fetching orders: {}", e);
        }
    }

    println!("✨ Account management test completed!");
    println!();
    println!("📚 Note:");
    println!("   • This test uses a sample address that likely has no positions/orders");
    println!("   • To test with real data, use an address that has active positions");
    println!("   • The SDK will iterate through all trading pairs to find positions/orders");
    println!("   • This may take some time depending on the number of pairs");

    // Tests pass if they complete without panicking
    // The actual functionality is tested by attempting the operations
}