US Treasury 30-Year Rate API in Python

US Treasury 30-Year Rate API in Python

You need the US 30-year Treasury yield inside your Python workflows and production services, with reproducible calculations, backtesting windows, and clear effective dates. By the end of this guide, you will query US_TREASURY_30Y from the Interest Rates API, read the latest and historical values, build time series and OHLC views, compute fluctuations and spreads, and estimate simple loan costs using only GET requests authenticated via api_key.

What the US_TREASURY_30Y symbol represents

US_TREASURY_30Y is the US Treasury Yield 30-Year: a benchmark long-term nominal yield in USD. In practice, it is widely used by:

Illustration: US Treasury 30-Year Rate API in Python
  • Mortgage and lending platforms setting long-duration rates and spreads
  • Treasury teams hedging duration and convexity
  • Economists and macro analysts tracking the term structure
  • Fintech apps powering investor dashboards and rate alerts

In the Interest Rates API, US_TREASURY_30Y is categorized as treasury, currency USD, and frequency daily. The value is expressed as a percentage per annum. For example, a JSON value of 5.33 means 5.33% annualized.

All endpoints are available at https://interestratesapi.com/api/v1/ and require GET requests with an api_key query parameter. Learn more at interestratesapi.com and explore models at the MCP. When you are ready to build, Register to get an API key.

How to read values and effective dates

Key response fields you’ll rely on:

  • rates: a map of symbol → numeric rate value (percent per annum)
  • dates: a map of symbol → effective date string (Y-m-d). For daily series, this is the business date for which the value applies.
  • currencies: a map of symbol → ISO currency (e.g., USD)
  • frequencies: where provided, the sampling frequency (e.g., daily)

For daily rates like US_TREASURY_30Y, weekends and US market holidays typically have no new observation. The latest endpoint returns the most recent available business date. Cache responses for short intervals (e.g., a few minutes) to reduce load and to align with publication cadence. Use rate limit headers where provided (X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset) to tune your polling frequency.

Endpoint: Catalogue of available rate symbols

Discover symbols and filter by category, base currency, or provider.

cURL

curl -s "https://interestratesapi.com/api/v1/latest?api_key=YOUR_API_KEY&symbols=SOFR"

Python (requests)

import requests

url = "https://interestratesapi.com/api/v1/symbols"
params = {
"category": "treasury",
"base": "USD",
"api_key": "YOUR_KEY"
}
r = requests.get(url, params=params, timeout=30)
symbols = r.json()

JavaScript (fetch)

const url = "https://interestratesapi.com/api/v1/symbols?category=treasury&base=USD&api_key=YOUR_KEY";
const resp = await fetch(url);
const symbols = await resp.json();

PHP

<?php
$ch = curl_init("https://interestratesapi.com/api/v1/symbols?category=treasury&base=USD&api_key=YOUR_KEY");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
curl_close($ch);
$symbols = json_decode($json, true);
?>

Sample JSON

{
"success": true,
"date": "2026-10-01",
"base": "USD",
"rates": {
"SOFR": 3.87
},
"dates": {
"SOFR": "2026-10-01"
},
"currencies": {
"SOFR": "USD"
},
"base_filter_note": null
}

Use this endpoint to confirm the existence and metadata of US_TREASURY_30Y (category treasury, currency USD, frequency daily) before coding against it.

Endpoint: Latest value

Fetch the most recent available US_TREASURY_30Y value. The date field represents the batch date; dates.US_TREASURY_30Y gives the symbol’s effective business date.

cURL

Python (requests)

import requests

resp = requests.get(
"https://interestratesapi.com/api/v1/latest",
params={"symbols": "US_TREASURY_30Y", "api_key": "YOUR_KEY"},
timeout=30
)
data = resp.json()
thirtyy = data["rates"]["US_TREASURY_30Y"]
effective_date = data.get("dates", {}).get("US_TREASURY_30Y")
currency = data.get("currencies", {}).get("US_TREASURY_30Y")

JavaScript (fetch)

const response = await fetch(
"https://interestratesapi.com/api/v1/latest?symbols=US_TREASURY_30Y&api_key=YOUR_KEY"
);
const data = await response.json();
const rate = data.rates["US_TREASURY_30Y"];
const effDate = data.dates?.["US_TREASURY_30Y"];
const ccy = data.currencies?.["US_TREASURY_30Y"];

PHP

<?php
$u = "https://interestratesapi.com/api/v1/latest?symbols=US_TREASURY_30Y&api_key=YOUR_KEY";
$ch = curl_init($u);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$out = curl_exec($ch);
curl_close($ch);
$data = json_decode($out, true);
$rate = $data["rates"]["US_TREASURY_30Y"] ?? null;
$effDate = $data["dates"]["US_TREASURY_30Y"] ?? null;
$ccy = $data["currencies"]["US_TREASURY_30Y"] ?? null;
?>

Sample JSON

Interpretation: rates.US_TREASURY_30Y is the percent value; dates.US_TREASURY_30Y is the effective business date; currencies map confirms USD.

Official sample (format illustration)

The following official sample demonstrates the exact structure of the latest endpoint. Values are illustrative and pertain to SOFR; keep your integration focused on US_TREASURY_30Y.

Endpoint: Historical value on a specific date

Get the observed US_TREASURY_30Y rate for a given date. For monthly series, the API uses the last available day of that month; US_TREASURY_30Y is daily, so request the specific date.

cURL

Python (requests)

import requests

params = {"date": "2025-06-15", "symbols": "US_TREASURY_30Y", "api_key": "YOUR_KEY"}
r = requests.get("https://interestratesapi.com/api/v1/historical", params=params, timeout=30)
hist = r.json()
rate_30y = hist["rates"]["US_TREASURY_30Y"]
asof = hist["date"]

JavaScript (fetch)

const url = new URL("https://interestratesapi.com/api/v1/historical");
url.searchParams.set("date", "2025-06-15");
url.searchParams.set("symbols", "US_TREASURY_30Y");
url.searchParams.set("api_key", "YOUR_KEY");
const res = await fetch(url.toString());
const hist = await res.json();

PHP

<?php
$q = http_build_query([
"date" => "2025-06-15",
"symbols" => "US_TREASURY_30Y",
"api_key" => "YOUR_KEY"
]);
$u = "https://interestratesapi.com/api/v1/historical?$q";
$ch = curl_init($u);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$out = curl_exec($ch);
curl_close($ch);
$hist = json_decode($out, true);
?>

Sample JSON

Use this for one-off point-in-time queries, valuation dates, or backfills.

Endpoint: Time series between two dates

Pull a daily series of US_TREASURY_30Y between start and end dates. Missing days (weekends/holidays) are omitted; index your time series by business dates.

cURL

Python (requests)

import requests
import pandas as pd

params = {
"start": "2025-10-04",
"end": "2026-10-04",
"symbols": "US_TREASURY_30Y",
"api_key": "YOUR_KEY"
}
resp = requests.get("https://interestratesapi.com/api/v1/timeseries", params=params, timeout=60)
js = resp.json()
series = js["rates"]["US_TREASURY_30Y"]
df = pd.Series(series, name="US_TREASURY_30Y").sort_index()

JavaScript (fetch)

const url = "https://interestratesapi.com/api/v1/timeseries?start=2025-10-04&end=2026-10-04&symbols=US_TREASURY_30Y&api_key=YOUR_KEY";
const resp = await fetch(url);
const js = await resp.json();
const series = js.rates["US_TREASURY_30Y"];

PHP

<?php
$u = "https://interestratesapi.com/api/v1/timeseries?start=2025-10-04&end=2026-10-04&symbols=US_TREASURY_30Y&api_key=YOUR_KEY";
$ch = curl_init($u);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$out = curl_exec($ch);
curl_close($ch);
$data = json_decode($out, true);
$series = $data["rates"]["US_TREASURY_30Y"] ?? [];
?>

Sample JSON

Note the nested map under rates.US_TREASURY_30Y keyed by ISO dates. This is ideal for charting and risk modeling.

Endpoint: Fluctuation (change statistics)

Summarize the change in US_TREASURY_30Y across a window. The API returns start/end values, absolute and percentage change, and the high/low over the period.

cURL

Python (requests)

import requests

