nepse_client.NepseClient
- class nepse_client.NepseClient[source]
Bases:
_NepseBaseSynchronous client for NEPSE API.
This client provides blocking methods to access Nepal Stock Exchange data including market status, company information, trading data, and more.
- Parameters:
logger (
Optional[Logger]) – Optional custom logger instancemask_request_data (
bool) – Whether to mask sensitive data in logs (default: True)timeout (
float) – Request timeout in seconds (default: 100.0)
Example
Basic usage:
from nepse_client import NepseClient client = NepseClient() # Get market status status = client.getMarketStatus() print(f"Market is {status['isOpen']}") # Get company details nabil = client.getCompanyDetails("NABIL") print(f"NABIL LTP: {nabil['lastTradedPrice']}")
Note
The client automatically manages authentication tokens and handles token expiration transparently.
- __init__(logger=None, mask_request_data=True, timeout=100.0)[source]
Initialize synchronous NEPSE client.
- Parameters:
logger (Logger | None)
mask_request_data (bool)
timeout (float)
Methods
__init__([logger, mask_request_data, timeout])Initialize synchronous NEPSE client.
close()Close HTTP client and cleanup resources.
Get headers with authorization token.
getCompanyAGM([company_id])Get Annual General Meeting (AGM) information for a specific company.
getCompanyDetails(symbol)Get detailed information for a specific company.
getCompanyDividend([company_id])Get dividend information for a specific company.
getCompanyFinancialDetails([company_id])Get financial details for a specific company.
getCompanyIDKeyMap([force_update])Get mapping of company symbols to IDs.
Get list of all listed companies.
getCompanyMarketDepth([company_id])Get market depth information for a specific company.
getCompanyNewsList([page, page_size, ...])Get list of company news.
getCompanyPriceVolumeHistory(symbol[, ...])Get price and volume history for a company.
Get NEPSE Daily Bank Subindex Graph Data.
Get NEPSE Development Bank Subindex Graph Data.
Get NEPSE Daily Finance Subindex Graph Data.
Get NEPSE Daily Float Index Graph Data.
Gat NEPSE Daily Hotel Tourism Subindex Graph Data.
Get NEPSE Daily Hydro Subindex Graph Data.
Get NEPSE Daily Investment Subindex Graph Data.
Get NEPSE Daily Life Insurance Subindex Graph Data.
Get NEPSE Daily Manufacturing Subindex Graph Data.
Get NEPSE Daily Microfinance Subindex Graph Data.
Get NEPSE Daily Mutual Fund Subindex Graph Data.
Get price volume history for a business date.
Get NEPSE Daily Non Life Insurance Subindex Graph data.
Get NEPSE Daily Other Subindex Graph Data.
getDailyScripPriceGraph(symbol)Get daily price graph data for a scrip.
Get NEPSE Daily Sensitive Float Index Graph Data.
Get NEPSE Daily Sensitive Index Graph.
Get NEPSE Daily Trading Subindex Graph Data.
getDebentureAndBondList([bond_type])Get list of debentures and bonds.
getDummyData()Get dummy data array.
getDummyID()Get dummy ID for current market state.
getFloorSheet([show_progress, paginated, page])Get floor sheet data.
getFloorSheetOf(symbol[, business_date, size])Get floor sheet for a specific company.
getHolidayList([year])Get list of market holidays for specified year.
getLiveMarket()Get live market data.
getMarketStatus()Get current market status (open/closed).
getNepseIndex()Get NEPSE index data.
getNepseNotice([page, size])Get NEPSE Notice data.
getNepseSubIndices()Get all NEPSE sub-indices.
getNewsAndAlertList([page, page_size, ...])Get list of News and Alert.
Generate general payload ID.
getPOSTPayloadIDForFloorSheet([business_date])Generate payload ID for floor sheet requests.
Generate payload ID for scrip-related requests.
getPressRelease([page, size])Get list of Press release.
getPriceVolume()Get current price and volume data for all securities.
getPriceVolumeHistory([business_date])Get price volume history for a business date.
Get scrips grouped by sector.
getSecurityIDKeyMap([force_update])Get mapping of security symbols to IDs.
Get list of all securities (non-delisted).
getSummary()Get market summary with turnover, trades, etc.
getSupplyDemand()Get supply and demand data.
getSymbolMarketDepth(symbol)Get market depth for a symbol.
getTopGainers()Get list of top gaining stocks.
getTopLosers()Get list of top losing stocks.
getTopTenTradeScrips()Get top 10 scrips by trade volume.
getTopTenTransactionScrips()Get top 10 scrips by transaction count.
getTopTenTurnoverScrips()Get top 10 scrips by turnover.
getTradingAverage([business_date, nDays])Get trading average data.
get_full_url(api_url)Construct full URL from API endpoint.
get_random_user_agent()Get random user agent.
handle_response(response[, request_data])Process HTTP response and handle errors.
init_client(tls_verify)Initialize HTTP client with specified settings.
requestGETAPI(url[, ...])Make GET request to NEPSE API.
requestPOSTAPI(url, payload_generator)Make POST request to NEPSE API.
setTLSVerification([flag])Enable or disable TLS certificate verification.
Attributes
- __init__(logger=None, mask_request_data=True, timeout=100.0)[source]
Initialize synchronous NEPSE client.
- Parameters:
logger (Logger | None)
mask_request_data (bool)
timeout (float)
- init_client(tls_verify)[source]
Initialize HTTP client with specified settings.
- Parameters:
tls_verify (
bool) – Whether to verify TLS certificates- Return type:
None
- requestGETAPI(url, include_authorization_headers=True)[source]
Make GET request to NEPSE API.
- Parameters:
url (
str) – API endpoint URLinclude_authorization_headers (
bool) – Whether to include auth headers
- Return type:
Any- Returns:
Parsed response data
- requestPOSTAPI(url, payload_generator)[source]
Make POST request to NEPSE API.
- Parameters:
url (
str) – API endpoint URLpayload_generator – Function to generate payload
- Return type:
Any- Returns:
Parsed response data
- getAuthorizationHeaders()[source]
Get headers with authorization token.
- Return type:
dict[str,str]- Returns:
Dictionary of HTTP headers
- getPOSTPayloadIDForScrips()[source]
Generate payload ID for scrip-related requests.
- Return type:
int
- getPOSTPayloadIDForFloorSheet(business_date=None)[source]
Generate payload ID for floor sheet requests.
- Parameters:
business_date (
Union[str,date,None]) – Business date (YYYY-MM-DD string or date object)- Return type:
int- Returns:
Payload ID integer
- getCompanyList()[source]
Get list of all listed companies.
- Return type:
list[dict[str,Any]]- Returns:
List of company dictionaries
Note
Results are cached internally. Subsequent calls return cached data unless cache is cleared.
- getSecurityList()[source]
Get list of all securities (non-delisted).
- Return type:
list[dict[str,Any]]- Returns:
List of security dictionaries
- getCompanyIDKeyMap(force_update=False)[source]
Get mapping of company symbols to IDs.
- Parameters:
force_update (
bool) – Force refresh of cached data- Return type:
dict[str,int]- Returns:
Dictionary mapping symbol to company ID
- getSecurityIDKeyMap(force_update=False)[source]
Get mapping of security symbols to IDs.
- Parameters:
force_update (
bool) – Force refresh of cached data- Return type:
dict[str,int]- Returns:
Dictionary mapping symbol to security ID
- getSectorScrips()[source]
Get scrips grouped by sector.
- Return type:
dict[str,list[str]]- Returns:
Dictionary mapping sector name to list of symbols
- getCompanyDetails(symbol)[source]
Get detailed information for a specific company.
- Parameters:
symbol (
str) – Company stock symbol (e.g., “NABIL”)- Return type:
dict[str,Any]- Returns:
Dictionary with company details
- Raises:
KeyError – If symbol not found
- getCompanyFinancialDetails(company_id=None)[source]
Get financial details for a specific company.
- Parameters:
company_id (str, optional) – The unique identifier for the company. If not provided, the behavior depends on the API endpoint’s default or requirements.
- Returns:
- A list of dictionaries containing financial details for the company.
Each dictionary might include keys like ‘period’, ‘financialMetrics’, ‘applicationDocumentDetailsList’, etc., as returned by the API. Returns an empty list if no data is found or an error occurs during the API request or processing.
The ‘applicationDocumentDetailsList’ within each item may be augmented with ‘fullFilePath’ and ‘fullEncryptedPath’ keys for
- Return type:
list
- getCompanyAGM(company_id=None)[source]
Get Annual General Meeting (AGM) information for a specific company.
- Parameters:
company_id (str, optional) – The unique identifier for the company. If not provided, the behavior depends on the API endpoint’s default or requirements.
- Returns:
- A list of dictionaries containing AGM details for the company.
Each dictionary might include keys like ‘meetingDate’, ‘agenda’, ‘applicationDocumentDetailsList’, etc., as returned by the API. Returns an empty list if no data is found or an error occurs during the API request or processing.
The ‘applicationDocumentDetailsList’ within each item may be augmented with a ‘fullFilePath’ key for document access.
- Return type:
list
- getCompanyDividend(company_id=None)[source]
Get dividend information for a specific company.
- Parameters:
company_id (str, optional) – The unique identifier for the company. If not provided, the behavior depends on the API endpoint’s default or requirements.
- Returns:
- A list of dictionaries containing dividend details for the company.
Each dictionary might include keys like ‘dividendType’, ‘rate’, ‘applicationDocumentDetailsList’, etc., as returned by the API. Returns an empty list if no data is found or an error occurs during the API request or processing.
The ‘applicationDocumentDetailsList’ within each item may be augmented with a ‘fullFilePath’ key for document access.
- Return type:
list
- getCompanyMarketDepth(company_id=None)[source]
Get market depth information for a specific company.
Market depth typically includes buy and sell orders at various price levels.
- Parameters:
company_id (str, optional) – The unique identifier (symbol or code) for the company/security. If not provided, the behavior depends on the API endpoint’s default or requirements.
- Returns:
- A list containing market depth data for the company.
The structure of the data depends on the API response, but it usually includes buy/sell orders with prices and volumes. Returns an empty list if no data is found or an error occurs during the API request.
- Return type:
list
- getCompanyPriceVolumeHistory(symbol, start_date=None, end_date=None)[source]
Get price and volume history for a company.
- Parameters:
symbol (
str) – Company symbolstart_date (
Union[str,date,None]) – Start date (YYYY-MM-DD or date object)end_date (
Union[str,date,None]) – End date (YYYY-MM-DD or date object)
- Return type:
dict[str,Any]- Returns:
Dictionary with paginated history data
- getDailyScripPriceGraph(symbol)[source]
Get daily price graph data for a scrip.
- Parameters:
symbol (
str) – Company symbol- Return type:
dict[str,Any]- Returns:
Graph data dictionary
- getFloorSheet(show_progress=False, paginated=False, page=None)[source]
Get floor sheet data.
- Parameters:
show_progress (
bool) – Show progress bar during downloadpaginated (
bool) – Return list of pages instead of flattened listpage (
Optional[int]) – Get specific page number (0-indexed)
- Return type:
Union[list[dict[str,Any]],list[list[dict[str,Any]]],dict[str,Any]]- Returns:
Floor sheet data (format depends on parameters)
- getFloorSheetOf(symbol, business_date=None, size=500)[source]
Get floor sheet for a specific company.
- Parameters:
symbol (
str) – Company symbolbusiness_date (
Union[str,date,None]) – Business date (YYYY-MM-DD string or date object)size (int)
- Return type:
list[dict[str,Any]]- Returns:
List of floor sheet records
- getSymbolMarketDepth(symbol)[source]
Get market depth for a symbol.
- Parameters:
symbol (
str) – Company symbol- Return type:
dict[str,Any]- Returns:
Market depth data
- getHolidayList(year=2025)[source]
Get list of market holidays for specified year.
- Return type:
list[dict[str,Any]]- Parameters:
year (int)
- getDebentureAndBondList(bond_type='debenture')[source]
Get list of debentures and bonds.
- Return type:
list[dict[str,Any]]- Parameters:
bond_type (str)
- getCompanyNewsList(page=0, page_size=100, is_strip_tags=True)[source]
Get list of company news.
- Return type:
dict[str,Any]- Parameters:
page (int)
page_size (int)
is_strip_tags (bool)
- getNewsAndAlertList(page=0, page_size=100, is_strip_tags=True)[source]
Get list of News and Alert.
- Return type:
dict[str,Any]- Parameters:
page (int)
page_size (int)
is_strip_tags (bool)
- getPressRelease(page=0, size=20)[source]
Get list of Press release.
- Parameters:
page (int, optional) – _description_. Defaults to None.
size (int, optional) – _description_. Defaults to 20.
- Returns:
Response containing press releases with full file paths
- Return type:
dict[str, Any]
- getNepseNotice(page=0, size=10)[source]
Get NEPSE Notice data.
- Parameters:
page (int, optional) – _description_. Defaults to 0.
size (int, optional) – _description_. Defaults to 10.
- Returns:
_description_
- Return type:
dict[str, Any]
- getPriceVolumeHistory(business_date=None)[source]
Get price volume history for a business date.
- Return type:
dict[str,Any]- Parameters:
business_date (str | None)
- getDailyNepseIndexGraph()[source]
Get price volume history for a business date.
- Return type:
list[Any]
- getDailySensitiveIndexGraph()[source]
Get NEPSE Daily Sensitive Index Graph.
- Returns:
_description_
- Return type:
list[Any]
- getDailyFloatIndexGraph()[source]
Get NEPSE Daily Float Index Graph Data.
- Returns:
_description_
- Return type:
list[Any]
- getDailySensitiveFloatIndexGraph()[source]
Get NEPSE Daily Sensitive Float Index Graph Data.
- Returns:
_description_
- Return type:
list[Any]
- getDailyBankSubindexGraph()[source]
Get NEPSE Daily Bank Subindex Graph Data.
- Returns:
_description_
- Return type:
list[Any]
- getDailyDevelopmentBankSubindexGraph()[source]
Get NEPSE Development Bank Subindex Graph Data.
- Returns:
_description_
- Return type:
list[Any]
- getDailyFinanceSubindexGraph()[source]
Get NEPSE Daily Finance Subindex Graph Data.
- Returns:
_description_
- Return type:
list[Any]
- getDailyHotelTourismSubindexGraph()[source]
Gat NEPSE Daily Hotel Tourism Subindex Graph Data.
- Returns:
_description_
- Return type:
list[Any]
- getDailyHydroSubindexGraph()[source]
Get NEPSE Daily Hydro Subindex Graph Data.
- Returns:
_description_
- Return type:
list[Any]
- getDailyInvestmentSubindexGraph()[source]
Get NEPSE Daily Investment Subindex Graph Data.
- Returns:
_description_
- Return type:
list[Any]
- getDailyLifeInsuranceSubindexGraph()[source]
Get NEPSE Daily Life Insurance Subindex Graph Data.
- Returns:
_description_
- Return type:
list[Any]
- getDailyManufacturingSubindexGraph()[source]
Get NEPSE Daily Manufacturing Subindex Graph Data.
- Returns:
_description_
- Return type:
list[Any]
- getDailyMicrofinanceSubindexGraph()[source]
Get NEPSE Daily Microfinance Subindex Graph Data.
- Returns:
_description_
- Return type:
list[Any]
- getDailyMutualfundSubindexGraph()[source]
Get NEPSE Daily Mutual Fund Subindex Graph Data.
- Returns:
_description_
- Return type:
list[Any]
- getDailyNonLifeInsuranceSubindexGraph()[source]
Get NEPSE Daily Non Life Insurance Subindex Graph data.
- Returns:
_description_
- Return type:
list[Any]