From ef8c508e3c3d9e7d39a5f56cd3b74b63d658bdf7 Mon Sep 17 00:00:00 2001 From: Sahil Parekh Date: Fri, 20 Dec 2024 07:23:52 +0530 Subject: [PATCH 1/3] Add function to get bulk data --- src/nse/NSE.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/nse/NSE.py b/src/nse/NSE.py index 3fc9a1d..7757a6f 100644 --- a/src/nse/NSE.py +++ b/src/nse/NSE.py @@ -1178,3 +1178,34 @@ 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.") + + folder = NSE.__getPath(folder, isFolder=True) if folder else self.dir + + url = "{}/historical/bulk-deals?from={}&to={}".format( + self.base_url, fromdate.strftime("%d-%m-%Y"), todate.strftime("%d-%m-%Y") + ) + + data = self.__req(url, params={"type": type}).json() + + if not 'data' in data or len(data['data']): + raise RuntimeError("No bulk deals data available for the specified date range.") + + return data['data'] \ No newline at end of file From 7750ff7ffb0c9134d3e10dda46e045a40ce11189 Mon Sep 17 00:00:00 2001 From: Sahil Parekh Date: Fri, 20 Dec 2024 07:50:38 +0530 Subject: [PATCH 2/3] resolved folder issue and removed type as parameter from url --- src/nse/NSE.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/nse/NSE.py b/src/nse/NSE.py index 7757a6f..0204894 100644 --- a/src/nse/NSE.py +++ b/src/nse/NSE.py @@ -1197,13 +1197,11 @@ def bulkdeals( if (todate - fromdate).days > 365: raise ValueError("The date range cannot exceed one year.") - folder = NSE.__getPath(folder, isFolder=True) if folder else self.dir - url = "{}/historical/bulk-deals?from={}&to={}".format( self.base_url, fromdate.strftime("%d-%m-%Y"), todate.strftime("%d-%m-%Y") ) - data = self.__req(url, params={"type": type}).json() + data = self.__req(url).json() if not 'data' in data or len(data['data']): raise RuntimeError("No bulk deals data available for the specified date range.") From 882bbbdabbfae1e668e5a0da1962dd40ac517f4f Mon Sep 17 00:00:00 2001 From: Sahil Parekh Date: Fri, 20 Dec 2024 07:54:21 +0530 Subject: [PATCH 3/3] resolved data len check --- src/nse/NSE.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nse/NSE.py b/src/nse/NSE.py index 0204894..1bc90ec 100644 --- a/src/nse/NSE.py +++ b/src/nse/NSE.py @@ -1203,7 +1203,7 @@ def bulkdeals( data = self.__req(url).json() - if not 'data' in data or len(data['data']): + 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'] \ No newline at end of file