#!/usr/bin/env cargo +nightly -Zscript //! Databento API Test & Balance Check Script //! //! Purpose: Verify API key, check credit balance, and test minimal data download //! //! Usage: //! cargo run --bin databento_test //! //! Requirements: //! - DATABENTO_API_KEY environment variable set //! - Network connectivity to Databento API //! //! Safety: //! - NO automatic downloads //! - Displays costs BEFORE any data download //! - Requires explicit confirmation use serde::{Deserialize, Serialize}; use std::error::Error; #[derive(Debug, Serialize, Deserialize)] struct AccountInfo { balance: f64, currency: String, organization: String, } #[derive(Debug, Serialize, Deserialize)] struct DatasetInfo { dataset: String, schema: String, cost_per_gb: f64, available_symbols: Vec, } #[tokio::main] async fn main() -> Result<(), Box> { println!("šŸ” Databento API Test & Balance Checker"); println!("========================================\n"); // 1. Check for API key let api_key = std::env::var("DATABENTO_API_KEY") .map_err(|_| "DATABENTO_API_KEY not set in environment")?; println!("āœ… API Key found: {}...{}", &api_key[..10], &api_key[api_key.len()-10..]); // 2. Verify API key and get account info println!("\nšŸ“Š Checking account balance..."); let client = reqwest::Client::new(); // Note: Databento API endpoint for account info // This is a placeholder - actual endpoint needs to be verified from docs let account_url = "https://api.databento.com/v0/account"; let response = client .get(account_url) .header("Authorization", format!("Bearer {}", api_key)) .send() .await; match response { Ok(resp) => { if resp.status().is_success() { println!("āœ… API key is valid!"); // Try to parse account info if let Ok(text) = resp.text().await { println!("\nšŸ“‹ Account Info:"); println!("{}", text); } } else { let status = resp.status(); let error_text = resp.text().await.unwrap_or_default(); println!("āŒ API key validation failed:"); println!(" Status: {}", status); println!(" Error: {}", error_text); return Err(format!("Invalid API key: {}", status).into()); } } Err(e) => { println!("āŒ Network error connecting to Databento API:"); println!(" {}", e); return Err(e.into()); } } // 3. Display pricing information println!("\nšŸ’° Dataset Pricing Information:"); println!("================================"); println!("\nFrom Databento documentation:"); println!("• $125 FREE credits for historical data"); println!("• Pricing is per GB consumed"); println!("• OHLCV bars (cheapest): ~$0.50-$2.00 per GB"); println!("• Trades: ~$5-$15 per GB"); println!("• L2 Order Book (MBP): ~$10-$30 per GB"); println!("• L3 Order Book (MBO): ~$30-$100 per GB"); // 4. Recommended minimal test download println!("\nšŸŽÆ Recommended Minimal Test Download:"); println!("===================================="); println!("Symbol: ES.FUT (E-mini S&P 500 futures)"); println!("Dataset: GLBX.MDP3 (CME MDP 3.0)"); println!("Schema: ohlcv-1m (1-minute bars)"); println!("Date Range: 1 day (e.g., 2024-01-02)"); println!("Est. Size: ~5-20 MB"); println!("Est. Cost: ~$0.01-$0.05 (well under $125 limit)"); println!("\nAlternative (even cheaper):"); println!("Symbol: SPY (S&P 500 ETF)"); println!("Dataset: XNAS.ITCH (Nasdaq)"); println!("Schema: ohlcv-1m"); println!("Date Range: 1 day"); println!("Est. Cost: ~$0.005-$0.02"); // 5. Cost estimation tool println!("\nšŸ“ Cost Estimation Formula:"); println!("==========================="); println!("Estimated GB = (symbols Ɨ days Ɨ data_points Ɨ bytes_per_point) / 1GB"); println!(" OHLCV-1m: ~390 bars/day Ɨ 32 bytes = ~12 KB per symbol per day"); println!(" Trades: ~10,000 trades/day Ɨ 24 bytes = ~240 KB per symbol per day"); println!(" MBP-1: ~100,000 updates/day Ɨ 48 bytes = ~4.8 MB per symbol per day"); println!("\nāš ļø IMPORTANT: NO DATA DOWNLOADED YET!"); println!(" This script only checks your account status."); println!(" Use the Databento Python/Rust client to actually download data."); println!(" Always check the cost estimate BEFORE downloading!"); println!("\nšŸ“š Next Steps:"); println!("=============="); println!("1. Review the pricing information above"); println!("2. Use Databento's cost estimator: https://databento.com/pricing"); println!("3. Start with OHLCV-1m data (cheapest option)"); println!("4. Download 1-2 days for 1-2 symbols first"); println!("5. Validate data quality before scaling up"); println!("6. Monitor your credit balance regularly"); Ok(()) }