DEV Community

Cover image for I built a free API for Pakistani mutual fund NAVs (because MUFAP's own one doesn't work)
Saad Salman
Saad Salman

Posted on Originally published at saadsalman.org

I built a free API for Pakistani mutual fund NAVs (because MUFAP's own one doesn't work)

Originally published on saadsalman.org in July 2026. Updated August 2026 with NAV history, fund metadata and a free public dataset.

Why MUFAP's own API doesn't work

I needed daily NAV data for Pakistani mutual funds for Gramafin, a personal finance app I'm building. MUFAP, the Mutual Funds Association of Pakistan, does have a JSON API. It just doesn't work for anyone who isn't a browser. I replicated Chrome's exact headers and parameters and still got 500 errors on every server-side request. My best guess is the frontend JavaScript establishes some session or anti-forgery state that isn't practical to replicate outside a real browser.

Their public Fund Directory page is a different story. It's a plain server-rendered HTML table with over 500 funds, current NAVs and prices sitting right in the markup. No auth, no pagination, no JavaScript required. So instead of fighting the broken API, I scrape the page that works.

To be fair, there is a paid option

CapitalStake sells a serious Pakistani mutual funds data product with AUMs, sector allocations, holdings history and uptime guarantees, delivered over REST, WebSocket, CSV and Excel. It's a commercial product with a "request a consultation" button, and if you're an organization that needs deep historical data and strict SLAs, that's probably where you should go.

But most developers just need today's NAVs as JSON without a sales call or a subscription. That's the gap this fills.

Turning it into its own thing

The scraper started as a piece of Gramafin's backend and grew into a standalone MIT-licensed project: pakistan-mutual-funds-api. If you're building anything fintech-adjacent in Pakistan, you've probably hit this exact wall, so I pulled it out into something you can clone and run in two minutes. No database to set up, no cloud account to configure, no framework to learn.

What it actually does

Three things:

  • Scrapes MUFAP's Fund Directory with cheerio, pulling each fund's name, AMC, NAV, offer price and category
  • Stores the result as plain JSON on disk, no Postgres or Redis required
  • Serves it from a small Express API at GET /api/funds, CORS wide open so you can call it straight from frontend code

By default it re-scrapes once a day and skips weekends, since MUFAP only publishes new NAVs on business days. Both are configurable through environment variables.

Try it

git clone https://github.com/saadsalmankhan/pakistan-mutual-funds-api.git
cd pakistan-mutual-funds-api
npm install
cp .env.example .env
npm run dev
Enter fullscreen mode Exit fullscreen mode

The API is up at localhost:4000/api/funds, and the README covers every configuration option.

Update (August 2026): it's a dataset now, not just an API

Since publishing this, the project grew the pieces people kept asking for.

NAV history. Every scrape now appends each fund's NAV to a per-fund NDJSON file, so any instance builds its own time series from the day it starts running. New endpoint: GET /api/funds/:id/history?from=&to=.

Lookups and filters. GET /api/funds/:id for a single fund, plus ?category=, ?amc=, ?q= and ?shariah=true on the list endpoint, and /api/categories and /api/amcs for building dropdowns.

Shariah flags, benchmarks and expense ratios. Every fund now carries a shariah boolean (295 of 549 funds are Shariah-compliant, derived from MUFAP's own category names) and a benchmark mapping: KSE-100 for conventional equity categories, KMI-30 for Shariah equity, null where no single index honestly applies. A separate npm run enrich pulls each fund's total expense ratio, management fee and inception date from MUFAP's expense ratios table and merges them into the snapshot.

A public dataset that updates itself. If you don't want to run anything at all: pakistan-mutual-funds-data is a repo where a GitHub Action scrapes MUFAP every business day and commits the snapshot, the growing NAV history and the fund metadata. You can curl the raw files and be done, and the commit log doubles as an audit trail of every data change.

Why this matters: a team building an AI mutual funds advisor wrote about their AWS hackathon project that no clean, structured, public dataset existed for Pakistani mutual funds, and they had to assemble 301,749 NAV rows by hand before they could build anything. That dataset now exists, it updates itself daily and it's free.

If you build something with it, I'd genuinely like to hear about it. I'm at saadsalman.org.

Top comments (0)