- 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
113 lines
4.2 KiB
Rust
113 lines
4.2 KiB
Rust
//! Test Databento historical data download using existing infrastructure
|
|
//!
|
|
//! This example tests the minimal download of ES.FUT OHLCV-1m data for a single day.
|
|
|
|
use std::env;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
println!("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
println!(" Databento Historical Download Test");
|
|
println!("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
println!();
|
|
|
|
// Check for API key
|
|
let api_key = env::var("DATABENTO_API_KEY")
|
|
.map_err(|_| "DATABENTO_API_KEY environment variable not set")?;
|
|
|
|
println!("✅ API Key found: {}...{}", &api_key[0..10], &api_key[api_key.len()-10..]);
|
|
println!();
|
|
|
|
// Test parameters
|
|
let symbol = "ES.FUT";
|
|
let dataset = "GLBX.MDP3";
|
|
let schema = "ohlcv-1m";
|
|
let start_date = "2024-01-02";
|
|
let end_date = "2024-01-02";
|
|
|
|
println!("📋 Download Parameters:");
|
|
println!(" Symbol: {} (E-mini S&P 500 Futures)", symbol);
|
|
println!(" Dataset: {} (CME Group MDP 3.0)", dataset);
|
|
println!(" Schema: {} (1-minute OHLCV bars)", schema);
|
|
println!(" Date: {} (single trading day)", start_date);
|
|
println!();
|
|
|
|
// Create HTTP client for Databento Historical API
|
|
let client = reqwest::Client::builder()
|
|
.timeout(std::time::Duration::from_secs(30))
|
|
.build()?;
|
|
|
|
// Build request URL
|
|
let url = format!(
|
|
"https://hist.databento.com/v0/timeseries.get_range?dataset={}&symbols={}&schema={}&start={}T00:00:00Z&end={}T23:59:59Z&encoding=dbn&stype_in=parent",
|
|
dataset, symbol, schema, start_date, end_date
|
|
);
|
|
|
|
println!("🔗 Request URL:");
|
|
println!(" {}", url);
|
|
println!();
|
|
|
|
println!("📥 Sending request...");
|
|
|
|
// Make request with Basic Authentication
|
|
let response = client
|
|
.get(&url)
|
|
.basic_auth(&api_key, Some(""))
|
|
.send()
|
|
.await?;
|
|
|
|
// Check status
|
|
let status = response.status();
|
|
println!("📊 Response Status: {}", status);
|
|
println!();
|
|
|
|
if !status.is_success() {
|
|
let error_text = response.text().await?;
|
|
eprintln!("❌ Request failed!");
|
|
eprintln!("Status: {}", status);
|
|
eprintln!("Response: {}", error_text);
|
|
return Err(format!("API returned error: {}", status).into());
|
|
}
|
|
|
|
// Get response body
|
|
let body = response.bytes().await?;
|
|
let size = body.len();
|
|
|
|
println!("✅ Download successful!");
|
|
println!("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
println!(" Size: {} bytes ({:.2} KB)", size, size as f64 / 1024.0);
|
|
|
|
// Estimate cost
|
|
let size_gb = size as f64 / 1_073_741_824.0;
|
|
let cost_low = size_gb * 0.50;
|
|
let cost_high = size_gb * 2.00;
|
|
|
|
println!(" Size (GB): {:.10}", size_gb);
|
|
println!(" Estimated: ${:.6} - ${:.6}", cost_low, cost_high);
|
|
println!(" Credits Left: ~${:.2}", 125.0 - cost_high);
|
|
println!();
|
|
|
|
// Save to file
|
|
let output_path = format!("test_data/real/databento/{}_{}_{}.dbn", symbol.replace("/", "_"), schema, start_date);
|
|
std::fs::create_dir_all("test_data/real/databento")?;
|
|
std::fs::write(&output_path, &body)?;
|
|
|
|
println!("💾 Saved to: {}", output_path);
|
|
println!();
|
|
|
|
// Verify file
|
|
if std::path::Path::new(&output_path).exists() {
|
|
let file_size = std::fs::metadata(&output_path)?.len();
|
|
println!("✅ File verified: {} bytes", file_size);
|
|
} else {
|
|
println!("⚠️ Warning: File not found after write");
|
|
}
|
|
|
|
println!();
|
|
println!("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
println!(" Test Complete!");
|
|
println!("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
|
|
Ok(())
|
|
}
|