OpenBB provider for OilPriceAPI - Real-time oil and commodity prices.
pip install openbb-oilpriceapifrom openbb import obb
# Configure your API key (get free key at https://oilpriceapi.com/signup)
obb.user.credentials.oilpriceapi_api_key = "your_api_key"
# Get all commodity prices
prices = obb.commodity.oil.price(provider="oilpriceapi")
df = prices.to_dataframe()
print(df)
# Get specific commodity (WTI crude)
wti = obb.commodity.oil.price(symbol="WTI", provider="oilpriceapi")
print(f"WTI Price: ${wti.results[0].price}/barrel")| Symbol | Name | Description |
|---|---|---|
WTI |
WTI Crude Oil | West Texas Intermediate benchmark |
BRENT |
Brent Crude Oil | North Sea benchmark |
URALS |
Urals Crude Oil | Russian export blend |
DUBAI |
Dubai Crude Oil | Middle East benchmark |
NG |
Natural Gas (US) | Henry Hub |
NG_EU |
Natural Gas (EU) | TTF |
NG_UK |
Natural Gas (UK) | NBP |
COAL |
Coal | Thermal coal |
DIESEL_US |
US Diesel | National average |
GASOLINE_US |
US Gasoline | National average |
You can set your API key in multiple ways:
Option 1: In Python
obb.user.credentials.oilpriceapi_api_key = "your_key"Option 2: Via settings file
Add to ~/.openbb_platform/user_settings.json:
{
"credentials": {
"oilpriceapi_api_key": "your_key"
}
}Option 3: Environment variable
export OPENBB_OILPRICEAPI_API_KEY="your_key"# Get WTI prices for the past week
history = obb.commodity.oil.historical(
symbol="WTI",
period="past_week",
provider="oilpriceapi"
)
df = history.to_dataframe()import pandas as pd
# Get all prices and compare
prices = obb.commodity.oil.price(provider="oilpriceapi")
df = prices.to_dataframe()
# Filter for crude oils
crude = df[df['symbol'].isin(['WTI', 'BRENT', 'URALS'])]
print(crude[['symbol', 'price', 'change_percent']])import matplotlib.pyplot as plt
history = obb.commodity.oil.historical(
symbol="BRENT",
period="past_month",
provider="oilpriceapi"
)
df = history.to_dataframe()
plt.figure(figsize=(10, 6))
plt.plot(df['date'], df['price'])
plt.title('Brent Crude - Past Month')
plt.ylabel('Price (USD/barrel)')
plt.show()Fetch latest commodity prices.
Parameters:
symbol(str, optional): Commodity symbol. If not provided, returns all commodities.provider(str): Must be "oilpriceapi"
Returns:
symbol: Commodity symbolname: Commodity nameprice: Current pricecurrency: Price currencyunit: Unit of measurementupdated_at: Last update timestampchange: Price change (absolute)change_percent: Price change (percentage)
Fetch historical price data.
Parameters:
symbol(str, required): Commodity symbolperiod(str): Historical period -past_day(24h hourly),past_week(7d daily),past_month(30d daily). Default:past_weekprovider(str): Must be "oilpriceapi"
Returns:
date: Price timestampsymbol: Commodity symbolprice: Price at timestampcurrency: Price currencyunit: Unit of measurement
# Clone the repository
git clone https://github.com/OilpriceAPI/openbb-oilpriceapi.git
cd openbb-oilpriceapi
# Install dependencies
poetry install
# Run tests
poetry run pytest
# Run tests with coverage
poetry run pytest --cov=openbb_oilpriceapiMIT License - see LICENSE for details.