Oil PricesOn a Cron Schedule
One curl works once. A scheduled workflow works every morning. Use GitHub Actions to pull energy prices on a cron, post them to a job summary, or build a free versioned price history inside your repo — no server required.
1. Store the API key as a secret
In your repository: Settings → Secrets and variables → Actions → New repository secret. Name it OILPRICEAPI_KEY and paste your key. Never commit the key itself — workflow logs are visible to everyone who can see the repo.
2. Scheduled pull with a job summary
This complete workflow fetches the latest Brent price every weekday morning and renders it in the run's summary page:
# .github/workflows/oil-price.yml
name: Daily oil price pull
on:
schedule:
# 06:15 UTC on weekdays. GitHub cron is UTC; avoid :00 — scheduled
# load peaks on the hour and runs can be delayed or dropped.
- cron: "15 6 * * 1-5"
workflow_dispatch: {} # manual "Run workflow" button for testing
jobs:
fetch-price:
runs-on: ubuntu-latest
steps:
- name: Fetch latest Brent price
run: |
curl -sS --fail-with-body \
"https://api.oilpriceapi.com/v1/prices/latest?by_code=BRENT_CRUDE_USD" \
-H "Authorization: Token ${{ secrets.OILPRICEAPI_KEY }}" \
-o price.json
- name: Write job summary
run: |
PRICE=$(jq -r '.data.price' price.json)
CODE=$(jq -r '.data.code' price.json)
ASOF=$(jq -r '.data.created_at' price.json)
echo "## ${CODE}: \$${PRICE}" >> "$GITHUB_STEP_SUMMARY"
echo "_as of ${ASOF}_" >> "$GITHUB_STEP_SUMMARY"The response the workflow parses with jq looks like this — the price lives under .data.price:
{
"status": "success",
"data": {
"price": 86.24,
"formatted": "$86.24",
"currency": "USD",
"code": "BRENT_CRUDE_USD",
"created_at": "2026-08-10T14:22:19.000Z",
"type": "spot_price"
}
}3. Variant: commit a price history to the repo
Append each day's price to a CSV and let git version it. A year of weekday runs is roughly 260 requests — a scheduled workflow like this stays far inside the free tier's 50 requests per day:
# .github/workflows/oil-price-history.yml
name: Append price history
on:
schedule:
- cron: "15 6 * * 1-5"
workflow_dispatch: {}
permissions:
contents: write # required for the commit step
jobs:
append-history:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Fetch and append
run: |
curl -sS --fail-with-body \
"https://api.oilpriceapi.com/v1/prices/latest?by_code=BRENT_CRUDE_USD" \
-H "Authorization: Token ${{ secrets.OILPRICEAPI_KEY }}" \
-o price.json
mkdir -p data
[ -f data/brent.csv ] || echo "created_at,code,price,currency" > data/brent.csv
jq -r '[.data.created_at, .data.code, .data.price, .data.currency] | @csv' \
price.json >> data/brent.csv
- name: Commit if changed
run: |
git config user.name "price-bot"
git config user.email "[email protected]"
git add data/brent.csv
git diff --cached --quiet || git commit -m "chore: append Brent price"
git push4. Variant: Python SDK
Swap the curl step for the official Python SDK when you want typed access or multiple commodities:
# Prefer the Python SDK? Same schedule, richer client:
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Fetch with the SDK
env:
OILPRICEAPI_KEY: ${{ secrets.OILPRICEAPI_KEY }}
run: |
pip install oilpriceapi
python - <<'PY'
import os
from oilpriceapi import OilPriceAPI
with OilPriceAPI(api_key=os.environ["OILPRICEAPI_KEY"]) as client:
price = client.prices.get("BRENT_CRUDE_USD")
print(price.commodity, price.value, price.currency)
PYNotes on scheduling
- GitHub cron runs in UTC and is best-effort: runs can start minutes late. Fine for daily prices, not for tick-level trading.
- Scheduled workflows are disabled automatically after 60 days of repo inactivity on the default branch — the commit-to-repo variant keeps itself alive because each run commits.
- Use
workflow_dispatchto test the workflow immediately instead of waiting for the cron.