API guide

Gold price API: live XAU, silver and precious metals prices

Fetching the price of gold takes one request. Knowing which gold, in which unit and as of which millisecond is what decides whether your app is right.

On this page
  1. Your first gold price request
  2. Metals symbols and the routes that serve them
  3. Spot gold vs gold futures: which price is this?
  4. Troy ounces, grams and kilograms
  5. The gold/silver ratio in Python
  6. Streaming gold prices over WebSocket
  7. Gold price history for charts and backtests
  8. Choosing a gold price API
  9. Questions

Key takeaways

  • `GET /commodities/quote/XAUUSD` returns the gold bid, ask and a Unix-millisecond timestamp; `XAGUSD`, `XPTUSD` and `XPDUSD` work the same way for silver, platinum and palladium.
  • XAUUSD is a spot reference: gold for immediate delivery. A futures price normally sits above it by the cost of carrying the metal to a later date.
  • XAU is the ISO 4217 code for one troy ounce of gold, 31.1034768 grams. Converting with the 28.35-gram kitchen ounce overstates every gram price by 9.7%.
  • The gold/silver ratio is the gold mid divided by the silver mid. On TickerLayer daily closes it moved between 65.0 and 68.0 in September 2026.
  • Every account starts with 3,000 free REST requests a month. The Commodities feed is priced from $49 a month, and WebSocket streaming comes with paid plans.

A gold price API returns the current price of gold as data your code can use. With TickerLayer, GET /commodities/quote/XAUUSD answers with the best bid, the best ask and a Unix-millisecond timestamp, and the commodities.quotes WebSocket channel streams the same fields as they change. Silver, platinum and palladium use the same routes under XAGUSD, XPTUSD and XPDUSD.

This is the developer version of the question. It covers the request and the response, the spot versus futures distinction, the troy ounce to gram conversion that trips up many jewelry calculators, the gold/silver ratio in a few lines of Python, streaming and history. The metals sit inside the broader commodities API next to crude, gas and grains; energy has its own oil price API guide.

Your first gold price request

Send your key in the x-api-key header and ask for the quote. There is no version segment and no path prefix, and the symbol goes straight into the path:

TerminalShell
curl -sS "https://api.tickerlayer.com/commodities/quote/XAUUSD" \
  -H "x-api-key: $TICKERLAYER_API_KEY"

GET /commodities/quote/XAUUSD

{
  "symbol": "XAUUSD",1
  "bid": 4155.9475,2
  "ask": 4156.4675,3
  "bid_size": 98,4
  "ask_size": 56,
  "timestamp": 17905911296605
}
  1. symbolGold against the US dollar. XAU is the ISO 4217 code for one troy ounce of gold.
  2. bidBest price a buyer is showing. A seller would receive this.
  3. askBest price a seller is showing. The $0.52 gap to the bid is about 1.25 basis points.
  4. bid_sizeSize available at the best bid. Units depend on the market, so compare it with its own history instead of reading it as ounces.
  5. timestampWhen the quote was observed, in Unix milliseconds (UTC): 2026-09-28 10:25:29.660.
A live response captured on 28 September 2026. REST always sends prices as JSON numbers.

Two habits save trouble later. Keep both sides of the quote instead of a single price, because the bid-ask spread is the cheapest liquidity signal you will ever get. And treat timestamp as the moment the price was observed, not the moment your request ran: the gold reference pauses from Friday 17:00 to Sunday 18:00 New York time, so a quote read on Saturday morning is Friday evening’s last one, and your interface should say so.

Metals symbols and the routes that serve them

Metals follow the same pattern as currency pairs: a metal code followed by the quote currency. XAUUSD is gold, XAGUSD silver, XPTUSD platinum and XPDUSD palladium, and COPPERUSD covers the main industrial metal. All five sit in the commodities catalog (GET /commodities/symbols lists the 25 commodity instruments) and share one set of routes:

RouteReturnsUse it for
GET /commodities/quote/XAUUSDBid, ask, sizes, timestampA live price, a spread check
GET /commodities/snapshot/XAUUSDThe quote plus last_price, prev_close, change, change_percentA price tile with the daily move
GET /commodities/agg/XAUUSD/prevThe last completed daily barYesterday’s close without a date range
GET /commodities/agg/XAUUSD/1/day/{from}/{to}OHLC bars, paginatedCharts, backtests, ratios over time
commodities.quotes over WebSocketQuote frames as prices changeTickers, alerts, a live ratio
Swap XAUUSD for XAGUSD, XPTUSD, XPDUSD or COPPERUSD. Full parameters are in the commodities docs.

