use std::sync::Arc;

use color_eyre::eyre::Result;
use discretionary_engine_risk::{collect_balances, config::LiveSettings, get_total_balance, initialize_exchanges};

pub async fn main(settings: Arc<LiveSettings>) -> Result<()> {
	let config = settings.config();
	let exchanges = initialize_exchanges(&config)?;
	let balances = collect_balances(&exchanges).await?;

	// Sort balances by value (descending)
	let mut sorted_balances: Vec<_> = balances.iter().collect();
	sorted_balances.sort_by(|a, b| b.1.partial_cmp(a.1).unwrap_or(std::cmp::Ordering::Equal));

	// Print individual balances
	for (key, balance) in sorted_balances {
		println!("{key}: {balance}$");
	}

	// Print total
	let total_balance = get_total_balance(&config, &balances).await?;
	println!("\nTotal: {total_balance}$");
	Ok(())
}
