Gold (XAU) Historical Price API
You need to backfill and chart gold prices, compute day-over-day changes, and trigger alerts when gold moves beyond a threshold. By the end of this guide, you’ll pull the latest XAU quote, understand how to read USD-per-ounce vs ounce-per-USD, and plan a robust pipeline to fetch historical time series for gold using Indices-API.
What you’re building: reliable gold time series with XAU
We’ll focus on the XAU symbol and how to turn the API’s base-USD rates into a USD-per-troy-ounce price series suitable for charting, analytics, and alerts. We’ll use:
- Latest quotes to seed dashboards and sanity-check new data.
- Time-series (daily) to backfill and keep a complete history for analysis.
- Optional fluctuation to compute rolling changes without writing your own diffs.
Before coding, confirm that XAU is the symbol you expect for gold in your application. Some venues use XAU for “1 troy ounce of gold,” while others use “XAU” to mean the PHLX Gold/Silver Index. Always verify the exact code you need on the Indices-API Supported Symbols page.
Understand the units: base is USD, XAU is ounces-per-USD
Indices-API responses are quoted relative to a base currency. In the gold response shown below, base is USD and the rates map includes both XAU and USDXAU:
- rates.XAU is the number of troy ounces per 1 USD (XAU per USD).
- rates.USDXAU is the number of USD per 1 troy ounce (USD per XAU), i.e., the familiar “gold price in USD.”
- rates.USD is 1 by definition, since base is USD.
| Symbol | Meaning | How to use |
|---|---|---|
| XAU | Troy ounces of gold per 1 USD (XAU per USD) | Invert for USD/oz: USD per XAU = 1 / XAU |
| USDXAU | USD per 1 troy ounce of gold (USD per XAU) | Use directly for the spot-like price per ounce |
| USD | Base currency (always 1 when base is USD) | Useful as a consistency check |
If your symbol lookup shows a different code or naming (for example, a venue-specific convention for gold), select that code from the Indices-API Supported Symbols list and adapt the samples accordingly.
Pull the latest gold price (XAU) over HTTP
We’ll use the Latest endpoint to fetch the current rates, then we’ll read the USD-per-ounce figure from rates.USDXAU for chart labeling, valuations, and alerts. Replace YOUR_API_KEY with your key from the registration flow.
curl -s "https://indices-api.com/api/latest?access_key=YOUR_API_KEY"
Sample response (copy/paste exact):
{"data":{"success":true,"timestamp":1795048800,"date":"2026-11-19","base":"USD","rates":{"XAU":0.0033219280470385,"USD":1,"USDXAU":301.03000000000014}}}
Field guide: what you’ll actually use
- data.success: Boolean status flag for the call.
- data.timestamp: Unix epoch seconds for the quote time (UTC). Use this to align candles and caches.
- data.date: Calendar date string (YYYY-MM-DD) for the quote.
- data.base: Base currency for all rates in this payload (USD here).
- data.rates.XAU: Ounces of gold per 1 USD.
- data.rates.USDXAU: USD per 1 troy ounce of gold (directly usable “price”).
For more on endpoints and parameters beyond “latest,” see the Indices-API Documentation. If you need coverage scope or market-change policies, consult MCP.
Minimal Python: get USD-per-ounce (USDXAU) and ounces-per-USD (XAU)
This snippet calls the same Latest endpoint, extracts both views of the price, and keeps the timestamp so you can roll it into your cache key or candle alignment logic.
import os
import requests
from datetime import datetime, timezone
API_KEY = os.getenv("INDICES_API_KEY", "YOUR_API_KEY")
URL = "https://indices-api.com/api/latest"
resp = requests.get(URL, params={"access_key": API_KEY}, timeout=10)
resp.raise_for_status()
payload = resp.json()["data"]
ts = payload["timestamp"] # epoch seconds (UTC)
as_of = datetime.fromtimestamp(ts, tz=timezone.utc)
base = payload["base"]
rates = payload["rates"]
# Ounces per USD (XAU per 1 USD):
xau_per_usd = rates.get("XAU")
# USD per ounce (1 XAU):
usd_per_oz = rates.get("USDXAU")
if usd_per_oz is None and xau_per_usd:
usd_per_oz = 1.0 / xau_per_usd
print(f"As of {as_of.isoformat()} base={base}")
print(f"XAU per USD: {xau_per_usd}")
print(f"USD per ounce: {usd_per_oz}")
Note: If your downstream systems expect USD per ounce, prefer rates.USDXAU directly. Only invert rates.XAU when USDXAU is not included.
Backfill a historical series for gold
For historical charts and research signals, use the daily Time-series endpoint to pull a contiguous range of dates. You’ll specify a start_date and end_date and parse the same fields: base, rates, date, and optionally timestamp if present in that endpoint’s schema.
- Do not set end_date to today; request up to yesterday to avoid partial-day data. Many feeds finalize and roll close-of-day values with a small delay.
- Gold prices may not print on weekends and public holidays. Plan for gaps or flat carry of prior close on non-trading days depending on your display policy.
- For long backfills, fetch in smaller windows to simplify retries and caching. Store by date to de-duplicate easily.
Refer to the parameter names and date format in the Documentation. When in doubt about the correct symbol for gold in your context, re-check the Symbols page before running large backfills.
Transforming series to USD per ounce
Historical responses will return rates relative to base=USD. For each day:
- If rates.USDXAU is available, use it directly as gold’s USD price.
- Else, compute USD per ounce as 1.0 / rates.XAU.
This normalization ensures your chart and alerts report values in the conventional USD/oz format.
Optional: day-over-day change with fluctuation
If you need quick percent/vs-change over a window, the Fluctuation endpoint provides start_rate, end_rate, absolute change, and change_pct for the period you select. It’s convenient for alerting or summary widgets when you don’t want to roll your own delta on the client.
- Set start_date and end_date to the desired window. As with time series, don’t use today as end_date.
- Changes are computed with the same base and symbol units as in latest/time series.
See exact parameters and response schema in the Documentation.
Practical details that will save you time
- Base currency: The examples here use base="USD". All rates are quoted relative to this base. Confirm base in each response; do not assume it.
- Units: rates.XAU is XAU per USD (ounces per 1 USD). rates.USDXAU is USD per XAU (USD per ounce). Choose the one that matches your UI and alert logic.
- Timestamps and timezone: timestamp is Unix epoch seconds in UTC. Use this to align candles, avoid mixing sessions, and control caches.
- Trading days vs weekends: Precious metals often observe exchange/OTC holiday schedules. Expect no updates or flat data on weekends/holidays. Design your charts to gracefully span gaps or carry last-known values.
- Update frequency: The Latest endpoint updates periodically depending on plan tier (for example, every 60 minutes or every 10 minutes). Don’t poll faster than the update cadence.
- Caching: Cache latest responses at least until a new timestamp appears. For server-side caches (CDN/app-layer), key by date and symbol to dedupe historical requests.
- end_date cannot be today: For historical/time-series/fluctuation, set end_date to the latest completed trading date (yesterday in UTC) to avoid partial prints.
- Error handling: Treat success=false or missing fields as non-fatal; retry with backoff. Log the timestamp and date for all stored rows.
- Symbol verification: Because “XAU” can also name the PHLX Gold/Silver Index in some contexts, confirm your intended code on the Symbols page before production roll-out.
From latest to a full gold chart: a simple workflow
- Get an API key: use the 7-day trial on the PRO plan ($49.99/mo) to evaluate throughput and data coverage.
- Seed your dashboard: call Latest, store timestamp, and display rates.USDXAU with a note of the quote time (UTC).
- Backfill history: run the Time-series endpoint in daily windows to fill your database. Normalize to USD per ounce for consistent charts.
- Keep current: schedule a job to refresh the latest price on the plan cadence. If the timestamp hasn’t advanced, keep the cached value.
- Compute deltas: either use the Fluctuation endpoint or compute differences from your stored series to power “1D/1W/1M” change badges.
Operational notes for production
- Idempotent writes: Upserts keyed by (symbol, date) reduce duplicate rows when you retry.
- Backfill windows: Chunk by month or quarter. If a request fails, retry the small window rather than the full range.
- Validation: For each day, assert the base is USD and that either XAU or USDXAU is present; flag otherwise.
- Migrations: When adding new symbols or switching to a different gold code, write a migration that keeps both raw (as returned) and normalized (USD per oz) values.
Helpful references
- Product and key management: Register for a free trial key.
- Endpoint parameters and response schemas: Documentation
- Symbol verification, including XAU variants: Symbols
- Market coverage and policies: MCP
- Context on gold benchmarks: LBMA Prices and CME Gold Futures for external reference (not required for API use).
FAQ
How do I get the “gold price in USD” from the response?
Use rates.USDXAU directly when available. If not present, compute 1.0 / rates.XAU to convert ounces-per-USD to USD-per-ounce.
Why does a weekend date show the same value as Friday?
Gold markets may be inactive on weekends/holidays. Your historical fetch will either return no print or carry-forward behavior depending on coverage and timing. Treat non-trading days carefully and avoid setting end_date to today.
What timezone should I use?
timestamps are Unix epoch seconds in UTC. Align your candles and caches on UTC boundaries to avoid partial-day issues across regions.
How frequently do “latest” quotes update?
The update cadence depends on your plan tier (for example, every 60 minutes or every 10 minutes). Poll at or slower than the cadence and cache until timestamp advances.
Is “XAU” the gold ounce or the PHLX Gold/Silver Index?
It can mean either depending on the venue. Confirm the exact symbol you need on the Symbols page before backfilling or deploying to production.
Get your key and ship your gold chart
Spin up your integration now: create a key with a 7-day trial on PRO ($49.99/mo), call the Latest endpoint to validate XAU/USDXAU in your environment, and then roll into a time-series backfill for charts and alerts. Start here: Register.