Spot gold vs gold futures: which price is this?

Search results mix several different "gold prices", and they differ by real money. Spot is the price for gold delivered now (in wholesale practice, settled two business days later). Futures fix a price today for delivery on a later date. Fund shares and perpetual contracts track one of the two, each with its own costs and trading hours. A gold price API that does not say which of these it returns is leaving the hard part to you.

XAUUSD is an indicative spot reference: gold against the dollar, not a particular futures contract. The commodities docs describe these references as indicative pricing, "not a claim about physical delivery, warehouse stocks, or venue-listed futures", which is the right framing for dashboards, analytics and valuation screens.

Futures sit above spot for a mechanical reason. Whoever sells gold for later delivery keeps the metal until then and waits for the cash, so the buyer effectively pays the interest the seller gives up, minus the small fee gold earns when it is lent out, called the lease rate.

F ≈ S × (1 + (r − l) × t)

F
Futures price for delivery in t years.
S
Spot price, for example the XAUUSD mid.
r
Annual interest rate for the same horizon.
l
Annual gold lease rate, usually small.
S = 4,286.74 (XAUUSD close, 25 Sep 2026), r = 4.24% (the 3-month US yield that day), l ignored, t = 0.25: F ≈ 4,332.18, about $45 above spot.

That upward slope is called contango, and it is the normal state of the gold curve. The contango and backwardation explainer shows why it matters to anyone who holds futures or a fund built on them.

FeatureSpot (XAUUSD)FuturesGold ETF sharePerpetual (XAUUSDT)
What it pricesGold for immediate deliveryGold for a fixed later dateA share backed by vaulted metalA contract with no expiry, tied to spot by funding
Expires
Gap to spotNone, it is the referenceCarry: interest minus leaseFees, and one share is a fraction of an ounceBasis, pulled toward zero by funding
When it tradesSunday evening to Friday evening, New York timeNearly around the clock on weekdaysUS stock market hours24/7
TickerLayer route/commodities/quote/XAUUSDNot listed/etfs/quote/USGOLD/perpetuals/quote/XAUUSDT
Perpetuals are a separate feed, and the perpetual composite is a calculated reference, not an executable or settlement price.

The perpetual column deserves its own read: funding, mark prices and the 24/7 schedule are covered in perpetual futures explained.

Troy ounces, grams and kilograms

Gold is priced per troy ounce, and the symbol says so: in ISO 4217, XAU is defined as one troy ounce of gold, just as XAG is one troy ounce of silver. A troy ounce is exactly 31.1034768 grams. The ounce on a kitchen scale, the avoirdupois ounce, is 28.349523125 grams, so the two differ by 9.7%.

That gap is the most common bug in gold calculators. Divide the dollar price by 28.35 instead of 31.10 and every per-gram figure comes out 9.7% too high: $151.21 a gram instead of $137.82 at the 25 September close. The troy ounce explainer covers where the unit comes from and how the other commodities are quoted; the converter below does the arithmetic.

Troy ounce converter

USD
Gram
31.103
Kilogram
0.0311
Ounce (avoirdupois)
1.097
Pound
0.0686
Value of this amount
$4,150.00
Price per gram
$133.43
Price per kilogram
$133,426

1 troy ounce = 31.1034768 g exactly. Precious metals are priced per troy ounce, not per ordinary ounce.

Runs in your browser. Paste the latest XAUUSD mid as the price per troy ounce.
UnitGramsTroy ouncesGold value
1 gram10.0321507$137.82
1 tola11.66380.375$1,607.53
1 avoirdupois ounce28.34950.911458$3,907.18
1 troy ounce31.10351$4,286.74
1 kilogram1,00032.1507$137,821.89
Priced at the XAUUSD daily close of 25 September 2026, $4,286.74. The tola, common in South Asia and the Gulf, is exactly three eighths of a troy ounce.

The gold/silver ratio in Python

The gold/silver ratio is how many ounces of silver buy one ounce of gold. Both metals are quoted in dollars per troy ounce, so the units cancel and the ratio is a plain division of the two mid prices.

mid = (bid + ask) ÷ 2ratio = mid(XAUUSD) ÷ mid(XAGUSD)

mid
Midpoint of the latest quote, so neither side of the spread skews the ratio.
ratio
Ounces of silver per ounce of gold.
4,286.74 ÷ 64.335 = 66.63 on the 25 September 2026 daily closes.

This script pulls gold, silver and EURUSD, then prints the ratio next to the numbers a jewelry or savings app actually shows: per gram, per kilogram, in euros and at 18 karat. It needs Python 3.9 or newer and pip install requests.

