Unofficial NEPSE (Nepal Stock Exchange) API client with auto-scaling worker pool for Node.js
npm install nepse-api-unofficial


A client for fetching data from Nepal Stock Exchange (NEPSE). This is an unofficial API client built with Bun in mind, featuring an auto-scaling worker pool for high-performance concurrent requests.
> Note: This project utilizes Bun workers. If you want to use this in Node.js, a PR is more than welcome!
This is an unofficial API client. It is not affiliated with, endorsed by, or connected to the Nepal Stock Exchange (NEPSE) in any way. Use at your own risk. The API endpoints may change without notice.
- 🚀 Auto-scaling worker pool - Dynamically scales workers based on load
- 📊 Full TypeScript support with comprehensive type definitions
- � Zod schemas for runtime type validation
- 📈 Market Data: Live market status, summary, supply/demand
- 🏢 Companies: List all companies, detailed security information
- 📉 Stock Data: Intraday charts, historical prices, market depth
- 🏆 Top Lists: Top gainers, losers, trade scrips, transactions, turnover
- 📰 Disclosures: Recent company disclosures
- ⚡ High Performance - Worker pool handles concurrent requests efficiently
- 🔄 Automatic retries - Built-in retry logic for failed requests
``bash`
bun add nepse-api-unofficial
`bash`
npm install nepse-api-unofficial
`bash`
yarn add nepse-api-unofficial
`bash`
pnpm add nepse-api-unofficial
- Bun runtime (Tested with v1.3.5)
- Node.js support is experimental/community-driven (PRs welcome)
- ESM module support
`typescript
import {
get_market_status,
getSummary,
getTopGainers,
getWorkerPoolStats,
shutdownWorkerPool,
} from 'nepse-api-unofficial';
// Get market status
const status = await get_market_status();
console.log('Market is:', status?.isOpen);
// Get market summary
const summary = await getSummary();
console.log('Total Turnover:', summary?.['Total Turnover Rs:']);
// Get top gainers
const gainers = await getTopGainers();
console.log('Top Gainer:', gainers?.[0]?.symbol);
// Check worker pool statistics
const stats = getWorkerPoolStats();
console.log('Active workers:', stats?.totalWorkers);
// Graceful shutdown when done
await shutdownWorkerPool();
`
| Function | Description |
|----------|-------------|
| getWorkerPool() | Get the worker pool instance |getWorkerPoolStats()
| | Get current worker pool statistics |shutdownWorkerPool()
| | Gracefully shutdown all workers |
| Function | Description | Return Type |
|----------|-------------|-------------|
| get_market_status() | Get current market open/close status | Promise |getSummary()
| | Get today's market summary | Promise |getPriceVolume()
| | Get price/volume for all securities | Promise |getSupplyDemand()
| | Get supply and demand data | Promise |liveMarketData()
| | Get live market data for all securities | Promise |
| Function | Description | Return Type |
|----------|-------------|-------------|
| getTopGainers() | Get top gaining stocks | Promise |getTopLoosers()
| | Get top losing stocks | Promise |getTopTenTradeScrips()
| | Get top traded by volume | Promise |getTopTenTransactions()
| | Get top by transaction count | Promise |getTopTenTurnover()
| | Get top by turnover | Promise |
| Function | Description | Return Type |
|----------|-------------|-------------|
| getNepseIndex() | Get all NEPSE indices | Promise |getNepseIndexIntraday(index)
| | Get intraday data for an index | Promise |getIndexPriceVolumeHistory(index, size)
| | Get historical data for an index | Promise |
| Function | Description | Return Type |
|----------|-------------|-------------|
| getSecurityList() | Get list of all securities | Promise |getCompaniesList()
| | Get list of all companies | Promise |get_security_detail(symbol)
| | Get detailed security info | Promise |
| Function | Description | Return Type |
|----------|-------------|-------------|
| stockIntraday(symbol) | Get intraday chart data | Promise |getStockDailyPrice(symbol)
| | Get daily price data | Promise |getPriceVolumeHistory(symbol, size)
| | Get historical price/volume | Promise |getMarket_depth(symbol)
| | Get market depth | Promise |
| Function | Description | Return Type |
|----------|-------------|-------------|
| disclosure() | Get recent company disclosures | Promise |
The worker pool automatically manages workers with the following defaults:
| Option | Default | Description |
|--------|---------|-------------|
| minWorkers | 1 | Minimum number of workers to maintain |maxWorkers
| | 10 | Maximum number of workers |idleTimeout
| | 30,000ms | Time before idle workers are terminated |taskTimeout
| | 60,000ms | Timeout for individual tasks |maxRetries
| | 3 | Number of retries for failed tasks |scalingThreshold
| | 0.8 | Scale up when 80% of workers are busy |
For advanced configuration, you can create a custom worker pool:
`typescript
import { WorkerPool } from 'nepse-api-unofficial';
const pool = new WorkerPool({
minWorkers: 2,
maxWorkers: 20,
idleTimeout: 60_000,
taskTimeout: 30_000,
maxRetries: 5,
scalingThreshold: 0.6,
logger: {
log: (msg) => console.log(msg),
warn: (msg) => console.warn(msg),
error: (msg, err) => console.error(msg, err),
},
});
`
`typescript
import {
get_market_status,
getSummary,
getTopGainers,
getTopLoosers,
getNepseIndex,
getWorkerPoolStats,
shutdownWorkerPool,
} from 'nepse-api-unofficial';
// Fire multiple requests concurrently
const [status, summary, gainers, losers, indices] = await Promise.all([
get_market_status(),
getSummary(),
getTopGainers(),
getTopLoosers(),
getNepseIndex(),
]);
console.log('Market:', status?.isOpen);
console.log('Summary:', summary);
console.log('Top Gainer:', gainers?.[0]);
console.log('Top Loser:', losers?.[0]);
console.log('NEPSE Index:', indices?.['NEPSE Index']);
// Check how the worker pool handled the load
console.log('Pool Stats:', getWorkerPoolStats());
// Always shutdown gracefully
await shutdownWorkerPool();
`
`typescript
import { get_security_detail, getMarket_depth } from 'nepse-api-unofficial';
// Get detailed information about NABIL bank
const nabil = await get_security_detail('NABIL');
console.log({
symbol: nabil?.security.symbol,
name: nabil?.security.securityName,
ltp: nabil?.securityDailyTradeDto?.lastTradedPrice,
});
// Get market depth
const depth = await getMarket_depth('NABIL');
console.log('Buy orders:', depth?.totalBuyQty);
console.log('Sell orders:', depth?.totalSellQty);
`
This package is written in TypeScript and provides full type definitions:
`typescript`
import type {
MarketStatus,
Summary,
SecurityDetailResponse,
TopGainerLoosers,
IndexKey,
WorkerPoolOptions,
// ... and many more
} from 'nepse-api-unofficial';
The package exports Zod schemas for runtime validation:
`typescript
import {
StockDailyPriceSchema,
marketDepthResponse,
SupplyDemandSchema,
} from 'nepse-api-unofficial';
// Validate data at runtime
const validated = StockDailyPriceSchema.parse(data);
`
All methods return null on failure instead of throwing exceptions:
`typescript
const status = await get_market_status();
if (!status) {
console.log('Failed to fetch market status');
return;
}
// Safe to use status here
console.log('Market:', status.isOpen);
`
NEPSE's API server sometimes has SSL certificate issues. This library temporarily disables SSL verification for API calls. While this is necessary for the API to work, be aware of this security consideration.
Contributions are welcome! Please feel free to submit a Pull Request.
1. Fork the repository
2. Create your feature branch (git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature'
3. Commit your changes ()git push origin feature/amazing-feature
4. Push to the branch ()
5. Open a Pull Request
`bashInstall dependencies
npm install
MIT License - see the LICENSE file for details.
Suraj Rimal - GitHub
- Nepal Stock Exchange for providing the data
- The open-source community for inspiration
---
⭐ Star this repo if you find it useful!