Skip to content

About

Track SGB and NPS Funds prices using API (and on Google Sheets)

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

NPS/SGB API

A small Cloudflare Worker that exposes plaintext endpoints for SGB prices and NPS NAV values.

Routes

  • GET /sgb/:symbol returns the latest price for any official SGB symbol.
  • GET /nps/:scheme returns the latest NAV for any official NPS scheme code or a readable alias.

SGB symbols

Every SGB in the exchange catalogue is supported by its official symbol. For example:

  • https://<your-worker>/sgb/SGBSEP29VI
  • https://<your-worker>/sgb/SGBJUN31I

Symbols are case-insensitive but must be supplied in their official compact form, without hyphens. For example, use /sgb/SGBSEP29VI. This matches the NPS route: pass the official identifier directly rather than relying on a maintained list.

NPS schemes

Every scheme in the NPS catalogue is supported by its official scheme code. This removes the need to add a code change whenever the catalogue changes.

For example, these equivalent URLs return HDFC Scheme E - Tier I:

  • https://<your-worker>/nps/SM008001
  • https://<your-worker>/nps/hdfc-e-tier-1

The official scheme-code format is SM followed by six digits. It is case-insensitive, so /nps/sm008001 also works. Find scheme codes in the official Protean NPS NAV search.

Readable aliases

The common HDFC options retain convenient aliases with unambiguous tier names:

  • hdfc-e-tier-1, hdfc-c-tier-1, hdfc-g-tier-1
  • hdfc-e-tier-2, hdfc-c-tier-2, hdfc-g-tier-2
  • hdfc-equity-advantage-tier-1

Google Sheets

=IMPORTDATA("https://nps-sgb-api.vsvipul.workers.dev/nps/"&E236)

Set E236 to an official NPS scheme code such as SM008001.

Caching

  • SGB responses: max-age=300
  • NPS responses: max-age=86400

The Worker also keeps successful responses in Cloudflare's Worker Cache API, avoiding repeat upstream requests from the same Cloudflare location. If an upstream temporarily fails, it can return the last successful result with X-Data-Stale: true for up to one day.

For cache hits that bypass Worker execution entirely, configure a Cloudflare Cache Rule for the Worker domain:

  • /sgb/*: cache 200 responses for 300 seconds
  • /nps/*: cache 200 responses for 86400 seconds
  • 4xx and 5xx: do not cache

Development

npm install
npm run dev

Deploy

npx wrangler deploy

About

Track SGB and NPS Funds prices using API (and on Google Sheets)

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages