API to Get the Hang Seng (HSI) Price
You need to display the Hang Seng Index (HSI) price on a dashboard, backfill a daily history for charting, and optionally convert a cash amount into “index points” for alerts or simulations. By the end of this guide, you’ll fetch the latest HSI print, normalize it from the API’s USD-based quote format, pull a historical window for charts, and implement a dollar-to-HSI conversion without guesswork.
What you’ll build and the endpoints you’ll use
We’ll focus on three things that get shipped into production fast:
- Retrieve the latest HSI price and timestamp for live tiles and notifications (Latest endpoint).
- Backfill a daily series to chart the Hang Seng over a date range (Time-series endpoint).
- Convert a USD amount to HSI “index units” (Convert endpoint and/or local math).
All examples below use HSI. Confirm any symbol you use (including regional variants) on the official list before deploying: Indices-API Supported Symbols. If you’re new to the platform, start here to get oriented: Indices-API home, and then grab your API key.
How HSI is quoted in the API (read this once, save an hour later)
Indices-API responses are USD-based. That means the “base” field is USD, and “rates” are expressed relative to USD. For indices, the key detail is that rates map to index-units-per-USD. In practice:
- rates.HSI represents how many HSI “index units” correspond to 1 USD.
- To recover the conventional index level (i.e., HSI points), invert the rate: index_level ≈ 1 / rates.HSI.
- Some responses also include a convenience field such as rates.USDHSI, which equals 1 / rates.HSI (a direct proxy for the index level).
The API returns a “timestamp” (Unix seconds), and a “date” (YYYY-MM-DD). Treat timeseries dates as daily closes or official session dates; do not assume weekends/holidays have prints. Always check whether the Hong Kong Exchange was open on a given date when building backfills or calculating gaps.
Get the latest Hang Seng (HSI) price
Use the latest endpoint with your access_key. This call is cache-friendly for your edge and ideal for tile refreshes or minute-based alerts. The API’s update frequency depends on your plan tier (for example, every 60 minutes or every 10 minutes). If you’re rolling an intraday board, respect cache lifetimes that match your plan’s update interval.
cURL request
curl -s "https://indices-api.com/api/latest?access_key=YOUR_API_KEY&symbols=HSI"
Official JSON response
{"data":{"success":true,"timestamp":1794098160,"date":"2026-11-08","base":"USD","rates":{"HSI":0.00032027305114889,"USD":1,"USDHSI":3122.3357582312333}}}
What these fields mean for your app
- success: Boolean indicating request success.
- timestamp: Unix time (seconds). Use it for caching keys, staleness checks, and UI “as of” labels.
- date: Session date (YYYY-MM-DD). Useful for charts and when rolling up to daily granularity.
- base: Always "USD" for this API; all rates are relative to USD.
- rates.HSI: Index units per 1 USD (≈ 0.0003202730511). Invert it to get the conventional index level.
- rates.USD: Always 1; base-to-base.
- rates.USDHSI: Convenience inverse of HSI (≈ 3122.335758...). Treat it as an approximation of the HSI level.
If your chart or tile needs a single “HSI level” number: prefer rates.USDHSI when present; otherwise compute 1 / rates.HSI. Round and format consistently (e.g., zero decimals for an index level display, unless you show fractional moves).
JavaScript example (fetch latest HSI and normalize)
async function getLatestHSI() {
const url = "https://indices-api.com/api/latest?access_key=YOUR_API_KEY&symbols=HSI";
const res = await fetch(url, { cache: "no-store" });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const payload = await res.json();
// The real data is in payload.data.* per the official response above
const { success, timestamp, date, base, rates } = payload.data;
if (!success) throw new Error("API reported unsuccessful response");
// Prefer USDHSI if present; otherwise invert HSI
const hsiLevel = (rates.USDHSI !== undefined && rates.USDHSI !== null)
? rates.USDHSI
: (1 / rates.HSI);
return {
asOfUnix: timestamp,
asOfDate: date,
base,
hsiLevel, // e.g., 3122.3357...
hsiPerUSD: rates.HSI
};
}
getLatestHSI()
.then(data => {
console.log(`HSI: ${Math.round(data.hsiLevel)} (as of ${data.asOfDate})`);
})
.catch(err => {
console.error("Failed to load HSI:", err);
});
Tip: When caching, key by the date and an update bucket aligned to your plan’s refresh cadence (for example, 10-minute buckets). That way you avoid thundering herds and respect the API’s update rhythm.
Backfill a daily series for HSI charting
For a sparkline, OHLC ribbon, or a full historical chart, call the time-series endpoint over a date range. The endpoint returns daily records keyed by date. Expect gaps on weekends and Hong Kong public holidays—don’t assume evenly spaced dates.
- Always validate that end_date is a past date. end_date cannot be today; set it to yesterday or the last known trading session.
- If you need today’s provisional print, first call the latest endpoint, then splice it onto your historical array with a distinct styling (e.g., dotted line) to indicate it’s intraday or mid-session.
- Normalize values per the same rule as latest: invert rates.HSI to display an index level, or use USDHSI if returned.
For parameters, field layout, and permissible date ranges per request, refer to the Indices-API Documentation. Verify HSI in the symbols directory here: Symbols page.
Convert a USD amount to HSI “index units”
You might want to express “how many HSI units would $X correspond to?” for alerts or allocations. There are two approaches:
- Use the Convert endpoint to have the API compute it server-side (recommended for auditability and consistency; see the Documentation for exact parameters).
- Compute locally from the latest response: amount_in_HSI = amount_in_USD × rates.HSI.
Example with local computation using the “latest” data you already fetched:
function usdToHSI(amountUSD, rates) {
// rates.HSI = index units per 1 USD
return amountUSD * rates.HSI;
}
// Using the payload from the latest call above:
const amountUSD = 1000;
const indexUnits = usdToHSI(amountUSD, { HSI: 0.00032027305114889 });
console.log(indexUnits.toFixed(6)); // 0.320273 HSI "units"
If you need the index level (points) that corresponds to a 1-USD notional, prefer rates.USDHSI (or 1 / rates.HSI). But for converting a cash amount to “index units,” multiply by rates.HSI as shown. For precision-sensitive workflows (e.g., auditing conversions or reconciling with downstream systems), use the Convert endpoint as documented and store the returned timestamp and input parameters along with the result.
Operational details that save you time
- Base currency and units: base is USD. rates.HSI is expressed in index units per USD. If you need an HSI “level,” use rates.USDHSI or 1 / rates.HSI.
- Update cadence: latest updates on a plan-based schedule (for example, every 60 minutes or every 10 minutes). Cache accordingly and don’t poll more frequently than necessary.
- Trading days: the Hang Seng Index trades on the Hong Kong Stock Exchange calendar. Expect no data on HK weekends and public holidays. Your time-series will skip those dates—handle gaps in charts cleanly.
- Timezone: timestamps are Unix seconds; display them in the user’s locale or label the session date explicitly. Do not assume your server timezone equals HK time.
- end_date rules: for time-series queries, set end_date to a completed day (yesterday or the last settled session). end_date cannot be today.
- Caching strategy: pin caches by (symbol, date, and update bucket). If you merge latest into historical, tag the merged point as provisional to avoid double-counting when the historical set later includes that date.
- Error handling: check success in the payload before reading rates. If a symbol is missing, reconcile it against the Supported Symbols and retry with a validated set.
Putting it together: dashboard flow for HSI
- On load, request a historical range via the time-series endpoint for HSI to draw your chart. Set end_date to yesterday (or last business day in HK) to comply with settlement timing.
- In parallel, call latest for HSI. If the timestamp is within your freshness window, compute a provisional index level from rates.USDHSI or 1 / rates.HSI and overlay it on the chart and the big number tile.
- For conversions (e.g., “$10,000 equals how many HSI units?”), either:
- Call the Convert endpoint with from=USD, to=HSI, amount=10000, and render the result; or
- Compute locally using the rate you already have: 10000 × rates.HSI.
- Cache both the historical segment and latest response. Invalidate latest on a cadence aligned to your plan’s refresh frequency.
When you need to expand beyond HSI (e.g., composite dashboards mixing Asian and US benchmarks), repeat the flow symbol-by-symbol and normalize each to its own freshness SLA. For network controls and hosting considerations, see MCP.
Security, scaling, and observability notes
- Secrets: keep your access_key on the server side. If you must call from the client, proxy through an endpoint that injects the key server-side and enforces per-user quotas.
- Retries: implement idempotent retries with exponential backoff. Avoid retrying faster than the update cadence—stale data won’t change mid-window.
- Monitoring: log timestamp, date, and the computed hsiLevel you display. This supports post-incident reviews when comparing with vendor records.
- Validations: ensure rates.USDHSI ≈ 1 / rates.HSI within your tolerated float epsilon. Alert if they diverge materially.
Where to find parameters and other capabilities
This article focused on the endpoints you need to ship HSI quickly: latest, time-series, and conversion. For optional features like intraday candles, OHLC, and fluctuation analysis, consult the Indices-API Documentation. If you’re browsing coverage or validating additional tickers, use the official Symbols directory. You can also explore the platform at indices-api.com to understand how it fits your stack.
FAQ
How do I display the conventional HSI level from the API response?
Use rates.USDHSI if present. If it’s not provided, compute 1 / rates.HSI. Both are derived from a USD base and should agree within float precision.
Why is my time-series missing dates?
Weekends and Hong Kong public holidays have no trading. The API returns only valid session dates. Handle gaps in your charting code and avoid resampling unless your UX calls for it.
Can I set end_date to today for time-series?
No. Set end_date to a completed session (e.g., yesterday or the last HK trading day). If you want a provisional current-day point, use the latest endpoint and merge it client-side.
What’s the update frequency for the latest endpoint?
It depends on your subscription plan (for example, every 60 minutes or every 10 minutes). Poll and cache according to your tier; polling more frequently won’t yield fresher data.
How do I convert USD to HSI units accurately?
Either call the Convert endpoint (recommended for a fully auditable server-side result; see the docs for parameters) or multiply amountUSD × rates.HSI from the latest response you already fetched.
Get an API key and start shipping
Spin up your HSI integration in minutes. Create your key here: Register for Indices-API. The Pro plan is $49.99/month with a 7-day trial. Use the latest endpoint for live tiles, time-series for charts, and conversion when you need USD-to-index unit math—then deploy with confidence.