nepse_client.sync_client
Synchronous NEPSE client implementation.
This module provides a blocking, synchronous interface to the NEPSE API, suitable for scripts, notebooks, and applications that don’t require concurrency.
Classes
Synchronous client for NEPSE API. |
- class nepse_client.sync_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)
- 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]
- getDailyOthersSubindexGraph()[source]
Get NEPSE Daily Other Subindex Graph Data.
- Returns:
_description_
- Return type:
list[Any]
- getDailyTradingSubindexGraph()[source]
Get NEPSE Daily Trading Subindex Graph Data.
- Returns:
_description_
- Return type:
list[Any]
-
headers:
dict[str,str]
-
company_symbol_id_keymap:
Optional[dict[str,int]]
-
security_symbol_id_keymap:
Optional[dict[str,int]]
-
company_list:
Optional[list[dict]]
-
security_list:
Optional[list[dict]]
-
holiday_list:
Optional[list[dict]]
-
sector_scrips:
Optional[dict[str,list[str]]]