Shanghai Composite (SHCOMP) Price History API
You need to backfill and chart a daily time series for the Shanghai Composite Index and keep it updated with fresh prints. By the end of this guide, you will be able to query the Indices-API for SHCOMP, handle missing or invalid-symbol responses correctly, and wire the results into a chart or alerting pipeline that respects trading days, update frequency, and caching.
What you’re building: a reliable SHCOMP time series feed
The concrete goal is simple: pull Shanghai Composite (SHCOMP) prices into your app with a workflow that can run on a schedule. We’ll focus on two endpoints you’ll actually need in production:
- Latest: to pick up current sessions’ updates and to verify symbol availability
- Time-series: to backfill a range of daily values for historical charts and stats
We’ll also cover practical details developers ask for: how values are quoted (base currency and units), how to treat weekends and holidays, why end_date cannot be today, how often the feed updates, and when to cache responses.
Before you start coding, confirm the symbol code for Shanghai Composite on the Indices-API Supported Symbols page. This is important because symbol taxonomies vary across providers. Do not assume synonyms like “SSEC” or “000001.SH” will resolve; you must use the exact code listed by Indices-API. This article uses SHCOMP as the working symbol to match the title, but you should validate it on the symbols page for your account.
Endpoint 1: Latest — verify symbol and pick up the most recent print
Use the latest endpoint to quickly check symbol availability and grab the current reading. It’s also the lightest-weight request you can place in a frequent poller. Depending on your subscription, the latest index data updates roughly every 60 minutes or every 10 minutes. The base currency in responses is USD, and rates are expressed as “per index.” For indices, this means you’ll read a USD-relative rate for each index code in the rates object, following a pattern like rates.USD{SYMBOL}.
Important: if you query on a weekend or a China market holiday, the latest endpoint will return the most recently available data; there won’t be a new print on non-trading days. Your app should be prepared for unchanged timestamps across these days.
Copy-pasteable curl request (Latest for SHCOMP)
curl -G "https://indices-api.com/api/latest" \
--data-urlencode "access_key=YOUR_API_KEY" \
--data-urlencode "symbols=SHCOMP"
If the symbol is invalid for your account or plan, you will receive an error envelope. Below is the real error response captured for an invalid symbol scenario. Use this as a template for your own error handling and logging.
{"success":false,"error":{"code":400,"type":"invalid_symbol","info":"One or more invalid symbols have been specified."}}
What you will typically use after a successful call:
- success: Boolean flag; true when the payload contains market data.
- timestamp: Unix epoch for the price snapshot; use it for cache headers and freshness checks.
- base: The base currency for the rates object (USD).
- date: Human-readable date string corresponding to timestamp.
- rates: Object keyed by index code; for indices, you’ll read the value under a key that matches the USD-index pattern (for example, USDSHCOMP). Confirm the exact key on the Indices-API Documentation for the latest endpoint.
Reminder: if you hit invalid_symbol, verify the exact code on the Symbols page, ensure your plan covers the requested index, and retry with the correct symbol.
JavaScript example (Latest for SHCOMP, with error handling)
async function fetchLatestSHCOMP() {
const baseUrl = "https://indices-api.com/api/latest";
const params = new URLSearchParams({
access_key: "YOUR_API_KEY",
symbols: "SHCOMP"
});
const res = await fetch(`${baseUrl}?${params.toString()}`, {
method: "GET",
headers: { "Accept": "application/json" }
});
if (!res.ok) {
throw new Error(`HTTP ${res.status}: ${res.statusText}`);
}
const data = await res.json();
// Handle the official error envelope shape from Indices-API
if (data.success === false) {
// Example: {"success":false,"error":{"code":400,"type":"invalid_symbol","info":"..."}}
const err = data.error || {};
throw new Error(`Indices-API error [${err.code} - ${err.type}]: ${err.info}`);
}
// Successful payload fields to use downstream
// - data.timestamp: number (epoch seconds)
// - data.date: string (YYYY-MM-DD)
// - data.base: "USD"
// - data.rates: object
//
// The index value you need will be at a key within data.rates that corresponds
// to USD + SYMBOL pattern. Confirm on the docs. Example expectation: data.rates.USDSHCOMP
const { timestamp, date, base, rates } = data;
// Validate presence of the SHCOMP rate key before consuming it
const key = "USDSHCOMP"; // Confirm this key on the Symbols/Docs pages for your account.
if (!rates || typeof rates[key] === "undefined") {
throw new Error("Rates object did not include the expected USDSHCOMP key. Check symbol mapping.");
}
return {
timestamp,
date,
base,
rate: rates[key],
unit: data.unit // expected to be "per index"
};
}
fetchLatestSHCOMP()
.then((snap) => {
console.log("Latest SHCOMP snapshot:", snap);
// Persist to your cache/store, update a chart, or notify downstream pipelines.
})
.catch((e) => {
console.error("Failed to fetch SHCOMP latest:", e.message);
// Optionally: retry with backoff, or surface a user-facing alert.
});
Notes for production:
- Set a short-lived cache (e.g., 30–120 seconds) around latest. Update frequency depends on your plan.
- Never assume today’s date has a fresh print during non-trading hours; rely on timestamp freshness instead.
- If you need interval candles for intraday charts, consult the Intraday or OHLC endpoints in the Documentation.
Endpoint 2: Time-series — backfill SHCOMP history for charts and analytics
Use the time-series endpoint to retrieve daily historical values between a start and end date. This is ideal for initializing a chart, computing rolling statistics (drawdowns, moving averages), or running a daily backtest refresh.
Key behavior to account for:
- Dates are returned in UTC with a daily granularity. Align them to your app’s time zone policy (Shanghai is UTC+8) when charting.
- Non-trading days (weekends/holidays) won’t add new SHCOMP prints. Don’t assume a value per calendar day; iterate over the dates returned by the API.
- end_date cannot be today. Always request up to yesterday, or let the endpoint’s default range return through the most recent completed day.
While this article does not duplicate the full request syntax, you can find the exact parameters and path for time-series queries in the Indices-API Documentation. The core fields to expect are consistent with the latest endpoint, plus timeseries-specific flags and a map keyed by date:
- success: true on success
- timeseries: true indicates a range query
- start_date, end_date: the requested bounds (end_date should be a completed day)
- base: "USD"
- rates: object keyed by date; each date entry contains rate objects keyed by index code (again, use the USD+SYMBOL mapping for the SHCOMP value)
Example downstream usage once you have a successful time-series payload:
- For each date d in rates: extract the SHCOMP value under the USD+SYMBOL key.
- Construct a sorted array of {date, value} pairs for your charting library.
- Persist the latest date processed and resume from that date on subsequent backfills.
If you need OHLC values instead of one daily rate, review the OHLC endpoint in the docs. The OHLC payload includes open/high/low/close per index symbol on a given date, which is suitable for candlestick charts.
Data model, units, and base currency
Indices-API responses for indices are quoted relative to USD. The base field will be "USD", and numerical values for indices are provided under rates with a “per index” unit. In practice:
- base: "USD" — always interpret returned numbers in that context.
- unit: "per index" — the value represents a USD-relative rate for the given index code.
- rates: in latest responses, look for the USD+SYMBOL key to get the SHCOMP figure; in time-series, do the same within each date bucket.
For multi-currency dashboards that display cross-views, you can use the conversion and fluctuation endpoints described in the Documentation. Always verify symbol and currency codes on the Symbols page before composing queries.
Operational details: trading days, freshness, and caching
Shanghai Composite reflects trading on the Shanghai Stock Exchange. Plan for:
- Non-trading days: weekends and China market holidays yield no new print. Your chart should not expect a point for each calendar day.
- Update frequency: the latest endpoint refresh cadence depends on your plan (for example, ~60-minute or ~10-minute updates). Design your poller interval accordingly.
- Do not request end_date=today on time-series: use yesterday. If you need today’s print, query the latest endpoint separately and reconcile.
- Time zones: store as UTC internally; render in your user’s local time or CST (UTC+8) as required by your product design.
- Caching: put a short TTL in front of latest (e.g., 30–120s) and a longer TTL for historical ranges (since those don’t change).
If you build alerts (e.g., notify on a 2% move), trigger off fresh timestamps from latest and compare against the last completed close from time-series or yesterday’s latest. For repeatable analytics, freeze the time range to completed days only.
Error handling and symbol validation for SHCOMP
The most common integration failure is an invalid symbol. When this occurs, the API returns a structured error as shown earlier. Your pipeline should detect data.success === false and surface the error.code, error.type, and error.info details to logs or monitoring. Then:
- Verify that “SHCOMP” is a supported symbol for your account on the Symbols page.
- Check that your plan grants access to the required exchanges. See your account dashboard or the MCP page for product coverage info.
- Retry with the exact symbol string from the symbols directory.
For rate limiting, network errors, or intermittent outages, apply exponential backoff, respect HTTP status codes, and fall back to cached data where appropriate. Always gate critical features (alerts, orders, or risk checks) on data.timestamp recency to avoid acting on stale prices.
Implementation checklist: from dev to production
- Get an API key: use the 7-day trial on the PRO plan ($49.99/mo after trial) to develop and test.
- Validate symbol: confirm SHCOMP on the Symbols page.
- Backfill: run a time-series request from your earliest needed date to yesterday (end_date cannot be today). Store the array of {date, value} in your DB.
- Keep fresh: poll latest during trading sessions, with a short cache TTL to avoid refetch storms.
- Charting: align timestamps to your display TZ and handle gaps for weekends/holidays gracefully.
- Monitoring: alert on invalid_symbol, HTTP >= 400, or unexpected shapes in rates; degrade gracefully to last-known values.
Testing tips: deterministic runs and reproducibility
For backtests and reproducible runs:
- Pin end_date to a completed historical day, not “today.”
- Log the response timestamp and the full set of dates returned by time-series.
- Hash and snapshot your historical series after each import to detect accidental changes upstream.
When comparing against other data sources, remember Indices-API values for indices are standardized against USD and returned with a “per index” unit. If you cross-check with the Shanghai Stock Exchange or data vendors exposing local-currency levels, ensure you convert/normalize appropriately before comparing.
Reference links
- Indices-API Documentation — endpoint parameters, response fields, and examples for latest, time-series, OHLC, and more.
- Indices-API Supported Symbols — verify SHCOMP and any other indices you plan to query.
- MCP — market coverage and product details.
- Shanghai Stock Exchange: Official SSE site — trading calendars and product listings for China’s A-shares.
FAQ
How do I find the correct symbol code for Shanghai Composite?
Open the Symbols directory and search for “Shanghai Composite.” Use the exact code shown there in your requests. If SHCOMP does not resolve for your account, pick the listed code and retry.
Why does my time-series query fail when end_date is today?
The API returns completed days only. Use yesterday as end_date. If you need intraday or current-day values, combine time-series (for history through yesterday) with the latest endpoint for today’s in-session data.
What does base: "USD" and unit: "per index" mean for SHCOMP?
It indicates the rates are expressed relative to USD, and the numbers in rates correspond to a “per index” unit for the given symbol. When reading SHCOMP, extract the USD+SYMBOL key from rates to obtain the value you’ll chart or compute on.
What should I do when I get success=false with type=invalid_symbol?
Confirm the symbol on the Symbols page, check your plan’s coverage on the MCP page, then retry with the listed code.
How frequently does latest update, and how should I poll it?
Update frequency depends on your subscription tier (for example, around every 60 minutes or every 10 minutes). Poll on a cadence slightly slower than your plan’s refresh interval and apply a brief cache TTL to avoid duplicate fetches across services.
Get your key and ship your SHCOMP chart
Spin up your SHCOMP integration with a 7-day trial on the PRO plan ($49.99/mo after the trial), then move your dashboard from prototype to production. Create your account here: Register. Once you have your key, follow the Documentation to finalize your time-series backfill and latest polling for SHCOMP.