params = {
"start": "2025-10-04",
"end": "2026-10-04",
"symbols": "US_TREASURY_30Y",
"api_key": "YOUR_KEY"
}
res = requests.get("https://interestratesapi.com/api/v1/fluctuation", params=params, timeout=30)
fl = res.json()
stats = fl["rates"]["US_TREASURY_30Y"]
change = stats["change"]
change_pct = stats["change_pct"]

JavaScript (fetch)

const u = "https://interestratesapi.com/api/v1/fluctuation?start=2025-10-04&end=2026-10-04&symbols=US_TREASURY_30Y&api_key=YOUR_KEY";
const r = await fetch(u);
const fl = await r.json();
const stats = fl.rates["US_TREASURY_30Y"];

PHP

<?php
$u = "https://interestratesapi.com/api/v1/fluctuation?start=2025-10-04&end=2026-10-04&symbols=US_TREASURY_30Y&api_key=YOUR_KEY";
$ch = curl_init($u);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$out = curl_exec($ch);
curl_close($ch);
$fl = json_decode($out, true);
$stats = $fl["rates"]["US_TREASURY_30Y"] ?? null;
?>

Sample JSON

Interpretation: change is in percentage points; change_pct is the relative percent change from start_value to end_value. Use this to power performance tiles and alerting.

Endpoint: OHLC (candlestick-style aggregates)

Request open, high, low, close computed from daily US_TREASURY_30Y observations for a period (monthly by default, also supports weekly or quarterly). This is generated on the fly from daily data.

cURL

Python (requests)

import requests

params = {
"symbols": "US_TREASURY_30Y",
"period": "monthly",
"start": "2025-10-04",
"end": "2026-10-04",
"api_key": "YOUR_KEY"
}
resp = requests.get("https://interestratesapi.com/api/v1/ohlc", params=params, timeout=30)
ohlc = resp.json()["rates"]["US_TREASURY_30Y"]
first_bar = ohlc[0] if ohlc else None

JavaScript (fetch)

const u = "https://interestratesapi.com/api/v1/ohlc?symbols=US_TREASURY_30Y&period=monthly&start=2025-10-04&end=2026-10-04&api_key=YOUR_KEY";
const res = await fetch(u);
const o = await res.json();
const bars = o.rates["US_TREASURY_30Y"];

PHP

<?php
$u = "https://interestratesapi.com/api/v1/ohlc?symbols=US_TREASURY_30Y&period=monthly&start=2025-10-04&end=2026-10-04&api_key=YOUR_KEY";
$ch = curl_init($u);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$out = curl_exec($ch);
curl_close($ch);
$ohlc = json_decode($out, true);
$bars = $ohlc["rates"]["US_TREASURY_30Y"] ?? [];
?>

Sample JSON

Use data_points to validate completeness for the aggregation window. Open/close correspond to the first/last business day in the period.

Endpoint: Convert (simple loan interest comparison)

Compare the simple total interest cost of a notional loan priced at US_TREASURY_30Y (latest value) versus another benchmark. This endpoint uses a simple interest model, not amortization.

cURL

Python (requests)

import requests

params = {
"from": "US_TREASURY_30Y",
"to": "ECB_MRO",
"amount": 100000,
"term_months": 12,
"api_key": "YOUR_KEY"
}
r = requests.get("https://interestratesapi.com/api/v1/convert", params=params, timeout=30)
cmp = r.json()
spread = cmp["difference"]["rate_spread"]

JavaScript (fetch)

const url = "https://interestratesapi.com/api/v1/convert?from=US_TREASURY_30Y&to=ECB_MRO&amount=100000&term_months=12&api_key=YOUR_KEY";
const res = await fetch(url);
const cmp = await res.json();

PHP

<?php
$u = "https://interestratesapi.com/api/v1/convert?from=US_TREASURY_30Y&to=ECB_MRO&amount=100000&term_months=12&api_key=YOUR_KEY";
$ch = curl_init($u);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$out = curl_exec($ch);
curl_close($ch);
$cmp = json_decode($out, true);
?>

Sample JSON

difference.rate_spread is the absolute percentage-point spread. This endpoint is useful for quick what-if comparisons across benchmarks.

