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 interop::flatten_row;pub use interop::flatten_rows;pub use interop::FlatExchangeRow;pub use models::CurrencyExchange;pub use models::CurrencyPair;pub use models::RateRequest;pub use models::RequestParseMode;pub use storage::checkpoint::CheckpointStore;pub use storage::checkpoint::FileCheckpointStore;pub use storage::sink::CsvSink;pub use storage::sink::DataSink;pub use storage::sink::NoopSink;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.
- interop
- Interoperability helpers for analytics/dataframe pipelines.
- 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.
- storage
- Storage primitives for fetcher workflows.
- time
- Time utilities and re-exports for convenient datetime handling.
Macros§
- datetime
- Creates a UTC datetime with a concise syntax.
- ticker
- Creates a ticker with a concise syntax.
- try_
datetime - Creates a UTC datetime and returns
Option<DateTime<Utc>>instead of panicking. - try_
ticker - Creates a ticker and returns
Result<Ticker, DukascopyError>.
Structs§
- Instrument
Catalog - Collection of instruments used by the fetcher.
- Instrument
Definition - Instrument metadata used by the fetcher.
- Ticker
- A ticker handle for fetching instrument rate data.
Enums§
- Asset
Class - Asset class for an instrument.
- Period
- Typed period for historical queries.
Constants§
- DEFAULT_
DOWNLOAD_ CONCURRENCY - Default maximum number of concurrent ticker download tasks.
Functions§
- download
- Downloads historical data for multiple tickers.
- download_
incremental - Incrementally downloads data for multiple tickers using checkpoint store.
- download_
incremental_ with_ client - Incrementally downloads data using client-configured concurrency.
- download_
incremental_ with_ concurrency - Incrementally downloads data for multiple tickers with custom concurrency limit.
- download_
range - Downloads historical data with custom date range.
- download_
range_ with_ client - Downloads historical data over a custom range using client-configured concurrency.
- download_
range_ with_ concurrency - Downloads historical data with custom date range and concurrency limit.
- download_
with_ client - Downloads historical data using client-configured concurrency.
- download_
with_ concurrency - Downloads historical data for multiple tickers with custom concurrency limit.
- get_
rate - Fetches the exchange rate for a currency pair at a specific timestamp.
- get_
rate_ for_ input - Parses request from input and fetches exchange rate.
- get_
rate_ for_ input_ with_ mode - Parses request from input using explicit parse mode and fetches exchange rate.
- get_
rate_ for_ pair - Fetches the exchange rate using a
CurrencyPair. - get_
rate_ for_ request - Fetches exchange rate for a unified request type (pair or symbol).
- get_
rate_ for_ symbol - Fetches exchange rate for a symbol using global client default quote currency.
- get_
rate_ in_ quote - Fetches exchange rate for a symbol in target quote currency.
- 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