1
1
import asyncio
2
2
import datetime
3
- import json
4
- from ast import Index
5
3
from typing import List , Optional
6
4
7
5
import humps
8
6
9
7
from nepse .errors import CompanyNotFound
10
8
from nepse .market .types import FloorSheet , MarketCap , MarketSummary , SectorwiseSummary
11
- from nepse .utils import _ClientWrapperHTTPX
9
+ from nepse .utils import _ClientWrapperHTTPX , get
12
10
13
11
BASE_URL = "https://newweb.nepalstock.com/api/nots"
14
12
@@ -177,11 +175,8 @@ async def _get_floorsheet_page(page_no: int) -> None:
177
175
await asyncio .sleep (sleep_time )
178
176
179
177
return contents
180
-
181
- async def _fetch_sectories_summaries (self , ** attrs ):
182
- pass
183
178
184
- async def get_sectorwise_summaries (
179
+ async def get_sectorwise_summary (
185
180
self , business_date : Optional [datetime .date ] = None
186
181
) -> List [SectorwiseSummary ]:
187
182
"""Get the sectorwise summary
@@ -190,7 +185,7 @@ async def get_sectorwise_summaries(
190
185
business_date (Optional[datetime.date]): The date for which to fetch the data
191
186
192
187
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
194
189
"""
195
190
business_date = business_date or datetime .date .today ()
196
191
@@ -202,11 +197,30 @@ async def get_sectorwise_summaries(
202
197
203
198
return [SectorwiseSummary (** model ) for model in sector_wise_summary ]
204
199
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
+ )
207
209
210
+ return [MarketSummary (** model ) for model in market_summary ]
208
211
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