Expand description
§dukascopy-fx
A production-ready Rust library for fetching historical forex exchange rates, inspired by Python’s yfinance library.
§Quick Start
use dukascopy_fx::{Ticker, datetime};
// Create a ticker and get data - yfinance style!
let ticker = Ticker::new("EUR", "USD");
// Get recent rate
let rate = ticker.rate().await?;
println!("EUR/USD: {}", rate.rate);
// Get last week of data
let history = ticker.history("1w").await?;
for r in history {
println!("{}: {}", r.timestamp, r.rate);
}§Features
- yfinance-style API: Familiar
Tickerobject withhistory()method - Period strings: Use
"1d","1w","1mo","1y"for easy time ranges - Built-in time utilities: No need to add chrono separately
- Type-safe: Strong types for currency pairs, rates, and errors
- Automatic handling: JPY pairs, metals, weekends - all transparent
§Usage Patterns
§Ticker API (Recommended)
use dukascopy_fx::{Ticker, datetime};
let eur_usd = Ticker::new("EUR", "USD");
let gold = Ticker::xau_usd();
// Get rate at specific time
let rate = eur_usd.rate_at(datetime!(2024-01-15 14:30 UTC)).await?;
// Get historical data with period strings
let weekly = eur_usd.history("1w").await?;§Batch Download
use dukascopy_fx::{Ticker, download};
let tickers = vec![
Ticker::eur_usd(),
Ticker::gbp_usd(),
Ticker::usd_jpy(),
];
let data = download(&tickers, "1w").await?;
for (ticker, rates) in data {
println!("{}: {} records", ticker.symbol(), rates.len());
}§Simple Function API
use dukascopy_fx::{get_rate, datetime};
let rate = get_rate("EUR", "USD", datetime!(2024-01-15 14:30 UTC)).await?;
println!("Rate: {}", rate.rate);Re-exports§
pub use error::DukascopyError;pub use models::CurrencyExchange;pub use models::CurrencyPair;pub use market::get_market_status;pub use market::is_market_open;pub use market::is_weekend;pub use market::MarketStatus;
Modules§
- advanced
- Advanced API for power users who need fine-grained control.
- error
- Error types for the Dukascopy FX library.
- macros
- Convenient macros for the library.
- market
- Forex market hours utilities.
- models
- Data models for currency pairs and exchange rates.
- prelude
- Prelude module - import everything commonly needed.
- time
- Time utilities and re-exports for convenient datetime handling.
Macros§
Structs§
- Ticker
- A forex ticker for fetching exchange rate data.
Functions§
- download
- Downloads historical data for multiple tickers.
- download_
range - Downloads historical data with custom date range.
- get_
rate - Fetches the exchange rate for a currency pair at a specific timestamp.
- get_
rate_ for_ pair - Fetches the exchange rate using a
CurrencyPair. - get_
rates_ range - Fetches exchange rates over a time range.
- get_
rates_ range_ for_ pair - Fetches exchange rates over a time range using a
CurrencyPair.
Type Aliases§
- Error
- Convenient alias for
DukascopyError - Result
- Convenient Result type for this crate