Gold Price API

The Gold Price API provides access to real-time gold futures price in the Chicago Mercantile Exchange (CME).

For other commodity prices, please check out our Commodity Price API.

/v1/goldprice GET

https://api.api-ninjas.com/v1/goldprice

Returns the current gold futures price in USD. For historical gold futures prices, see /v1/goldpricehistorical.


Parameters

None

Headers

  • X-Api-Key  required

    API Key associated with your account.

Sample Request Live Demo!

https://api.api-ninjas.com/v1/goldprice

Headers

X-Api-KeyLog in or sign up to get your API Key

Sample Response

JSON
1 2 3 4 { "price": 2310.1, "updated": 1714769998 }

Code Examples

1 2 3 4 5 6 7 import requests api_url = 'https://api.api-ninjas.com/v1/goldprice' response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'}) if response.status_code == requests.codes.ok: print(response.text) else: print("Error:", response.status_code, response.text)

If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.

/v1/goldpricehistorical GETPremium Only

https://api.api-ninjas.com/v1/goldpricehistorical

Returns historical gold futures price data in OHLCV (Open, High, Low, Close, Volume) format. The data is returned in descending order (most recent first), and all prices are in USD.


Parameters

  • period  optional

    Time interval between data points. Valid values are: 1m, 5m, 15m, 30m, 1h, 4h. Default is 1h.

  • start  optional

    Start timestamp in Unix format. If not provided, defaults to 24 hours ago.

  • end  optional

    End timestamp in Unix format. If not provided, defaults to current time.

Headers

  • X-Api-Key  required

    API Key associated with your account.

Historical Price Sample Request

https://api.api-ninjas.com/v1/goldpricehistorical?period=1h&start=1706000000&end=1706302801

Historical Price Sample Response

JSON
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 [ { "open": 2624.7, "low": 2621.4, "high": 2626.3, "close": 2622.3, "volume": 1640, "time": 1732582800 }, { "open": 2626.5, "low": 2617.1, "high": 2626.5, "close": 2624.7, "volume": 2986, "time": 1732579200 }, { "open": 2630.2, "low": 2625.2, "high": 2631.6, "close": 2626.6, "volume": 1191, "time": 1732575600 }, "..." ]