Commodity Price API

The Commodity Price API provides access to real-time commodity prices for dozens of commonly-traded commodities in major exchanges (CME, NYMEX, etc.).

/v1/commodityprice GET

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

Returns the current price information for any given commodity. All quoted prices are in USD.

For historical commodity prices, see /v1/commoditypricehistorical.


Parameters

  • name  required

    Name of commodity. The supported values are:

    ValueDescriptionPremium Only
    goldGold FuturesNo
    soybean_oilSoybean Oil FuturesYes
    wheatWheat FuturesYes
    platinumPlatinumNo
    micro_silverMicro Silver FuturesYes
    lean_hogsLean Hogs FuturesNo
    cornCorn FuturesYes
    oatOat FuturesNo
    aluminumAluminum FuturesNo
    soybean_mealSoybean Meal FuturesNo
    silverSilver FuturesYes
    soybeanSoybean FuturesYes
    lumberLumber FuturesNo
    live_cattleLive Cattle FuturesYes
    sugarSugarYes
    natural_gasNatural GasYes
    crude_oilCrude OilYes
    orange_juiceOrange JuiceYes
    coffeeCoffeeYes
    cottonCottonYes
    copperCopperYes
    micro_goldMicro Gold FuturesNo
    feeder_cattleFeeder Cattle FuturesNo
    rough_riceRough Rice FuturesNo
    palladiumPalladiumNo
    cocoaCocoaYes
    brent_crude_oilBrent Crude OilYes
    gasoline_rbobGasoline RBOBYes
    heating_oilHeating OilYes
    class_3_milkClass III Milk FuturesYes

Headers

  • X-Api-Key  required

    API Key associated with your account.

Sample Request Live Demo!

name
https://api.api-ninjas.com/v1/commodityprice?name=platinum

Headers

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

Sample Response

JSON
1 2 3 4 5 6 { "exchange": "NYMEX", "name": "Platinum", "price": 995.05, "updated": 1728677095 }

Code Examples

1 2 3 4 5 6 7 8 9 import requests name = 'platinum' api_url = 'https://api.api-ninjas.com/v1/commodityprice?name={}'.format(name) 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/commoditypricehistorical GET

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

Returns historical commodity 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

  • name  required

    Name of commodity. Use the same values as the name parameter in /v1/commodityprice.

  • 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/commoditypricehistorical?symbol=gold&period=1h&start=1728677095&end=1729677095

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": 2757.2, "low": 2745.4, "high": 2758, "close": 2751.2, "volume": 29068, "time": 1729674000 }, { "open": 2763.9, "low": 2754.5, "high": 2764.5, "close": 2757.3, "volume": 16722, "time": 1729670400 }, { "open": 2764.6, "low": 2763, "high": 2767, "close": 2763.9, "volume": 5495, "time": 1729666800 }, "..." ]