How to Get S&P/TSX Composite (GSPTSE) Prices via API
To chart the S&P/TSX Composite or alert on a move, you need a current GSPTSE quote, a clear understanding of its units, and a way to handle days when the market is closed. This guide shows how to request and read the latest value, then use historical data to build a series without treating stale quotes as new market moves.
Request the latest GSPTSE quote
Start by getting an API key from Register. The latest endpoint returns available index rates; the example below reads GSPTSE from that response rather than relying on an undocumented filtering parameter.
Replace YOUR_API_KEY with your key:
curl "https://indices-api.com/api/latest?access_key=YOUR_API_KEY"
Confirm the symbol and its specifications in Symbols before adding it to a production symbol configuration. This matters because the response contains both a GSPTSE rate and a differently expressed USDGSPTSE quote.
The following real response shows the fields to expect:
{"data":{"success":true,"timestamp":1796344800,"date":"2026-12-04","base":"USD","rates":{"GSPTSE":4.0237837016982e-5,"USD":1,"USDGSPTSE":24852.230490867576}}}
The quote is inside data.rates, not at the top level. For a display that uses the direct quote shown here, read data.rates.USDGSPTSE; retain the base, date, and timestamp alongside it so consumers can interpret and assess the observation.
Fetch and parse it in Python
This example uses the Python standard library and reads the key from an environment variable. It checks the API success flag and required fields before printing the quote; it does not assume that an HTTP response alone means the data is usable.
import json
import os
from decimal import Decimal
from urllib.parse import urlencode
from urllib.request import urlopen
api_key = os.environ["INDICES_API_KEY"]
query = urlencode({"access_key": api_key})
url = "https://indices-api.com/api/latest?" + query
with urlopen(url, timeout=10) as response:
payload = json.load(response, parse_float=Decimal)
data = payload.get("data")
if not isinstance(data, dict) or data.get("success") is not True:
raise RuntimeError("The API did not return a successful data object")
rates = data.get("rates")
if not isinstance(rates, dict) or "USDGSPTSE" not in rates:
raise RuntimeError("The response does not contain the USDGSPTSE quote")
quote = rates["USDGSPTSE"]
base = data["base"]
quote_date = data["date"]
timestamp = data["timestamp"]
print("USDGSPTSE:", quote)
print("Base:", base)
print("Date:", quote_date)
print("Timestamp:", timestamp)
Set INDICES_API_KEY in the process environment before running the script. In an application, handle network errors and missing fields at the boundary, then pass a validated observation to the chart or alerting component. Do not log the full request URL: the key is in its query string.
Understand the quote before charting it
The response contains two GSPTSE-related entries with different orientations. In this sample, rates.GSPTSE is a small USD-based rate, while rates.USDGSPTSE is its reciprocal-style direct quote. They should not be displayed interchangeably or combined in one series without conversion.
base is USD, the default base in the provided response. That does not mean the index itself is a US index, nor should a dashboard silently label every returned value as an official index-point value. Verify the symbol’s quote convention and intended display units in the symbol specifications before comparing it with another source or using it in a financial calculation.
Use the remaining fields as follows:
ratesholds the returned numeric rates. SelectUSDGSPTSEfor the direct quote in this response and keep its orientation consistent over time.baseidentifies the response’s base currency. Store it with the observation rather than assuming every future response has the same base.dateis the date associated with the returned data. Preserve it as supplied; do not substitute the date on which your job happened to run.timestampis a Unix timestamp. Interpret it as an instant in UTC, then convert it to your display timezone if needed. It is not, by itself, proof of a particular market session or trade time.successindicates whether the returned data object reports success. Still check that the specific rate and metadata your application needs are present.
For storage, a useful observation consists of the symbol or quote key, value, base, API date, and source timestamp. Keeping those fields together makes it possible to distinguish a new fetch from a genuinely new source observation. Decimal handling, as in the Python example, also avoids introducing binary floating-point representation into the initial parse.
Build a historical series and measure a move
For a chart that needs more than the latest quote, use the time-series endpoint to request daily historical rates between a start and an end date. The documented response groups rates by date, so transform each returned date and the relevant quote into an observation before sorting the series chronologically.
The end_date cannot be today. End a historical request on an earlier date, and obtain the current observation separately from the latest endpoint if your application needs it. Check the request parameters, allowed date range per request, symbol availability, and any applicable plan restrictions in the Documentation.
Do not assume the earliest available date for GSPTSE from a general statement about historical coverage. Check the actual series returned for the range you need. If a requested range is too large for your access, split it according to the documented limits, deduplicate observations at the boundaries, and record gaps for review.
Before combining a historical rate with the latest USDGSPTSE quote, check which key and orientation the historical response provides. A series made from reciprocal rates will move in the opposite direction to a series made from their direct quotes. If a conversion is required, apply it consistently to valid, nonzero values and label the resulting series accordingly.
The fluctuation endpoint is another option when the job is to compare two dates rather than draw every daily observation. Its documented response includes start_rate, end_rate, change, and change_pct. Confirm which GSPTSE rate those fields describe before presenting the result as a move in the direct quote; a percentage change on a reciprocal rate is not simply the negative of the direct quote’s percentage change.
If calculating the move yourself, compare like with like: the same quote key, base, and units at both endpoints. Subtract the starting value from the ending value for an absolute change; divide that change by the starting value for a fractional change, provided the starting value is nonzero. Use actual returned observations and show their dates with the result.
Operate the integration around market hours
The latest endpoint’s update frequency depends on the subscription plan. The supplied plan information includes update intervals of every 60 minutes or every 10 minutes, but a fetch does not necessarily produce a new market observation. Check the current plan details before choosing a polling schedule or promising a freshness level to users.
Cache the latest successful observation for your dashboard or downstream services. Refresh it according to your plan’s update frequency, and use the returned timestamp—not merely the time your cache was filled—to decide whether the source data is fresh enough for the application. If a refresh fails, you can retain the last successful observation, but mark it as stale rather than presenting it as current.
GSPTSE follows a market calendar, not a continuous trading schedule. Weekends and market holidays can leave the most recent observation unchanged, and a response date may not represent a new trading session. Preserve returned dates and check the applicable exchange calendar rather than manufacturing a weekend price or assuming that every weekday is a trading day.
For charts, choose an explicit gap policy. Leaving missing dates absent makes the source observations visible; carrying a prior value forward can be useful for a calendar-aligned display, but it should be marked as carried forward and excluded from calculations that require an actual new observation. Never overwrite the original returned value or timestamp when creating a display-only fill.
For alerts, compare distinct observations, not repeated downloads of the same timestamp. Define whether the threshold applies to the direct quote or the reciprocal rate, and suppress or label alerts when the latest observation exceeds your freshness threshold. This prevents a cache refresh or a closed-market period from looking like a new price event.
The examples here do not depend on pagination. If your historical workflow requires multiple requests, follow the documented request limits and pagination behavior for the endpoint and plan you use; do not assume that a response contains a complete requested range without checking it.
FAQ
Which response field should I use for the GSPTSE display?
The real latest response above exposes the direct quote as data.rates.USDGSPTSE. It also contains data.rates.GSPTSE, a differently oriented rate. Confirm the intended units for your application and use the same orientation throughout a chart or calculation.
Can I request a time series ending today?
No. end_date cannot be today. Use an earlier end date for the historical series and request the latest observation separately when you need a current value; check its timestamp before combining it with historical data.
Why did the latest quote not change after another request?
Your plan’s update interval may not have elapsed, or the market may be closed. Compare the returned timestamp and date with the observation you already have. A new request time alone does not establish that the underlying quote has changed.
Can I use the fluctuation percentage directly for an alert?
Only after confirming the rate orientation, dates, base, and units match the quote your alert monitors. A fluctuation in a reciprocal rate is not the same percentage move as a fluctuation in the direct quote.
Get a free API key through Register above, then test the latest request and verify the quote conventions before shipping. The supplied plan information lists PRO at $49.99 per month with a seven-day trial; check current terms and eligibility when signing up. For related integration options, see MCP.