Home Documentation Playground Pricing API Status Blog About FAQ Support

Rust Exchange Rate API | AllRatesToday Rust SDK

Integrate exchange rates into Rust apps with the official AllRatesToday SDK. cargo add allratestoday to get started with 160+ currencies.

Documentation index: see the full API reference for all REST endpoints. For other SDKs, visit the docs hub.

Rust Exchange Rate API — AllRatesToday SDK

The allratestoday crate is the official Rust SDK for the AllRatesToday currency API. It provides a typed, async client for fetching live mid-market rates, converting between 160+ currencies, querying historical time-series, and more — all with idiomatic Rust error handling.

The crate is published on crates.io and full API documentation is available on docs.rs. Source code and issue tracking live on GitHub.

Installation

Add the crate with Cargo:

cargo add allratestoday

Or add it directly to your Cargo.toml:

[dependencies]
allratestoday = "0.1"

The crate uses reqwest under the hood and requires an async runtime such as tokio.

Quick Start

Create a client, fetch the latest rates, and convert a currency amount in a few lines:

use allratestoday::AllRatesToday;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = AllRatesToday::new("art_live_xxxxx");

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

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

    Ok(())
}

Authentication

Every request is authenticated with a Bearer token derived from your API key. Pass the key when constructing the client:

let client = AllRatesToday::new("art_live_xxxxx");
  1. Sign up at allratestoday.com/register.
  2. Verify your email.
  3. Copy the key from your dashboard. It begins with art_live_.
  4. Pass it to AllRatesToday::new() or load it from an environment variable at runtime.

For production apps, avoid hardcoding the key. Load it from an environment variable instead:

let api_key = std::env::var("ALLRATES_API_KEY")
    .expect("ALLRATES_API_KEY must be set");
let client = AllRatesToday::new(&api_key);

All Methods

The AllRatesToday struct exposes the following async methods. All return a Result with structured response types and AllRatesTodayError on failure.

latest(base, symbols)

Fetch the latest exchange rates for a base currency, optionally filtered to specific target symbols.

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

// Only EUR and GBP
let filtered = client.latest("USD", Some(&["EUR", "GBP"])).await?;
ParameterTypeDescription
base &str Base currency code (e.g. "USD").
symbols Option<&[&str]> Optional list of target currency codes. Pass None for all.

convert(from, to, amount)

Convert an amount from one currency to another using the latest mid-market rate.

let result = client.convert("EUR", "JPY", 250.0).await?;
println!("{} EUR = {} JPY", result.query.amount, result.result);
ParameterTypeDescription
from &str Source currency code.
to &str Target currency code.
amount f64 Amount to convert.

for_date(date, base, symbols)

Retrieve historical exchange rates for a specific date.

let historical = client.for_date("2025-01-15", "USD", Some(&["EUR", "GBP"])).await?;
println!("{:#?}", historical);
ParameterTypeDescription
date &str Date in YYYY-MM-DD format.
base &str Base currency code.
symbols Option<&[&str]> Optional list of target currency codes.

time_series(start, end, base, symbols)

Fetch exchange rates over a date range. Returns a map of dates to rate objects.

let series = client.time_series(
    "2025-01-01",
    "2025-01-31",
    "USD",
    Some(&["EUR", "GBP"]),
).await?;

for (date, rates) in &series.rates {
    println!("{}: {:#?}", date, rates);
}
ParameterTypeDescription
start &str Start date (YYYY-MM-DD).
end &str End date (YYYY-MM-DD).
base &str Base currency code.
symbols Option<&[&str]> Optional list of target currency codes.

symbols()

List all supported currencies with their names and codes.

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

Takes no parameters. Returns a map of currency codes to metadata objects.

get_rate(from, to)

Get the current exchange rate for a single currency pair.

let rate = client.get_rate("GBP", "USD").await?;
println!("1 GBP = {} USD", rate.rate);
ParameterTypeDescription
from &str Source currency code.
to &str Target currency code.

get_historical_rates(source, target, period)

Retrieve historical rates for a currency pair over a preset time period.

let history = client.get_historical_rates("USD", "EUR", "30d").await?;
for point in &history.rates {
    println!("{}: {}", point.date, point.rate);
}
ParameterTypeDescription
source &str Source currency code.
target &str Target currency code.
period &str Time window: "1d", "7d", "30d", or "1y".

Error Handling

All methods return Result<T, AllRatesTodayError>. The error enum covers network failures, authentication problems, and API-level errors:

use allratestoday::{AllRatesToday, AllRatesTodayError};

match client.latest("USD", None).await {
    Ok(rates) => println!("{:#?}", rates),
    Err(AllRatesTodayError::Unauthorized) => {
        eprintln!("Invalid API key. Check your art_live_ token.");
    }
    Err(AllRatesTodayError::RateLimited) => {
        eprintln!("Rate limit exceeded. Wait or upgrade your plan.");
    }
    Err(AllRatesTodayError::BadRequest(msg)) => {
        eprintln!("Bad request: {}", msg);
    }
    Err(AllRatesTodayError::Network(e)) => {
        eprintln!("Network error: {}", e);
    }
    Err(e) => {
        eprintln!("Unexpected error: {}", e);
    }
}
VariantCause
Unauthorized Missing or invalid API key (HTTP 401).
RateLimited Monthly quota exceeded (HTTP 429). Upgrade at allratestoday.com/pricing.
BadRequest(String) Invalid parameters — unsupported currency code, bad date format, etc.
Network(reqwest::Error) Connection timeout, DNS failure, or other transport-level error.

Configuration

By default, the client connects to https://allratestoday.com. You can override the base URL for staging or self-hosted deployments:

let client = AllRatesToday::new("art_live_xxxxx")
    .base_url("https://staging.allratestoday.com");
OptionDefaultPurpose
new(api_key) Create a client with the given API key (Bearer token).
.base_url(url) https://allratestoday.com Override the API host. Useful for staging or local development.

Full Example

A complete program that fetches the latest rates, converts a value, and checks historical data:

use allratestoday::AllRatesToday;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api_key = std::env::var("ALLRATES_API_KEY")
        .expect("Set ALLRATES_API_KEY environment variable");
    let client = AllRatesToday::new(&api_key);

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

    // Currency conversion
    let conversion = client.convert("USD", "EUR", 1000.0).await?;
    println!("1000 USD = {} EUR", conversion.result);

    // Historical rate for a specific date
    let historical = client.for_date("2025-06-01", "EUR", Some(&["USD"])).await?;
    println!("EUR/USD on 2025-06-01: {:#?}", historical);

    // Time series over a month
    let series = client.time_series(
        "2025-01-01", "2025-01-31", "GBP", Some(&["USD"])
    ).await?;
    println!("GBP/USD January 2025: {} data points", series.rates.len());

    // Single pair rate
    let rate = client.get_rate("AUD", "CAD").await?;
    println!("AUD/CAD: {}", rate.rate);

    // List all supported currencies
    let symbols = client.symbols().await?;
    println!("Supported currencies: {}", symbols.symbols.len());

    // Historical rates with preset period
    let history = client.get_historical_rates("USD", "JPY", "7d").await?;
    println!("USD/JPY last 7 days: {} points", history.rates.len());

    Ok(())
}

Support

Resources

Ready to add live FX data to your Rust app?

One cargo add. Free tier. No credit card.

Get a free API key View source on GitHub