Elixir HTTP client for the NBP Web API (Narodowy Bank Polski), built on Req. Provides exchange rate tables, single currency rates, and gold prices.

Usage

# Current exchange rate table (A, B or C)
{:ok, [table]} = NbpReq.tables(:a)
table.effective_date #=> ~D[2026-06-12]
table.rates          #=> [%NbpReq.Rate{code: "USD", mid: 3.6767, ...}, ...]

# Rates for a single currency
{:ok, currency} = NbpReq.rates(:a, "USD")
{:ok, currency} = NbpReq.rates(:c, "EUR", last: 10)

# Gold prices (1g, 1000 fineness, PLN)
{:ok, prices} = NbpReq.gold_prices(from: ~D[2026-01-01], to: ~D[2026-01-31])

All functions accept the same query options (at most one of):

OptionMeaning
nonemost recent data
today: truetoday's data (404 before publication)
date: %Date{}data for a specific day
last: nlast n data points
from:/to:inclusive date range (API limit: 367 days)

Errors come back as {:error, :not_found}, {:error, {:bad_request, msg}}, {:error, {:http_error, status, body}}, or {:error, exception} for transport failures.

Extra Req options (e.g. retry: false) can be passed per call via req_options: [...], or globally via application config:

config :nbp_req, req_options: [retry: false]

Installation

Add nbp_req to your list of dependencies in mix.exs:

def deps do
  [
    {:nbp_req, "~> 0.1.0"}
  ]
end

Testing

The test suite stubs HTTP with Req.Test — no network access needed:

mix test