use ostium_rust_sdk::{Network, OstiumClient};
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() {
tracing_subscriber::fmt::init();
println!("🏦 Ostium Account Management Test");
println!("=================================\n");
let client = create_test_client().await.unwrap();
let test_address = "0xd4f68b3479fa08f11adf37362637ba6061829a1f".parse().ok();
println!("📊 Testing account queries for address: {:?}", test_address);
println!();
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!();
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);
}
}
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");
}