Gold at $3,997.92 and silver at $54.02 a troy ounce give a gold-silver ratio of 74.0. The ratio is the gold price divided by the silver price, both in US dollars per troy ounce.
Calculate the ratio with the API
The calculation needs a gold price and a silver price. Narwhal returns both through its commodity spot API, with each price in troy_ounce. The result means how many ounces of silver one ounce of gold buys. Keep gold as the numerator and silver as the denominator throughout the calculation.
- Get your API key Get a free API key and keep it in the
NARWHAL_API_KEYenvironment variable. The script reads that variable and sends the key in theAuthorization: Bearer YOUR_KEYheader. - Select the gold and silver prices Use
GET /v1/commodities/spot/XAU/USDfor gold andGET /v1/commodities/spot/XAG/USDfor silver. These are separate requests, and both prices use US dollars per troy ounce, so the values have the same currency and unit. - Divide gold by silver Run the Python script to read each response's
priceand divide gold by silver. Its output includes both input prices alongside the ratio, so you can read the calculation with its inputs.Python, the gold-silver ratioimport os import requests H = {"Authorization": f"Bearer {os.environ['NARWHAL_API_KEY']}"} API = "https://api.narwhalapi.com/v1/commodities/spot" def price(code): return float(requests.get(f"{API}/{code}/USD", headers=H, timeout=10).json()["price"]) gold, silver = price("XAU"), price("XAG") print(f"gold {gold:.2f} / silver {silver:.4f} = {gold / silver:.2f}") - Read the result For the 24 October 2026 example, the output is
gold 3996.00 / silver 53.9171 = 74.11. Read the ratio as ounces of silver per ounce of gold; the two input prices are amounts in US dollars per troy ounce.
In the script, price("XAU") reads gold and price("XAG") reads silver. The function adds each metal code and /USD to the commodity spot URL, then reads the price field from the JSON response as a number. The final line prints the gold price, the silver price and their quotient together. The script displays the ratio to two decimal places, gold to two and silver to four. These formats apply to the printed output; the division uses the price values read from the responses. Use that quotient wherever your calculation needs the gold-silver ratio; keep the individual prices when you need to refer back to the inputs.
Calculate it in a sheet or read it online
Open the gold-silver ratio page to read the ratio on the website. That is the direct route when you want to read the figure without making the two API requests yourself. You can also put the gold and silver prices into a spreadsheet and do the division there.
Put the gold price in B1 and the silver price in B2, both in USD per troy ounce. Enter the formula in the cell where you want the ratio, with labels beside the input cells to identify each metal.
=B1/B2When you enter another pair of prices, replace the gold input in B1 and the silver input in B2. Leave the formula as gold divided by silver. Use the same pair of prices in the sheet and in an API calculation if you want to compare the results. The spreadsheet formula takes its inputs from those cells, while the Python script takes its inputs from the spot responses.
Which option to use when
| Situation | Best option | Why |
|---|---|---|
| Read the ratio | The gold-silver ratio page | Read the figure on the website |
| Build a chart or model | Daily bars for gold and silver | Divide prices on matching dates |
| Set up an alert | Store and compare the ratio | Compare the stored ratio for an alert |
For a chart or model, use GET /v1/commodities/spot/XAU/USD/bars and GET /v1/commodities/spot/XAG/USD/bars. Set interval=1d and supply the required start and end dates for both metals. Request the same date range for gold and silver, then divide gold by silver bar by bar on matching dates. Each pair supplies the inputs for that date's ratio in your chart or model. Keep the gold series in the numerator throughout the history, just as you do for the spot calculation. For an alert, store the calculated ratio and compare it as described in the commodity price alert how-to.
Do I need the same time for both prices?
Yes, use prices from the same time, because different times add noise to the ratio. Request both spot prices at once, or use daily bars on the same dates. When you build a ratio history, pair each gold bar with the silver bar for that date before you divide.
For a spot ratio, make the gold and silver requests together. For a daily series, use the dates to pair the inputs: the gold price for a date belongs with the silver price for that same date. Apply the division to each matched pair.
Why not use silver in another currency?
The ratio is currency-neutral only when both prices are in the same currency. Use USD for both requests in this calculation. A gold price in USD and a silver price in another currency do not meet that condition, even if both prices are quoted per troy ounce. The currency and the unit must match.
What does the ratio mean on the Free plan?
On the Free plan, the ratio is an end-of-day figure because spot commodity prices use the previous UTC day's close. Interpret the gold and silver inputs on that basis when you read the result. The division stays the same: the gold close divided by the silver close, with both prices in USD per troy ounce.
Worked example: calculate the gold-silver ratio
On 24 October 2026, the example uses gold at $3,996.00 and silver at $53.9171 per troy ounce. Start with the gold price, then divide it by the silver price. Retain the supplied silver price in the calculation and display the resulting ratio to the precision used by the Python script.
| Step | On 24 October 2026 |
|---|---|
| Gold price | $3,996.00 per troy ounce |
| Silver price | $53.9171 per troy ounce |
| Divide gold by silver | 3,996.00 / 53.9171 = 74.11 |
| Read the ratio | One ounce of gold buys about 74 ounces of silver |
Published .
