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

Commit

Permalink
Merge pull request #41 from Samrid-Pandit/feature/market-summary
Browse files Browse the repository at this point in the history
Market Summary now can be accessible through API wrapper.
  • Loading branch information
CaffeineDuck authored Jul 15, 2021
2 parents ff1da3c + 4991748 commit 7b27ece
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
42 changes: 28 additions & 14 deletions nepse/market/core.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import asyncio
import datetime
import json
from ast import Index
from typing import List, Optional

import humps

from nepse.errors import CompanyNotFound
from nepse.market.types import FloorSheet, MarketCap, MarketSummary, SectorwiseSummary
from nepse.utils import _ClientWrapperHTTPX
from nepse.utils import _ClientWrapperHTTPX, get

BASE_URL = "https://newweb.nepalstock.com/api/nots"

Expand Down Expand Up @@ -177,11 +175,8 @@ async def _get_floorsheet_page(page_no: int) -> None:
await asyncio.sleep(sleep_time)

return contents

async def _fetch_sectories_summaries(self, **attrs):
pass

async def get_sectorwise_summaries(
async def get_sectorwise_summary(
self, business_date: Optional[datetime.date] = None
) -> List[SectorwiseSummary]:
"""Get the sectorwise summary
Expand All @@ -190,7 +185,7 @@ async def get_sectorwise_summaries(
business_date (Optional[datetime.date]): The date for which to fetch the data
Returns:
List[SectorwiseSummary]: The list of containing data related to sector wise summary
List[SectorwiseSummary]: The list containing data related to sector wise summary
"""
business_date = business_date or datetime.date.today()

Expand All @@ -202,11 +197,30 @@ async def get_sectorwise_summaries(

return [SectorwiseSummary(**model) for model in sector_wise_summary]

async def get_sectorwise_summary(self, **attrs) -> SectorwiseSummary:
pass
async def get_market_summaries(self) -> List[MarketSummary]:
"""Get the market summaries
Returns:
List[MarketSummary]: The list of Objects containing related to Market Summary
"""
market_summary = humps.decamelize(
await self._client_wrapper._get_json(f"{BASE_URL}/market-summary-history")
)

return [MarketSummary(**model) for model in market_summary]

async def get_market_summaries(self) -> List[MarketSummary]:
pass


async def get_market_summary(
self, date: Optional[datetime.date] = None
) -> MarketSummary:
"""Get the market summary for a specific date
Args:
date (Optional[datetime.date]): Date to filter the market summary. Defaults to today
Returns:
MarketSummary: [description]
"""
market_summaries = await self.get_market_summaries()
date = date or datetime.date.today()

return get(market_summaries, business_date=date)
16 changes: 15 additions & 1 deletion nepse/market/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __post_init__(self) -> None:
year, month, day = self.business_date.split("-")
self.business_date = datetime.date(int(year), int(month), int(day))


@dataclass
class SectorwiseSummary:
business_date: datetime.date
Expand All @@ -49,4 +50,17 @@ class SectorwiseSummary:

def __post_init__(self) -> None:
year, month, day = self.business_date.split("-")
self.business_date = datetime.date(int(year), int(month), int(day))
self.business_date = datetime.date(int(year), int(month), int(day))


@dataclass
class MarketSummary:
business_date: datetime.date
total_turnover: float
total_traded_shares: int
total_transactions: int
traded_scrips: int

def __post_init__(self) -> None:
year, month, day = self.business_date.split("-")
self.business_date = datetime.date(int(year), int(month), int(day))

0 comments on commit 7b27ece

Please sign in to comment.