gold_price.pyPython
import os

import requests

API = "https://api.tickerlayer.com"
HEADERS = {"x-api-key": os.environ["TICKERLAYER_API_KEY"]}
GRAMS_PER_TROY_OUNCE = 31.1034768


def mid(asset: str, symbol: str) -> float:
    """Midpoint of the latest bid and ask for one symbol."""
    r = requests.get(f"{API}/{asset}/quote/{symbol}", headers=HEADERS, timeout=10)
    if r.status_code == 403:
        raise SystemExit(f"This key has no access to {asset}: see tickerlayer.com/pricing")
    r.raise_for_status()
    q = r.json()
    return (float(q["bid"]) + float(q["ask"])) / 2


gold = mid("commodities", "XAUUSD")    # USD for one troy ounce of gold
silver = mid("commodities", "XAGUSD")  # USD for one troy ounce of silver
eurusd = mid("forex", "EURUSD")        # USD for one euro

per_gram = gold / GRAMS_PER_TROY_OUNCE
print(f"Gold, 1 ozt      {gold:>10.2f} USD")
print(f"Silver, 1 ozt    {silver:>10.3f} USD")
print(f"Gold/silver      {gold / silver:>10.2f}")
print(f"Gold, 1 gram     {per_gram:>10.2f} USD {per_gram / eurusd:>9.2f} EUR")
print(f"Gold, 1 kg       {per_gram * 1000:>10.0f} USD")
print(f"18k gold, 1 gram {per_gram * 0.75:>10.2f} USD")
Output, 28 September 2026 at 10:56 UTC
Gold, 1 ozt         4157.09 USD
Silver, 1 ozt        61.392 USD
Gold/silver           67.71
Gold, 1 gram         133.65 USD    117.52 EUR
Gold, 1 kg           133654 USD
18k gold, 1 gram     100.24 USD

EURUSD is dollars per euro, so a dollar price becomes a euro price by dividing by it. For a pair quoted the other way round, such as USDINR, multiply instead. The 403 branch matters in production: a key without the commodities feed gets a clear refusal, and retrying will not change it.

Gold/silver ratio, daily closes

Ounces of silver per ounce of gold

Ratio of daily closes, UTC days, Monday to Friday, 31 August to 25 September 2026.TickerLayer XAUUSD and XAGUSD daily bars, retrieved 28 September 2026.

Read the ratio as a relative-value gauge, not a signal. Since 1990 it has ranged from roughly 30 to above 120, and it can stay stretched for years. It is useful for normalizing a precious-metals dashboard, or as one column in a correlation matrix. It is not a trade recommendation.

Streaming gold prices over WebSocket

Polling is fine for a price tile. For a ticker, an alert or a live ratio, subscribe instead: one connection, one subscribe message, then quote frames as the price moves. WebSocket access comes with paid plans, and free accounts can request a trial from the dashboard.

Your appTickerLayer stream
  1. Upgrade to wss://stream.tickerlayer.com/?apiKey=the key rides on the URLYour app to TickerLayer stream
  2. {"type":"system","event":"ready"}TickerLayer stream to Your app
  3. subscribe commodities.quotes: XAGUSD, XAUUSDYour app to TickerLayer stream
  4. subscribed, symbols echoed in sorted orderTickerLayer stream to Your app
  5. quote frames, snapshot: truelast known value per symbolTickerLayer stream to Your app
  6. quote frames as prices changeTickerLayer stream to Your app
  7. protocol pingstandard clients answer on their ownTickerLayer stream to Your app
Send nothing before the ready frame. A failed subscribe returns an error frame and leaves the socket open.
gold-stream.mjsJavaScript
// npm install ws
import WebSocket from "ws";

const URL = "wss://stream.tickerlayer.com/?apiKey=" +
  encodeURIComponent(process.env.TICKERLAYER_API_KEY);
const mids = {};

// perMessageDeflate: false keeps per-message compression off on a busy stream.
const ws = new WebSocket(URL, { perMessageDeflate: false });

