Fetch live and historical exchange rates in Rust. Install our SDK with cargo or call the REST API directly with reqwest.
Install the official Rust SDK from crates.io using cargo.
cargo add exchange-rateapi
Or add it manually to your Cargo.toml:
[dependencies]
exchange-rateapi = "0.1"
reqwest and serde which are pulled in automatically.
Create a client and fetch your first exchange rate in just a few lines.
use exchange_rateapi::ExchangeRateAPI;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ExchangeRateAPI::new("era_live_YOUR_API_KEY");
// Get the latest USD to EUR rate
let rate = client.get_rate("USD", "EUR").await?;
println!("1 USD = {} EUR", rate.rate);
// Output: 1 USD = 0.9215 EUR
Ok(())
}
era_live_. The free plan includes 300 requests per month.
The SDK authenticates every request using a Bearer token derived from your API key. Pass the key when constructing the client.
use exchange_rateapi::ExchangeRateAPI;
let client = ExchangeRateAPI::new("era_live_YOUR_API_KEY");
All subsequent method calls on client automatically include the Authorization: Bearer era_live_... header.
The exchange-rateapi crate wraps every API endpoint and handles authentication, retries, and response deserialization for you.
Retrieve the most recent exchange rates for one or more target currencies.
use exchange_rateapi::ExchangeRateAPI;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ExchangeRateAPI::new("era_live_YOUR_API_KEY");
// Latest rates for specific symbols
let rates = client.latest("USD", &["EUR", "GBP", "JPY"]).await?;
for r in &rates {
println!("1 USD = {} {}", r.rate, r.target);
}
// Output:
// 1 USD = 0.9215 EUR
// 1 USD = 0.7891 GBP
// 1 USD = 151.42 JPY
Ok(())
}
Convert a specific amount from one currency to another.
// Convert 1000 USD to EUR
let result = client.convert("USD", "EUR", 1000.0).await?;
println!("$1,000 = {} EUR", result.result);
Fetch exchange rates for a specific historical date.
// Get rates for a specific date
let rates = client.for_date("2026-01-15", "USD", &["EUR", "GBP"]).await?;
for r in &rates {
println!("{}: 1 USD = {} {}", r.time, r.rate, r.target);
}
Retrieve rates across a date range.
// Get daily rates over a date range
let series = client.time_series(
"2026-01-01",
"2026-01-31",
"USD",
&["EUR"]
).await?;
for point in &series {
println!("{}: {}", point.date, point.rate);
}
Get all supported currency codes and names.
// Get all supported currency codes
let symbols = client.symbols().await?;
for currency in &symbols.currencies {
println!("{}: {}", currency.code, currency.name);
}
Get the current rate for a single currency pair.
// Single currency pair
let rate = client.get_rate("USD", "EUR").await?;
println!("1 USD = {} EUR", rate.rate);
Fetch historical rate data using preset period strings such as "7d", "30d", "90d", or "1y".
// Get 30-day historical data
let history = client.get_historical_rates("USD", "EUR", "30d").await?;
for point in &history.data {
println!("{}: {}", point.date, point.rate);
}
The SDK returns errors via the ExchangeRateAPIError enum, which covers authentication failures, rate limiting, network issues, and invalid responses.
use exchange_rateapi::{ExchangeRateAPI, ExchangeRateAPIError};
#[tokio::main]
async fn main() {
let client = ExchangeRateAPI::new("era_live_YOUR_API_KEY");
match client.get_rate("USD", "EUR").await {
Ok(rate) => {
println!("1 USD = {} EUR", rate.rate);
}
Err(ExchangeRateAPIError::Unauthorized) => {
eprintln!("Invalid API key. Check your API key.");
}
Err(ExchangeRateAPIError::RateLimited) => {
eprintln!("Rate limit exceeded. Try again later.");
}
Err(ExchangeRateAPIError::NotFound) => {
eprintln!("Currency pair not found.");
}
Err(ExchangeRateAPIError::Network(e)) => {
eprintln!("Network error: {}", e);
}
Err(e) => {
eprintln!("Unexpected error: {}", e);
}
}
}
Customize the client with a custom base URL or request timeout.
use exchange_rateapi::ExchangeRateAPI;
use std::time::Duration;
let client = ExchangeRateAPI::builder("era_live_YOUR_API_KEY")
.base_url("https://exchange-rateapi.com")
.timeout(Duration::from_secs(30))
.build();
[
{
"rate": 0.9215,
"source": "USD",
"target": "EUR",
"time": "2026-05-28T12:00:00Z"
}
]
[
{ "rate": 0.9215, "source": "USD", "target": "EUR", "time": "2026-05-28T12:00:00Z" },
{ "rate": 0.7891, "source": "USD", "target": "GBP", "time": "2026-05-28T12:00:00Z" },
{ "rate": 151.42, "source": "USD", "target": "JPY", "time": "2026-05-28T12:00:00Z" }
]
/api/v1/symbols endpoint.
Explore the Rust SDK resources:
Get your free API key and start fetching exchange rates in Rust in under a minute.
Get Free API Key →