11import asyncio
22import datetime
3- import json
4- from ast import Index
53from typing import List , Optional
64
75import humps
86
97from nepse .errors import CompanyNotFound
108from nepse .market .types import FloorSheet , MarketCap , MarketSummary , SectorwiseSummary
11- from nepse .utils import _ClientWrapperHTTPX
9+ from nepse .utils import _ClientWrapperHTTPX , get
1210
1311BASE_URL = "https://newweb.nepalstock.com/api/nots"
1412
@@ -177,11 +175,8 @@ async def _get_floorsheet_page(page_no: int) -> None:
177175 await asyncio .sleep (sleep_time )
178176
179177 return contents
180-
181- async def _fetch_sectories_summaries (self , ** attrs ):
182- pass
183178
184- async def get_sectorwise_summaries (
179+ async def get_sectorwise_summary (
185180 self , business_date : Optional [datetime .date ] = None
186181 ) -> List [SectorwiseSummary ]:
187182 """Get the sectorwise summary
@@ -190,7 +185,7 @@ async def get_sectorwise_summaries(
190185 business_date (Optional[datetime.date]): The date for which to fetch the data
191186
192187 Returns:
193- List[SectorwiseSummary]: The list of containing data related to sector wise summary
188+ List[SectorwiseSummary]: The list containing data related to sector wise summary
194189 """
195190 business_date = business_date or datetime .date .today ()
196191
@@ -202,11 +197,30 @@ async def get_sectorwise_summaries(
202197
203198 return [SectorwiseSummary (** model ) for model in sector_wise_summary ]
204199
205- async def get_sectorwise_summary (self , ** attrs ) -> SectorwiseSummary :
206- pass
200+ async def get_market_summaries (self ) -> List [MarketSummary ]:
201+ """Get the market summaries
202+
203+ Returns:
204+ List[MarketSummary]: The list of Objects containing related to Market Summary
205+ """
206+ market_summary = humps .decamelize (
207+ await self ._client_wrapper ._get_json (f"{ BASE_URL } /market-summary-history" )
208+ )
207209
210+ return [MarketSummary (** model ) for model in market_summary ]
208211
209- async def get_market_summaries (self ) -> List [MarketSummary ]:
210- pass
211-
212-
212+ async def get_market_summary (
213+ self , date : Optional [datetime .date ] = None
214+ ) -> MarketSummary :
215+ """Get the market summary for a specific date
216+
217+ Args:
218+ date (Optional[datetime.date]): Date to filter the market summary. Defaults to today
219+
220+ Returns:
221+ MarketSummary: [description]
222+ """
223+ market_summaries = await self .get_market_summaries ()
224+ date = date or datetime .date .today ()
225+
226+ return get (market_summaries , business_date = date )
0 commit comments