ws.on("message", (data) => {
  const msg = JSON.parse(data.toString());
  if (msg.type === "system" && msg.event === "ready") {
    ws.send(JSON.stringify({
      action: "subscribe",
      channels: ["commodities.quotes"],
      symbols: ["XAUUSD", "XAGUSD"],
    }));
    return;
  }
  if (msg.type === "error") {
    console.error("subscribe failed:", msg.code, msg.message);
    return;
  }
  if (msg.type !== "quote") return;

  // Commodity frames usually carry numbers, but some arrive as strings.
  mids[msg.symbol] = (Number(msg.bid) + Number(msg.ask)) / 2;
  if (mids.XAUUSD && mids.XAGUSD) {
    const at = new Date(msg.ts).toISOString().slice(11, 23);
    console.log(`${at} UTC  gold ${mids.XAUUSD.toFixed(2)}  ` +
      `silver ${mids.XAGUSD.toFixed(3)}  ratio ${(mids.XAUUSD / mids.XAGUSD).toFixed(3)}`);
  }
});

ws.on("close", (code) => console.log("closed with", code));
ws.on("error", (err) => console.error("socket error:", err.message));
Output (trimmed), 28 September 2026
10:57:20.166 UTC  gold 4157.12  silver 61.380  ratio 67.727
10:57:21.425 UTC  gold 4157.22  silver 61.390  ratio 67.718
10:57:22.404 UTC  gold 4157.51  silver 61.390  ratio 67.723
10:57:23.010 UTC  gold 4157.50  silver 61.386  ratio 67.727

The time to read is ts, in Unix milliseconds; commodity frames mirror it as timestamp. For reconnecting with backoff and resubscribing after a drop, follow the WebSocket market data guide.

Gold price history for charts and backtests

Live quotes are half of a gold price API; the other half is history, which comes from the aggregates route. Bar sizes are 1, 5 and 15 minutes, 1 and 4 hours, and 1 day; dates are UTC YYYY-MM-DD, limit goes up to 5,000, and next_offset goes back in as offset until it comes back null. How far back you can go depends on the plan: two years on Individual and ten on Business, per the pricing page.

TerminalShell
curl -sS "https://api.tickerlayer.com/commodities/agg/XAUUSD/1/day/2026-09-13/2026-09-25?sort=asc" \
  -H "x-api-key: $TICKERLAYER_API_KEY"

XAUUSD daily bars, 14 to 25 September 2026

UTC days, Monday to Friday. Each bar is labelled at midnight UTC of its date.TickerLayer XAUUSD daily bars, retrieved 28 September 2026.

Three details matter when you build on these bars. A daily bar covers a UTC day, so it is not the same number as a London auction price or a futures settlement. Do not read v on the spot metals as market-wide volume: spot gold trades over the counter, with no single tape to count, and the docs note that volume may be 0 or null. And weekend bars are thin, because the reference pauses between Friday and Sunday evening in New York, so filter to Monday through Friday before you compute daily returns.

Choosing a gold price API

What to check before you commit

  • The unit is stated or follows from the symbol: dollars per troy ounce for XAU, never a bare "price".
  • The docs say whether the number is spot, a futures contract or a fund share.
  • Quotes carry both bid and ask, not only a midpoint.
  • Timestamps are Unix milliseconds in UTC and mark the observation, not the response.
  • History uses the same symbols and field names as the live quote.
  • Streaming exists for the day a dashboard outgrows polling.
  • The license fits your use: Individual plans are for personal and research use, commercial use needs Business.
  • Limits are readable from response headers such as X-RateLimit-Limit, and a throttled request comes back as a 429 with Retry-After.

Quality claims should be checkable too. The commodities data-quality page publishes how the metals references compare with an instrument-matched outside reference, under a stated methodology, which is a better basis for a decision than a headline number.

Questions

Is there a free gold price API?

Every TickerLayer account starts with 3,000 free REST requests a month and needs no card. Commodities, including XAUUSD, are sold as their own feed from $49 a month on the Individual plan.

What does XAU/USD mean?

XAU is the ISO 4217 code for one troy ounce of gold, so XAU/USD is the number of US dollars one troy ounce costs. XAG/USD is the same for silver.

Is the gold price per ounce or per troy ounce?

Per troy ounce, which is 31.1034768 grams. The everyday avoirdupois ounce is 28.35 grams, about 9.7% lighter.

What is the difference between spot gold and gold futures?

Spot is the price for delivery now. A futures price fixes the price for a later date and normally sits above spot by the interest cost of carrying the metal, minus the lease rate. XAUUSD is a spot reference.

How do I convert the gold price to grams?

Divide the price per troy ounce by 31.1034768. At $4,286.74 an ounce, one gram is worth $137.82 and one kilogram $137,821.89.

How is the gold/silver ratio calculated?

Divide the gold price by the silver price, both in dollars per troy ounce. Use mid prices, so a bid on one side is never divided by an ask on the other.

Keep reading

Ready to integrate?

Start with the free tier, explore the docs, and connect via REST or WebSocket in minutes.