cbat 0.0.19

The unofficial Rust crate for the Coinbase Advanced Trade API
Documentation
use cbat::prelude::*;

#[tokio::main]
async fn main() {
    // Initialize the client with your API credentials
    let client = Client::new(
        "accounts-example",
        std::env::var("CBAT_KEY_NAME").expect("CBAT_KEY_NAME must be set"),
        std::env::var("CBAT_KEY_SECRET").expect("CBAT_KEY_SECRET must be set"),
    );

    // List all accounts
    println!("=== Listing All Accounts ===");
    match ApiAccounts::list_accounts(&client).await {
        Ok(accounts) => println!("{:#?}", accounts),
        Err(e) => eprintln!("Error listing accounts: {}", e),
    }

    // Get a specific account (you'll need a valid account UUID)
    println!("\n=== Getting Specific Account ===");
    match ApiAccounts::list_accounts(&client).await {
        Ok(accounts) => {
            if let Some(accs) = accounts.accounts {
                if let Some(first_account) = accs.first() {
                    match ApiAccounts::get_account(&client, &first_account.uuid).await {
                        Ok(account) => println!("{:#?}", account),
                        Err(e) => eprintln!("Error getting account: {}", e),
                    }
                }
            }
        }
        Err(e) => eprintln!("Error listing accounts: {}", e),
    }

    // List portfolios
    println!("\n=== Listing Portfolios ===");
    match ApiPortfolios::list_portfolios(&client, None).await {
        Ok(portfolios) => println!("{:#?}", portfolios),
        Err(e) => eprintln!("Error listing portfolios: {}", e),
    }
}