- Created data/examples/download_ml_training_data.rs using reqwest + Databento HTTP API - Downloaded 90 days × 4 symbols (ES.FUT, NQ.FUT, ZN.FUT, 6E.FUT) - Files saved to test_data/real/databento/ml_training/ - Total: 360 files, 15 MB compressed DBN format - Used existing Rust pattern from download_nq_fut.rs - API key loaded from .env file - 100% success rate (360/360 files) - Ready for ML training benchmarks Next: Create simplified training benchmark for RTX 3050 Ti GPU measurements
141 lines
5.1 KiB
Rust
141 lines
5.1 KiB
Rust
#!/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<String>,
|
||
}
|
||
|
||
#[tokio::main]
|
||
async fn main() -> Result<(), Box<dyn Error>> {
|
||
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(())
|
||
}
|