allratestoday 1.0.0

Official Rust SDK for AllRatesToday — real-time mid-market exchange rates for 160+ currencies
Documentation

allratestoday

Crates.io Docs.rs License: MIT

Official Rust SDK for AllRatesToday -- real-time mid-market exchange rates for 160+ currencies.

Installation

Add the crate to your project:

cargo add allratestoday

Or add it manually to your Cargo.toml:

[dependencies]
allratestoday = "1"

Quick Start

use allratestoday::AllRatesToday;

fn main() {
    let client = AllRatesToday::new("art_live_your_api_key");

    // Get latest rates
    let rates = client.latest("USD", Some(&["EUR", "GBP"])).unwrap();
    println!("{:?}", rates);

    // Convert currency
    let result = client.convert("USD", "EUR", 100.0).unwrap();
    println!("100 USD = {:?} EUR", result.result);
}

Authentication

Sign up at allratestoday.com to get your API key. Keys follow the format art_live_....

The SDK sends the key as a Bearer token in the Authorization header.

API Methods

latest(base, symbols) -- Get Latest Rates

Fetch the most recent exchange rates for a base currency.

// All currencies
let rates = client.latest("USD", None)?;

// Specific currencies only
let rates = client.latest("USD", Some(&["EUR", "GBP", "JPY"]))?;
println!("Base: {:?}", rates.base);
println!("Rates: {:?}", rates.rates);

convert(from, to, amount) -- Convert Currency

Convert an amount from one currency to another.

let result = client.convert("USD", "EUR", 250.0)?;
println!("Rate: {:?}", result.rate);
println!("Result: {:?}", result.result);

for_date(date, base, symbols) -- Historical Rates

Get exchange rates for a specific historical date.

let rates = client.for_date("2025-01-15", "USD", Some(&["EUR", "GBP"]))?;
println!("Date: {:?}", rates.date);
println!("Rates: {:?}", rates.rates);

time_series(start_date, end_date, base, symbols) -- Time Series

Get exchange rates over a date range.

let series = client.time_series(
    "2025-01-01",
    "2025-01-31",
    "USD",
    Some(&["EUR", "GBP"]),
)?;
for (date, day_rates) in series.rates.unwrap_or_default() {
    println!("{date}: {:?}", day_rates);
}

symbols() -- List Supported Currencies

Retrieve all supported currency codes and names.

let symbols = client.symbols()?;
for (code, info) in symbols.symbols.unwrap_or_default() {
    println!("{code}: {info}");
}

get_rate(from, to) -- Single Pair Rate

Get the exchange rate for a single currency pair.

let rate = client.get_rate("USD", "EUR")?;
println!("USD/EUR: {:?}", rate.rate);

get_historical_rates(source, target, period) -- Preset Period Historical Rates

Get historical rates for a currency pair over a preset period.

Supported periods: 1d, 7d, 30d, 1y.

let history = client.get_historical_rates("USD", "EUR", "30d")?;
for point in history.rates.unwrap_or_default() {
    println!("{}: {:?}", point.date.unwrap_or_default(), point.rate);
}

Error Handling

All methods return Result<T, AllRatesTodayError>. The error enum has three variants:

Variant Description
HttpError Network or transport-level failure (timeout, DNS, TLS)
ApiError Non-2xx HTTP response from the API
ParseError Failed to deserialize the response body
use allratestoday::{AllRatesToday, AllRatesTodayError};

let client = AllRatesToday::new("art_live_your_api_key");

match client.latest("USD", None) {
    Ok(rates) => println!("{:?}", rates),
    Err(AllRatesTodayError::HttpError(e)) => eprintln!("Network error: {e}"),
    Err(AllRatesTodayError::ApiError { status, message }) => {
        eprintln!("API error {status}: {message}");
    }
    Err(AllRatesTodayError::ParseError(msg)) => eprintln!("Parse error: {msg}"),
}

Custom Base URL

For testing or self-hosted instances, you can override the base URL:

let client = AllRatesToday::with_base_url(
    "art_live_your_api_key",
    "https://custom.example.com",
);

Examples

Run the included example:

export ALLRATESTODAY_API_KEY="art_live_your_api_key"
cargo run --example basic

License

This project is licensed under the MIT License.

Links