Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.

Commit 7b27ece

Browse files
authored
Merge pull request #41 from Samrid-Pandit/feature/market-summary
Market Summary now can be accessible through API wrapper.
2 parents ff1da3c + 4991748 commit 7b27ece

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

nepse/market/core.py

+28-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import asyncio
22
import datetime
3-
import json
4-
from ast import Index
53
from typing import List, Optional
64

75
import humps
86

97
from nepse.errors import CompanyNotFound
108
from nepse.market.types import FloorSheet, MarketCap, MarketSummary, SectorwiseSummary
11-
from nepse.utils import _ClientWrapperHTTPX
9+
from nepse.utils import _ClientWrapperHTTPX, get
1210

1311
BASE_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)

nepse/market/types.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __post_init__(self) -> None:
3939
year, month, day = self.business_date.split("-")
4040
self.business_date = datetime.date(int(year), int(month), int(day))
4141

42+
4243
@dataclass
4344
class SectorwiseSummary:
4445
business_date: datetime.date
@@ -49,4 +50,17 @@ class SectorwiseSummary:
4950

5051
def __post_init__(self) -> None:
5152
year, month, day = self.business_date.split("-")
52-
self.business_date = datetime.date(int(year), int(month), int(day))
53+
self.business_date = datetime.date(int(year), int(month), int(day))
54+
55+
56+
@dataclass
57+
class MarketSummary:
58+
business_date: datetime.date
59+
total_turnover: float
60+
total_traded_shares: int
61+
total_transactions: int
62+
traded_scrips: int
63+
64+
def __post_init__(self) -> None:
65+
year, month, day = self.business_date.split("-")
66+
self.business_date = datetime.date(int(year), int(month), int(day))

0 commit comments

Comments
 (0)