How to Get S&P GSCI Natural Gas Index (SPGSNG) Prices using a REST API
You need to load, display, and monitor the S&P GSCI Natural Gas Index in your app. By the end of this guide you’ll fetch the latest SPGSNG print over a REST API, compute a USD-per-index quote you can chart, and wire up day-over-day fluctuation logic for alerts and dashboards.
What you will build and why SPGSNG matters
We’ll implement a small integration that:
- Pulls the latest S&P GSCI Natural Gas Index (symbol: SPGSNG) value using a single GET request.
- Derives a “USD per index” price ready for charting and tooltips.
- Prepares a fluctuation query to measure day-over-day movement for alerting and summaries.
The S&P GSCI family tracks commodities via a production-weighted methodology; the Natural Gas sub-index reflects front-month exposure to natural gas futures. For methodology and context, see the publisher’s overview on S&P Dow Jones Indices.
Confirm the symbol and understand the quote
The symbol for the S&P GSCI Natural Gas Index on Indices-API is SPGSNG. If you’re embedding this into a selector or symbol search, confirm the code and naming on the Indices-API Supported Symbols page before shipping.
Indices-API returns index “rates” relative to a base currency. By default, base is USD. Two fields you’ll use for pricing:
- rates.SPGSNG — how many SPGSNG “index units” per 1 USD.
- rates.USDSPGSNG — how many USD per 1 SPGSNG index unit (the inverted quote), often the value you’ll present in charts and UI.
This dual representation saves you from inverting on the client and lets you pick the expression you prefer.
Get the latest SPGSNG print (curl + JSON)
Use the latest endpoint to fetch current values. Authentication uses an access_key query parameter. Replace YOUR_API_KEY with your real key; if you don’t have one, get a free trial key from the Register page.
curl -s "https://indices-api.com/api/latest?access_key=YOUR_API_KEY"
Below is an official response for the endpoint. Copy it into tests and fixtures exactly as-is while you wire up parsing.
{"data":{"success":true,"timestamp":1791679200,"date":"2026-10-11","base":"USD","rates":{"SPGSNG":0.0062531265632816,"USD":1,"USDSPGSNG":159.92000000000104}}}
Fields you will use:
- success: Boolean for request status.
- timestamp: Unix epoch seconds for when the rates snapshot was computed. Treat as UTC.
- date: The ISO date of the snapshot, aligned to market/trading calendars and settlement conventions.
- base: The base currency (USD). All rates are relative to this base.
- rates: A map of quotes. For SPGSNG work:
- rates.SPGSNG — SPGSNG per 1 USD.
- rates.USDSPGSNG — USD per 1 SPGSNG.
Parse the latest price in Python
The snippet below calls the same endpoint, verifies success, converts the timestamp to a Python datetime, and extracts both the inverted and non-inverted quotes so you can feed charts and alert logic.
import os
import time
import json
import urllib.request
from datetime import datetime, timezone
API_KEY = os.getenv("INDICES_API_KEY", "YOUR_API_KEY")
URL = f"https://indices-api.com/api/latest?access_key={API_KEY}"
with urllib.request.urlopen(URL, timeout=10) as resp:
payload = resp.read().decode("utf-8")
data = json.loads(payload).get("data", {})
if not data.get("success"):
raise RuntimeError(f"Indices-API error: {payload}")
ts = data["timestamp"]
dt = datetime.fromtimestamp(ts, tz=timezone.utc)
base = data["base"] # "USD"
as_of_date = data["date"] # e.g., "2026-10-11"
rates = data["rates"]
spgsng_per_usd = float(rates["SPGSNG"]) # SPGSNG units per 1 USD
usd_per_spgsng = float(rates["USDSPGSNG"]) # USD per SPGSNG unit
print(f"As of {as_of_date} {dt.isoformat()} (base {base}):")
print(f" SPGSNG per USD : {spgsng_per_usd}")
print(f" USD per SPGSNG : {usd_per_spgsng}")
# Example: format for a chart tooltip
tooltip_value = f"${usd_per_spgsng:,.2f} per SPGSNG"
print(tooltip_value)
Notes for production:
- Cache the entire JSON by timestamp; if the snapshot doesn’t change, avoid re-rendering charts or duplicating alerts.
- Treat timestamp as authoritative for data recency; not all markets update at the same moment.
- If your UI favors the inverted quote (USDSPGSNG), store it as a float and format at the edge of your app to minimize rounding artifacts.
From print to chart: units, caching, and refresh cadence
Indices-API’s latest endpoint updates on a cadence tied to your plan. Depending on subscription, snapshots refresh roughly every 60 minutes, every 10 minutes, or more frequently. Use that cadence as your minimum cache TTL to stay within quota and avoid needless redraws.
SPGSNG is expressed against USD. In the example, rates.USDSPGSNG is the direct “dollars per index unit” value you’ll likely chart. If you prefer normalized values, maintain both series in your store; the non-inverted SPGSNG-per-USD quote is useful for cross-index comparisons that share the same base.
Market calendars matter. Commodities-based indices observe weekends and holidays; expect missing entries on non-trading days. Your chart should render gaps or carry the last value with a visual convention indicating “no trading” rather than an implied flat session.
Compute day-over-day fluctuation for SPGSNG
To drive “moved up/down X% today” badges and alerts, use the fluctuation endpoint with a short window. The flow:
- Choose a window, e.g., the last two valid trading dates (T-1 to T).
- Call the fluctuation endpoint for SPGSNG over that window.
- Read the response’s start_rate and end_rate, then compute your change and change_pct from the payload (do not invent values).
Important implementation details:
- Do not set end_date to today if a fresh snapshot isn’t yet available for your plan. Use the last completed trading day to avoid partial-day artifacts.
- Weekends and holidays will shift the effective start_date automatically; be prepared for gaps.
- Base is USD, so interpret start_rate and end_rate in the same “rates relative to USD” framework as latest.
For parameter names, response schema, and examples, see the Indices-API Documentation. This post avoids fabricating percentage changes; when you implement, surface the exact change values returned by the API for your selected dates.
Historical series and OHLC, when you need them
If you’re backfilling charts or running studies, consider:
- Time-series endpoint for daily historical rates between two dates.
- OHLC endpoint for open, high, low, and close on a given date.
These are the right tools to build a continuous SPGSNG chart, compute moving averages, or snapshot end-of-day values. Observe the same rules: USD base, trading-day calendars, and use end_date not equal to today. For exact request parameters and available ranges, reference the Documentation. If you’re unsure about symbol normalization across endpoints, reconfirm SPGSNG on the Symbols page.
Production notes that save debugging time
- Base currency and inversion:
- base is "USD" by default; rates.* are quotes expressed relative to USD.
- Use rates.USDSPGSNG when you need a dollar-denominated display value without client-side inversion.
- Timestamp and timezone:
- timestamp is epoch seconds. Treat as UTC in your time-series store.
- For intraday displays, show local time with a UTC badge to avoid confusion.
- Update frequency:
- Snapshots refresh on a plan-dependent cadence (e.g., around every 60 or 10 minutes).
- Don’t poll faster than the data updates; use a cache keyed by timestamp.
- Trading days vs. weekends:
- No updates on weekends/holidays; accommodate gaps in charts.
- When computing fluctuation, automatically back off to the last trading day.
- end_date cannot be today:
- For historical, time-series, and fluctuation calls, set end_date to the most recent completed trading day.
- Error handling:
- Check success and guard against missing keys in rates.
- Log the raw payload for diagnosis when success is false.
- Rounding and presentation:
- Keep full precision internally (e.g., Decimal if required).
- Format at the UI layer (e.g., two decimals for USD per SPGSNG) to reduce cumulative rounding error.
Quick build checklist
- Get an access key from Indices-API Register and store it securely.
- Call GET /api/latest and verify data.success before parsing.
- Read data.base, data.date, data.timestamp, and data.rates to compute display values.
- Use rates.USDSPGSNG for a direct USD-per-index quote in charts.
- Cache by timestamp and align refresh to plan cadence.
- For day-over-day change, call the fluctuation endpoint with a completed end_date (not today).
- Confirm the SPGSNG symbol via Symbols.
- Review endpoint parameters on the Documentation page.
Where SPGSNG data fits in a broader workflow
For quant pipelines, pair SPGSNG levels with your internal factors or spreads; many teams also track benchmark storage reports and futures curves externally for context. A few helpful references:
- U.S. EIA Natural Gas Data for storage and demand/supply indicators.
- CME Henry Hub Futures for contract specifications and expiries that influence index rolls.
- Indices-API MCP for programmatic access patterns and model control points in larger deployments.
FAQ
Which symbol should I use for the S&P GSCI Natural Gas Index?
Use SPGSNG. If you’re unsure or see multiple variants in your system, confirm in the Symbols list.
What value should I chart: SPGSNG or USDSPGSNG?
Chart rates.USDSPGSNG when you want a dollar price per index unit. Keep rates.SPGSNG (index units per USD) internally if you need consistent math across multiple indices sharing USD as base.
Why does my fluctuation endpoint show no change on a weekend?
Commodities markets observe weekends and holidays. If your start_date and end_date both land on non-trading days, change may be zero. Use the last two completed trading dates for meaningful fluctuation.
Can I set end_date to today?
Do not set end_date to today. Use the most recent completed trading day to avoid partial-day data and to comply with the endpoint’s constraints.
How often should I refresh the latest quote?
Match your polling to the plan’s update frequency (for example, every ~60 minutes or ~10 minutes). Cache by timestamp so identical snapshots do not trigger redundant work.
Get an API key and ship your SPGSNG integration
Spin up your integration with a 7-day trial and upgrade as needed (Pro plan from $49.99/month). Start by requesting your key from Indices-API Register, then use the Documentation to plug in time-series, fluctuation, or OHLC as your product evolves.