A bullion inventory is worth its fine gold weight times the gold price. Each item has a gross weight and a fineness, so the job is to compute fine grams, multiply by the price per gram and sum. Two calls cover it: GET /v1/convert gives the live price per gram, and GET /v1/bars gives the daily close for a past date. Both calls were run live on 2 November 2026.
- Fine weight is gross grams times fineness. A 22K coin is 0.9167 fine, 18K is 0.75 and 14K is 0.585.
- A valuation needs a price and a date. Use the live rate for today and the closed daily bar for a past date.
- The result is a market value for your records. The terms of a sale, a dealer's spread and your accounting policy set any other figure.
Value the stock today
The script reads the live gram price once and values four items. The inventory list is an example.
import jsonfrom decimal import Decimal, ROUND_HALF_UPfrom urllib.request import urlopenAPI = "https://api.goldprice.dev"cents = lambda d: d.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)inventory = [ # item, gross grams, fineness ("1 kg cast bar", "1000.00", "0.9999"), ("100 g minted bar", "100.00", "0.9999"), ("1 oz coin (22K)", "33.93", "0.9167"), ("Scrap lot, 14K", "412.60", "0.5850"),]with urlopen(f"{API}/v1/convert?from=XAU&to=USD&amount=1&unit=gram", timeout=10) as r: q = json.load(r)gram = Decimal(q["rate"])total = Decimal(0)print("Valued at", q["timestamp"], "- 24K rate", cents(gram), "USD per gram")for name, grams, fineness in inventory: fine = Decimal(grams) * Decimal(fineness) value = fine * gram total += value print(f"{name:<18} fine {fine:>9.3f} g {cents(value):>12,}")print(f"{'Total':<18} {'':>16} {cents(total):>12,}")Valued at 2026-11-02T11:25:01.624637Z - 24K rate 125.52 USD per gram1 kg cast bar fine 999.900 g 125,502.52100 g minted bar fine 99.990 g 12,550.251 oz coin (22K) fine 31.104 g 3,903.97Scrap lot, 14K fine 241.371 g 30,295.70Total 172,252.44The 1 kg cast bar has a fine weight of 999.900 g and a value of 125,502.52 dollars at that rate. The total for the four items was 172,252.44 dollars.
Value it at a past date
An end-of-month figure needs the close of that day. GET /v1/bars with symbol=XAU-USD-SPOT and interval=1d returns the daily open, high, low and close, newest first. Check is_closed before you use a close. The troy ounce is 31.1034768 grams.
import jsonfrom decimal import Decimal, ROUND_HALF_UPfrom urllib.request import urlopenAPI = "https://api.goldprice.dev"OZ = Decimal("31.1034768") # grams in a troy ouncedef close_on(day: str) -> Decimal: url = f"{API}/v1/bars?symbol=XAU-USD-SPOT&interval=1d&from={day}&to={day}" with urlopen(url, timeout=10) as r: bar = json.load(r)["bars"][0] assert bar["is_closed"] return Decimal(bar["close"])close = close_on("2026-10-30")fine_g = Decimal("1000.00") * Decimal("0.9999")value = (fine_g / OZ * close).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)print(f"2026-10-30 close {close} USD/oz, 1 kg bar: {value:,} USD")2026-10-30 close 3875.245 USD/oz, 1 kg bar: 124,579.56 USDThe last 30 days of daily bars are available without a key. One year of daily bars needs Basic, and history from 1996 needs Plus or Pro.
Rules that keep the numbers clean
- Decimal for money. The API returns prices as strings. Parse them into
Decimaland keep floats out of the sum. - Round once. Sum unrounded values, then round the total. Rounding each line and adding the lines can differ by a cent.
- One rate per report. Fetch the rate once and use it for every line, so the lines agree.
- Record the source. Print the timestamp or the bar date on the report.
- Other currencies. Change
to=USDto one of the 35 supported codes for a local-currency valuation.
Limits
Free and keyless prices are 15 minutes late, and paid plans return live prices. The price is a spot price for gold. It does not include any dealer premium, assay cost, storage cost or tax. For dealer sell and buyback prices in a country, the Basic plan adds the /v1/physical endpoint, with a country code in the path.