Skip to content

Commit

Permalink
Merge pull request #4 from sahilparekh/bulkdeals
Browse files Browse the repository at this point in the history
Add function to get bulk data
  • Loading branch information
BennyThadikaran authored Dec 23, 2024
2 parents f993277 + 882bbbd commit 2363c65
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/nse/NSE.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,3 +1178,32 @@ def holidays(
data = self.__req(url, params={"type": type}).json()

return data

def bulkdeals(
self, fromdate: datetime, todate: datetime
) -> Dict:
"""Download the bulk deals report for the specified date range and return the data.
:param fromdate: Start date of the bulk deals report to download
:type fromdate: datetime.datetime
:param todate: End date of the bulk deals report to download
:type todate: datetime.datetime
:raise ValueError: if the date range exceeds one year.
:raise RuntimeError: if no bulk deals data is available for the specified date range.
:return: Bulk deals data
:rtype: dict
"""

if (todate - fromdate).days > 365:
raise ValueError("The date range cannot exceed one year.")

url = "{}/historical/bulk-deals?from={}&to={}".format(
self.base_url, fromdate.strftime("%d-%m-%Y"), todate.strftime("%d-%m-%Y")
)

data = self.__req(url).json()

if not 'data' in data or len(data['data']) < 1:
raise RuntimeError("No bulk deals data available for the specified date range.")

return data['data']

0 comments on commit 2363c65

Please sign in to comment.