Gold price history at a glance
Approximate market levels in nominal US dollars per troy ounce at each turning point:
| Year | Price | What happened |
|---|---|---|
| 1971 | $35–44 | The US ends dollar convertibility; the fixed $35 peg dissolves and gold trades freely. |
| 1980 | ~$850 | Double-digit inflation and oil shocks drive the spike that remained the inflation-adjusted record for decades. |
| 1999 | ~$250 | The bottom of a 20-year bear market amid central-bank selling and an equity boom. |
| 2011 | ~$1,895 | Post-financial-crisis peak during quantitative easing and the European debt crisis. |
| 2020 | ~$2,070 | Pandemic stimulus and negative real yields set a new nominal high. |
| 2024 | $2,700+ | Record central-bank buying and rate-cut expectations power a breakout. |
| 2026 | $4,000+ | The rally extends; gold trades above $4,000 for the first time. |
The recurring drivers behind those moves: real interest rates (gold pays no yield, so it shines when inflation-adjusted rates fall), the strength of the US dollar, central-bank reserve buying, and crisis demand for a haven.
Prerequisites
To pull the data yourself you need three things:
- Python 3.8 or newer.
- The
requestslibrary, plusmatplotlibif you want the chart step. - A free API Ninjas API key — issued instantly, no credit card. If you already have an account, it's on your profile page.
pip install requests matplotlibStep 1: Get the current price
/v1/goldprice takes no parameters — just the API key header:
import requests
response = requests.get(
'https://api.api-ninjas.com/v1/goldprice',
headers={'X-Api-Key': 'YOUR_API_KEY'},
timeout=10,
)
response.raise_for_status()
gold = response.json()
print(f"Gold: ${gold['price']:,} per troy ounce")
# Gold: $4,305.6 per troy ounce{
"price": 4305.6,
"unit": "troy_ounce",
"currency_unit": "USD",
"updated": 1786044078
}The price is USD per troy ounce and updated is the Unix timestamp of the quote. It tracks COMEX gold futures — the benchmark price the headlines quote.
Step 2: Pull historical candles
/v1/goldpricehistorical returns OHLCV candles — open, high, low, close, volume — newest first, so sort by time before doing anything else:
import os
import requests
session = requests.Session()
session.headers['X-Api-Key'] = os.environ.get('API_NINJAS_KEY', 'YOUR_API_KEY')
candles = session.get(
'https://api.api-ninjas.com/v1/goldpricehistorical',
params={'period': '1d'},
timeout=10,
).json()
candles.sort(key=lambda c: c['time']) # API returns newest first
print(f"{len(candles)} daily candles, latest close ${candles[-1]['close']:,}")[
{
"open": 4302.1,
"low": 4301.8,
"high": 4309.7,
"close": 4306.2,
"volume": 898,
"time": 1786028400
},
{
"open": 4306,
"low": 4299.5,
"high": 4308,
"close": 4302,
"volume": 2215,
"time": 1786024800
}
]Three optional parameters shape the series:
| Parameter | Values | Meaning |
|---|---|---|
period | 1m … 1d | Candle interval: 1m, 5m, 15m, 30m, 1h (default), 4h, 1d. |
start | Unix seconds | Start of the range. |
end | Unix seconds | End of the range. |
For a specific window, convert dates to timestamps:
import time
from datetime import datetime, timezone
start = int(datetime(2026, 1, 1, tzinfo=timezone.utc).timestamp())
end = int(time.time())
candles = session.get(
'https://api.api-ninjas.com/v1/goldpricehistorical',
params={'period': '1d', 'start': start, 'end': end},
timeout=10,
).json()Step 3: Chart the history
With sorted candles, a line chart of closes is a dozen lines of matplotlib:
from datetime import datetime, timezone
import matplotlib.pyplot as plt
candles.sort(key=lambda c: c['time'])
dates = [datetime.fromtimestamp(c['time'], tz=timezone.utc) for c in candles]
closes = [c['close'] for c in candles]
plt.figure(figsize=(10, 5))
plt.plot(dates, closes)
plt.title('Gold price history (USD per troy ounce)')
plt.ylabel('Close (USD)')
plt.grid(alpha=0.3)
plt.tight_layout()
plt.savefig('gold_price_history.png')Step 4: Export to CSV
For Excel, Google Sheets, or a database load, write the candles straight out:
import csv
candles.sort(key=lambda c: c['time'])
with open('gold_price_history.csv', 'w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=['time', 'open', 'high', 'low', 'close', 'volume'])
writer.writeheader()
writer.writerows(candles)
print(f'Wrote {len(candles)} rows')Where to go from here
The same request pattern covers the rest of the metals and energy complex: the Commodity Price API for silver, platinum, copper, and wheat, and the Oil Price API for WTI and Brent. For equities, the Stock Price API uses the identical OHLCV historical shape. The complete script is below.