use cbat::prelude::*;
use chrono::{DateTime, Utc};
#[tokio::main]
async fn main() {
let client = Client::new(
"products-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"),
);
println!("=== Getting Best Bid/Ask ===");
match ApiProducts::get_best_bid_ask(&client, Some(vec!["BTC-USD"])).await {
Ok(bid_ask) => println!("{:#?}", bid_ask),
Err(e) => eprintln!("Error getting best bid/ask: {}", e),
}
println!("\n=== Getting Product Book ===");
match ApiProducts::get_product_book(&client, "BTC-USD", Some(1), None).await {
Ok(book) => println!("{:#?}", book),
Err(e) => eprintln!("Error getting product book: {}", e),
}
println!("\n=== Listing Products ===");
match ApiProducts::list_products(&client, Some(1), None, None, None, None, None, None, None).await {
Ok(products) => println!("{:#?}", products),
Err(e) => eprintln!("Error listing products: {}", e),
}
println!("\n=== Getting Specific Product ===");
match ApiProducts::get_product(&client, "BTC-USD", None).await {
Ok(product) => println!("{:#?}", product),
Err(e) => eprintln!("Error getting product: {}", e),
}
println!("\n=== Getting Product Candles ===");
let current_time: DateTime<Utc> = Utc::now();
let epoch_time = current_time.timestamp();
let start = epoch_time - 10_000;
let end = epoch_time + 10_000;
match ApiProducts::get_product_candles(&client, "BTC-USD", &start.to_string(), &end.to_string(), Granularity::OneMinute, Some(1)).await {
Ok(candles) => println!("{:#?}", candles),
Err(e) => eprintln!("Error getting product candles: {}", e),
}
println!("\n=== Getting Market Trades ===");
match ApiProducts::get_market_trades(&client, "BTC-USD", 1, None, None).await {
Ok(trades) => println!("{:#?}", trades),
Err(e) => eprintln!("Error getting market trades: {}", e),
}
}