The Commodity Price API provides access to real-time commodity prices for dozens of commonly-traded commodities in major exchanges (CME, NYMEX, etc.).
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.
name
requiredName of commodity. The supported values are:
Value | Description | Premium Only |
---|---|---|
gold | Gold Futures | No |
soybean_oil | Soybean Oil Futures | Yes |
wheat | Wheat Futures | Yes |
platinum | Platinum | No |
micro_silver | Micro Silver Futures | Yes |
lean_hogs | Lean Hogs Futures | No |
corn | Corn Futures | Yes |
oat | Oat Futures | No |
aluminum | Aluminum Futures | No |
soybean_meal | Soybean Meal Futures | No |
silver | Silver Futures | Yes |
soybean | Soybean Futures | Yes |
lumber | Lumber Futures | No |
live_cattle | Live Cattle Futures | Yes |
sugar | Sugar | Yes |
natural_gas | Natural Gas | Yes |
crude_oil | Crude Oil | Yes |
orange_juice | Orange Juice | Yes |
coffee | Coffee | Yes |
cotton | Cotton | Yes |
copper | Copper | Yes |
micro_gold | Micro Gold Futures | No |
feeder_cattle | Feeder Cattle Futures | No |
rough_rice | Rough Rice Futures | No |
palladium | Palladium | No |
cocoa | Cocoa | Yes |
brent_crude_oil | Brent Crude Oil | Yes |
gasoline_rbob | Gasoline RBOB | Yes |
heating_oil | Heating Oil | Yes |
class_3_milk | Class III Milk Futures | Yes |
X-Api-Key
requiredAPI Key associated with your account.
https://api.api-ninjas.com/v1/commodityprice?name=platinum
Headers
X-Api-Key
Log in or sign up to get your API Key
1
2
3
4
5
6
{
"exchange": "NYMEX",
"name": "Platinum",
"price": 995.05,
"updated": 1728677095
}
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.
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.
name
requiredName of commodity. Use the same values as the name parameter in /v1/commodityprice.
period
optionalTime interval between data points. Valid values are: 1m
, 5m
, 15m
, 30m
, 1h
, 4h
. Default is 1h
.
start
optionalStart timestamp in Unix format. If not provided, defaults to 24 hours ago.
end
optionalEnd timestamp in Unix format. If not provided, defaults to current time.
X-Api-Key
requiredAPI Key associated with your account.
https://api.api-ninjas.com/v1/commoditypricehistorical?symbol=gold&period=1h&start=1728677095&end=1729677095
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
},
"..."
]