Practical engineering notes: business days, caching, and errors

  • Publication frequency: US_TREASURY_30Y is daily. Expect new observations on US business days; weekends and US market holidays usually have no new value.
  • Effective date: Use the dates map per symbol to drive UI labels like “As of YYYY-MM-DD.”
  • Caching: Cache latest and historical responses for short periods to minimize repeated identical requests and smooth any upstream publishing delays.
  • Rate limits: Respect X-RateLimit-* headers and back off or queue jobs when X-RateLimit-Remaining nears zero. On 429, check Retry-After.
  • Timeouts: Set client timeouts (e.g., 30–60s) and implement retry with jitter on transient network errors. Keep retries idempotent since all endpoints are GET.
  • Error handling: Parse the standardized error shape:
    • 401: Missing/invalid api_key
    • 403: Account without active plan
    • 404: No symbols matched or no data in range (may include details with available ranges)
    • 422: Validation error (e.g., wrong date format)
    • 429: Request quota exhausted

If you need to explore the broader model catalog, check the MCP. For production keys, Register and store your key securely.

Compute spreads and payments from returned values

US_TREASURY_30Y is returned as an annual percentage. Common calculations:

  • Spread versus another rate (percentage points): spread_pp = r1 - r2
  • Relative spread in percent: spread_pct = (r1 - r2) / r2 × 100 (if r2 ≠ 0)
  • Simple monthly interest on amount A over m months at annual rate r%: interest = A × (r / 100) × (m / 12)
  • Amortized monthly payment for principal P at annual rate r% over n months:
    • Convert to monthly rate i = (r / 100) / 12
    • Payment = P × i / (1 - (1 + i)^(-n))

Do not hard-code values; always read the latest or historical value from the API and then apply the formulas. Remember that the convert endpoint uses a simple interest model; use your own amortization logic when required.

Real-world integration patterns

  • Interest rate dashboards: Combine /latest with /timeseries for sparklines and trend panels. Use dates to display “As of” annotations.
  • Mortgage pricing: Pull US_TREASURY_30Y daily, add a fixed spread, and compute amortized payments with your underwriting rules.
  • Risk models: Fetch /timeseries for rolling windows, compute duration exposure measures using daily changes, and validate aggregates with /ohlc.
  • Macro research: Use /fluctuation to summarize moves across policy cycles or tightening phases, and cross-compare with central bank symbols if needed.

All requests are GET and authenticated with the api_key parameter; see interestratesapi.com for platform details and Get started with Interest Rates API when you are ready to build.

Troubleshooting examples

  • Validation error (422): Ensure dates are in Y-m-d. Example: 2026-10-04
  • No data (404): Check the details field for available ranges, or adjust start/end to the series coverage
  • Mismatched currency filter: If you set base=USD, symbols with non-USD currency will be filtered out; omit base or pass the correct one
  • Quota exceeded (429): Reduce polling, increase cache TTL, and respect Retry-After before retrying

Quick reference: Endpoint summary for US_TREASURY_30Y

  • /symbols — discover metadata and confirm symbol existence
  • /latest — most recent daily value with effective date and currency
  • /historical — value on a specific date
  • /timeseries — daily series across a date range
  • /fluctuation — summary stats (start/end, change, high/low)
  • /ohlc — aggregated open/high/low/close bars (weekly/monthly/quarterly)
  • /convert — simple loan interest comparison between two benchmarks

FAQ

How often is US_TREASURY_30Y updated?
It is a daily series. Expect new observations on US business days; there will typically be no new value on weekends and US market holidays.

What units are returned?
Rates are returned as percentages per annum. For instance, 5.33 represents 5.33%.

Which date should I display to users?
Display the per-symbol date from the dates map (e.g., dates.US_TREASURY_30Y) to show the effective business date for the value.

Can I get monthly OHLC bars for charting?
Yes. Use /ohlc with period=monthly. The response includes open, high, low, close, and data_points per bar computed from daily observations.

How do I authenticate?
Append your key as the api_key query parameter to every GET request. Do not use headers for authentication.

Build your US_TREASURY_30Y integration now: browse the Interest Rates API MCP, then Register and Get started with Interest Rates API to obtain your api_key and ship your Python code.

Ready to get started?

Get your API key and start validating bank data in minutes.

Get API Key

Related posts