finance-query v3.0.0

World Bank Open Data#

info · Feature flag required

toml
finance-query = { version = "...", features = ["worldbank"] }

World Bank Open Data serves roughly 1,600 development and macro-economic indicators across 200+ economies. It is keyless — no registration, no API key, no environment variable.

It complements FRED, which is US-centric and needs a key: when you want GDP, inflation, population, or trade figures for economies outside the United States, route Capability::ECONOMIC here.

Setup#

rust · no_run feature=worldbank
use finance_query::{Capability, Provider, Providers};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let providers = Providers::builder()
        .route(Capability::ECONOMIC, [Provider::WorldBank])
        .build()
        .await?;
    Ok(())
}

Series Identifiers#

The ECONOMIC capability addresses a series with a single string, so a World Bank series is written as "<COUNTRY>/<INDICATOR>":

rust · no_run feature=worldbank
use finance_query::{Capability, Provider, Providers};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let providers = Providers::builder()
        .route(Capability::ECONOMIC, [Provider::WorldBank])
        .build()
        .await?;

    let gdp = providers.economic("USA/NY.GDP.MKTP.CD").series().await?;

    println!("{}", gdp.title.unwrap_or_default());   // "GDP (current US$) — United States"
    for obs in &gdp.observations {
        println!("{} {:?}", obs.date, obs.value);    // "1960-01-01" Some(543300000000.0)
    }
    Ok(())
}

Omitting the country resolves against the world aggregate:

rust · no_run feature=worldbank
use finance_query::{Capability, Provider, Providers};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let providers = Providers::builder()
        .route(Capability::ECONOMIC, [Provider::WorldBank])
        .build()
        .await?;

    // Equivalent to "WLD/SP.POP.TOTL" — world population
    let world_pop = providers.economic("SP.POP.TOTL").series().await?;
    Ok(())
}

Common Indicators#

Indicator codeDescription
NY.GDP.MKTP.CDGDP (current US$)
NY.GDP.MKTP.KD.ZGGDP growth (annual %)
NY.GDP.PCAP.CDGDP per capita (current US$)
FP.CPI.TOTL.ZGInflation, consumer prices (annual %)
SL.UEM.TOTL.ZSUnemployment (% of total labour force)
SP.POP.TOTLPopulation, total
NE.EXP.GNFS.ZSExports of goods and services (% of GDP)
GC.DOD.TOTL.GD.ZSCentral government debt (% of GDP)

Response Shape#

Results come back as the provider-neutral EconomicSeries, the same type FRED, Alpha Vantage, and Polygon return:

FieldValue from World Bank
series_idThe string you passed in
titleIndicator name and country, e.g. "GDP (current US$) — United States"
unitsThe API's unit field when it is populated (usually empty — most indicators state their unit in the title)
frequency"Annual", "Quarterly", or "Monthly", inferred from the period labels
observationsChronological (oldest first), with value: None for periods the World Bank has no figure for

World Bank period labels (2023, 2023Q1, 2023M04) are normalised to the YYYY-MM-DD start of the period so dates sort and parse like every other provider's.

Fallback Chains#

Because it is keyless, World Bank makes a good last resort behind a keyed provider:

rust · no_run feature=full
use finance_query::{Capability, Provider, Providers};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let providers = Providers::builder()
        .route(Capability::ECONOMIC, [Provider::Fred, Provider::WorldBank])
        .build()
        .await?;
    Ok(())
}

Note that the two use different identifier schemes — a FRED series id is not a World Bank series id — so a chain like this is useful for availability, not for transparently retrying the same identifier.

Rate Limits#

The World Bank publishes no documented quota. The client paces itself at 5 requests/second, and a 429 surfaces as FinanceError::RateLimited.

Next Steps#

built with cargo soothfast docs build source