nepse_client.AsyncNepseClient
- class nepse_client.AsyncNepseClient[source]
Bases:
_NepseBaseAsynchronous client for NEPSE API.
This client provides non-blocking async methods to access Nepal Stock Exchange data, enabling concurrent operations and better performance for bulk requests.
- 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:
import asyncio from nepse_client import AsyncNepseClient async def main(): client = AsyncNepseClient() # Get market status status = await client.getMarketStatus() print(f"Market is {status['isOpen']}") # Concurrent requests status, summary, gainers = await asyncio.gather( client.getMarketStatus(), client.getSummary(), client.getTopGainers() ) asyncio.run(main())
Note
All methods are coroutines and must be awaited. The client automatically manages authentication tokens and handles token expiration.
- __init__(logger=None, mask_request_data=True, timeout=100.0)[source]
Initialize asynchronous NEPSE client.
- Parameters:
logger (Logger | None)
mask_request_data (bool)
timeout (float)
Methods
__init__([logger, mask_request_data, timeout])Initialize asynchronous NEPSE client.
close()Close HTTP client and cleanup resources.
Get headers with authorization token.
getCompanyDetails(symbol)Get detailed information for a specific company.
getCompanyIDKeyMap([force_update])Get mapping of company symbols to IDs.
Get list of all listed companies.
getCompanyPriceVolumeHistory(symbol[, ...])Get price and volume history for a company.
getDailyScripPriceGraph(symbol)Get daily price graph data for a scrip.
getDummyData()Get dummy data array.
getDummyID()Get dummy ID for current market state.
getFloorSheet([show_progress])Get complete floor sheet data.
getFloorSheetOf(symbol[, business_date])Get floor sheet for a specific company.
Get live market data.
Get current market status (open/closed).
Get NEPSE index data.
Get all NEPSE sub-indices.
Generate general payload ID.
getPOSTPayloadIDForFloorSheet([business_date])Generate payload ID for floor sheet requests.
Generate payload ID for scrip-related requests.
Get current price and volume data for all securities.
Get scrips grouped by sector.
getSecurityIDKeyMap([force_update])Get mapping of security symbols to IDs.
Get list of all securities (non-delisted).
Get market summary with turnover, trades, etc.
Get supply and demand data.
getSymbolMarketDepth(symbol)Get market depth for a symbol.
Get list of top gaining stocks.
Get list of top losing stocks.
Get top 10 scrips by trade volume.
Get top 10 scrips by transaction count.
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 async HTTP client with specified settings.
requestGETAPI(url[, ...])Make async GET request to NEPSE API.
requestPOSTAPI(url, payload_generator)Make async 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 asynchronous NEPSE client.
- Parameters:
logger (Logger | None)
mask_request_data (bool)
timeout (float)
- init_client(tls_verify)[source]
Initialize async HTTP client with specified settings.
- Parameters:
tls_verify (
bool) – Whether to verify TLS certificates- Return type:
None
- async requestGETAPI(url, include_authorization_headers=True)[source]
Make async 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
- async requestPOSTAPI(url, payload_generator)[source]
Make async POST request to NEPSE API.
- Parameters:
url (
str) – API endpoint URLpayload_generator – Async function to generate payload
- Return type:
Any- Returns:
Parsed response data
- async getAuthorizationHeaders()[source]
Get headers with authorization token.
- Return type:
dict[str,str]- Returns:
Dictionary of HTTP headers
- async getPOSTPayloadIDForScrips()[source]
Generate payload ID for scrip-related requests.
- Return type:
int
- async 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
- async getMarketStatus()[source]
Get current market status (open/closed).
- Return type:
dict[str,Any]
- async getPriceVolume()[source]
Get current price and volume data for all securities.
- Return type:
list[dict[str,Any]]
- async getSummary()[source]
Get market summary with turnover, trades, etc.
- Return type:
dict[str,Any]
- async getTopTenTradeScrips()[source]
Get top 10 scrips by trade volume.
- Return type:
list[dict[str,Any]]
- async getTopTenTransactionScrips()[source]
Get top 10 scrips by transaction count.
- Return type:
list[dict[str,Any]]
- async getTopTenTurnoverScrips()[source]
Get top 10 scrips by turnover.
- Return type:
list[dict[str,Any]]
- async getTradingAverage(business_date=None, nDays=180)[source]
Get trading average data.
- Return type:
dict[str,Any]- Parameters:
business_date (str | None)
nDays (int)
- async getSecurityList()[source]
Get list of all securities (non-delisted).
- Return type:
list[dict[str,Any]]
- async getCompanyIDKeyMap(force_update=False)[source]
Get mapping of company symbols to IDs.
- Return type:
dict[str,int]- Parameters:
force_update (bool)
- async getSecurityIDKeyMap(force_update=False)[source]
Get mapping of security symbols to IDs.
- Return type:
dict[str,int]- Parameters:
force_update (bool)
- async getCompanyDetails(symbol)[source]
Get detailed information for a specific company.
- Return type:
dict[str,Any]- Parameters:
symbol (str)
- async getCompanyPriceVolumeHistory(symbol, start_date=None, end_date=None)[source]
Get price and volume history for a company.
- Return type:
dict[str,Any]- Parameters:
symbol (str)
start_date (str | date | None)
end_date (str | date | None)
- async getDailyScripPriceGraph(symbol)[source]
Get daily price graph data for a scrip.
- Return type:
dict[str,Any]- Parameters:
symbol (str)
- async getFloorSheet(show_progress=False)[source]
Get complete floor sheet data.
- Parameters:
show_progress (
bool) – Show progress bar during download- Return type:
list[dict[str,Any]]- Returns:
List of all floor sheet records