@rumess/nepse-api
v1.0.5
Published
Unofficial Node.js library to interface with nepalstock.com
Maintainers
Readme
@rumess/nepse-api
Unofficial Node.js library to interface with nepalstock.com. This is a TypeScript/Node.js port of the Python NEPSE API library.
Features
- TypeScript Support: Full type definitions for better development experience
- Command Line Interface: Built-in CLI tool for quick data access
- Web Server: Express.js server for API endpoints
- Comprehensive Data Access: Market data, company information, indices, and more
- Error Handling: Custom error classes for better debugging
- SSL Certificate Handling: Automatic SSL verification bypass for NEPSE's certificate issues
- Token Management: Automatic token handling and refresh
- Dummy ID Management: Handles NEPSE's dummy ID requirements
Installation
Using npm
npm install @rumess/nepse-apiQuick Start
Basic Usage
import { Nepse } from '@rumess/nepse-api';
// Create instance
const nepse = new Nepse();
nepse.setTLSVerification(false); // Handle SSL certificate issues
// Get market data
const marketStatus = await nepse.getMarketStatus();
console.log(marketStatus);
const companyList = await nepse.getCompanyList();
console.log(companyList);Command Line Interface
# Show version
nepse-cli --version
# Get market status
nepse-cli status
# Get market status and save to file
nepse-cli status --output-file status.json
# Get market status in CSV format
nepse-cli status --to-csv --output-file status.csv
# Get floorsheet
nepse-cli floorsheet
# Get floorsheet and save to file
nepse-cli floorsheet --output-file floor.json
# Get floorsheet in CSV format
nepse-cli floorsheet --to-csv --output-file floor.csv
# Hide progress bar when getting floorsheet
nepse-cli floorsheet --hide-progressbar
# Start web server
nepse-cli serverAPI Reference
Core Class
Nepse
Main class for all NEPSE API operations.
const nepse = new Nepse();
nepse.setTLSVerification(false);
// Market data
const status = await nepse.getMarketStatus();
const summary = await nepse.getMarketSummary();
const indices = await nepse.getNepseIndex();
const subIndices = await nepse.getNepseSubIndices();
// Company data
const companies = await nepse.getCompanyList();
const securities = await nepse.getSecurityList();
// Trading data
const floorsheet = await nepse.getFloorSheet();
const liveMarket = await nepse.getLiveMarket();
const topGainers = await nepse.getTopTenGainers();
const topLosers = await nepse.getTopTenLosers();
const topTradeScrips = await nepse.getTopTenTradeScrips();
const topTransactionScrips = await nepse.getTopTenTransactionScrips();
const topTurnoverScrips = await nepse.getTopTenTurnoverScrips();
// Market depth
const marketDepth = await nepse.getMarketDepth('NICL');
// Security details
const securityDetails = await nepse.getSecurityDetails('NICL');
const securityGraph = await nepse.getSecurityDailyGraph('NICL');
const securityPriceVolumeHistory = await nepse.getSecurityPriceVolumeHistory('NICL');
// Today's price data
const todaysPrice = await nepse.getTodaysPriceVolumeHistory();Available Methods (Security)
Market Data
getMarketStatus()- Get current market statusgetMarketSummary()- Get market summarygetNepseIndex()- Get NEPSE indicesgetNepseSubIndices()- Get sub-indicesgetLiveMarket()- Get live market data
Security Information
getSecurityList(force?)- Get list of all securities (cached by default)getSecurityDetails(symbol)- Get specific security detailsgetSecurityDailyGraph(symbol)- Get security's daily graph datagetSecurityPriceVolumeHistory(symbol)- Get security's price volume history
Trading Data
getFloorSheet(options?)- Get floorsheet with optional filteringpage- Page number (default: 0)size- Page size (default: 500)symbol- Filter by company symbolbuyerBroker- Filter by buyer broker IDsellerBroker- Filter by seller broker ID
getTopTenGainers()- Get top 10 gainersgetTopTenLosers()- Get top 10 losersgetTopTenTradeScrips()- Get top 10 by trade volumegetTopTenTransactionScrips()- Get top 10 by transaction countgetTopTenTurnoverScrips()- Get top 10 by turnovergetTodaysPriceVolumeHistory(options?)- Get today's price datapage- Page number (default: 0)size- Page size (default: 500)businessDate- Specific business date
Market Depth
getMarketDepth(symbol)- Get market depth for a symbol
Index Graph Data
getIndexDailyGraph(indexId)- Get daily graph for specific indexgetNepseIndexDailyGraph()- NEPSE index daily graph
Index IDs
Use the IndexIDEnum for index graph data:
import { IndexIDEnum } from '@rumess/nepse-api';
// Available indices
IndexIDEnum.NEPSE // '58'
IndexIDEnum.SENSITIVE // '57'
IndexIDEnum.FLOAT // '62'
IndexIDEnum.SENSITIVE_FLOAT // '63'
IndexIDEnum.BANKING // '51'
IndexIDEnum.DEVELOPMENT_BANK // '55'
IndexIDEnum.FINANCE // '60'
IndexIDEnum.HOTEL_TOURISM // '52'
IndexIDEnum.HYDRO // '54'
IndexIDEnum.INVESTMENT // '67'
IndexIDEnum.LIFE_INSURANCE // '65'
IndexIDEnum.MANUFACTURING // '56'
IndexIDEnum.MICROFINANCE // '64'
IndexIDEnum.MUTUAL_FUND // '66'
IndexIDEnum.NON_LIFE_INSURANCE // '59'
IndexIDEnum.OTHERS // '53'
IndexIDEnum.TRADING // '61'
// Example usage
const nepseGraph = await nepse.getIndexDailyGraph(IndexIDEnum.NEPSE);Web Server
Start the web server to access NEPSE data via HTTP endpoints:
nepse-cli --start-serverAvailable endpoints:
GET /- Server information and available routesGET /summary- Market summaryGET /nepseIndex- NEPSE indicesGET /nepseSubIndices- Sub-indicesGET /topGainers- Top gainersGET /topLosers- Top losersGET /topTenTradeScrips- Top 10 by trade volumeGET /topTenTransactionScrips- Top 10 by transaction countGET /topTenTurnoverScrips- Top 10 by turnoverGET /companyList- Company listGET /securityList- Security listGET /liveMarket- Live market dataGET /marketDepth?symbol=SYMBOL- Market depth for symbolGET /floorsheet- Today's floorsheetGET /isNepseOpen- Market statusGET /companyDetails?symbol=SYMBOL- Company detailsGET /companyPriceVolumeHistory?symbol=SYMBOL- Company price volume historyGET /dailyIndexGraph?indexId=ID- Index daily graphGET /dailyNepseIndexGraph- NEPSE index daily graphGET /dailyScripPriceGraph?symbol=SYMBOL- Company daily graph
Error Handling
The library provides custom error classes:
import {
NepseError,
NepseNetworkError,
NepseInvalidClientRequest,
NepseInvalidServerResponse,
NepseTokenExpired
} from '@rumess/nepse-api';
try {
const data = await nepse.getMarketStatus();
} catch (error) {
if (error instanceof NepseNetworkError) {
console.log('Network error occurred');
} else if (error instanceof NepseTokenExpired) {
console.log('Token expired, retrying...');
}
}TypeScript Support
Full TypeScript definitions are included:
import {
MarketStatus,
Company,
Security,
MarketSummary,
NepseIndex,
NepseSubIndex,
TopTenItem,
TopTenTradeScripItem,
TopTenTransactionScripItem,
TopTenTurnoverScripItem,
FloorSheet,
MarketDepth,
LiveMarketData,
CompanyDetails,
CompanyDailyGraph,
CompanyPriceVolumeHistory,
TodaysPrice,
IndexGraphData
} from '@rumess/nepse-api';
const companies: Company[] = await nepse.getCompanyList();
const status: MarketStatus = await nepse.getMarketStatus();Development
Building
npm run buildTesting
npm testLinting
npm run lintFormatting
npm run formatDevelopment Mode
npm run devSSL Certificate Issues
NEPSE's website has SSL certificate issues. The library automatically handles this by providing a setTLSVerification(false) method:
const nepse = new Nepse();
nepse.setTLSVerification(false); // Required for NEPSE's SSL issuesContributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License
Disclaimer
This is an unofficial library and is not affiliated with NEPSE or nepalstock.com. Use at your own risk.
