Skip to main content

Crate dukascopy_fx

Crate dukascopy_fx 

Source
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 Ticker object with history() 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

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§

InstrumentCatalog
Collection of instruments used by the fetcher.
InstrumentDefinition
Instrument metadata used by the fetcher.
Ticker
A ticker handle for fetching instrument rate data.

Enums§

AssetClass
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