nsedt.reports

function to download reports

  1"""
  2function to download reports
  3"""
  4
  5import logging
  6
  7from nsedt.utils import get_cookies, fetch_csv, format_date, fetch_zip
  8from nsedt.resources.constants import (
  9    REPORT_URL, MARKET_ACTIVITY_REPORT,
 10    BHAV_COPY_REPORT, SEC_BHAV_COPY_REPORT, NSCCL_REPORTS, NSCCL_VOLT)
 11
 12log = logging.getLogger("root")
 13
 14# tbd
 15# bulk deals
 16# block deals
 17
 18
 19def get_market_activity_report(date: str):
 20    """
 21    get_market_activity_report
 22
 23    Args:\n
 24        date (str): date for which to download market activity report\n
 25    Returns:
 26        string: string content of the file as right now its not possible 
 27        to format the content to json or pandas df
 28    Expects:
 29        date to be in format of  "dd-mm-yyyy" eg: 30-04-2024
 30        all other cases will be invalidated
 31    """
 32    date = format_date(date, date_format='%d%m%y')
 33    if not date:
 34        raise ValueError("Please provide date format in '%d-%m-%Y' format")
 35
 36    cookies = get_cookies()
 37    url = f"{REPORT_URL}{MARKET_ACTIVITY_REPORT}{date}.csv"
 38    return fetch_csv(url, cookies, response_type="raw")
 39
 40
 41def get_volatility_report(date: str, response_type: str="panda_df"):
 42    """
 43    get_volatility_report
 44
 45    Args:\n
 46        date (str): date for which to download market activity report\n
 47        response_type (str, Optional): define the response type panda_df | json . Default json\n
 48    Returns:
 49        string: string content of the file as right now its not possible
 50        to format the content to json or pandas df
 51    Expects:
 52        date to be in format of  "dd-mm-yyyy" eg: 30-04-2024
 53        all other cases will be invalidated
 54    """
 55    date = format_date(date, date_format='%d%m%Y')
 56    if not date:
 57        raise ValueError("Please provide date format in '%d-%m-%Y' format")
 58    cookies = get_cookies()
 59    url = f"{REPORT_URL}{NSCCL_VOLT}CMVOLT_{date}.CSV"
 60    print(url)
 61    return fetch_csv(url, cookies, response_type=response_type)
 62
 63
 64def get_bhav_copy_zip(date: str, response_type: str="panda_df"):
 65    """
 66    get_market_activity_report
 67
 68    Args:\n
 69        date (str): date for which to download market activity report\n
 70        path (str): path to save the bhav copy zip
 71    Returns:
 72        bool: if the file is save to the local path or not
 73    Expects:
 74        date to be in format of  "dd-mm-yyyy" eg: 30-04-2024
 75    """
 76
 77    date = format_date(date, date_format='%d%b%Y')
 78    if not date:
 79        raise ValueError("Please provide date format in '%d-%m-%Y' format")
 80    date = date.upper()
 81    cookies = get_cookies()
 82    url = f"{REPORT_URL}{BHAV_COPY_REPORT}{date[2:5]}/cm{date}bhav.csv.zip"
 83    file_name = url.split("/")[-1].replace(".zip", "")
 84    return fetch_zip(url, cookies, file_name=file_name, response_type=response_type)
 85
 86
 87def get_sec_full_bhav_copy(date: str, response_type: str="panda_df"):
 88    """
 89    get_sec_full_bhav_copy
 90
 91    Args:\n
 92        date (str): date for which to download market activity report\n
 93        response_type (str, Optional): define the response type panda_df | json . Default json\n
 94    Returns:
 95        string: string content of the file as right now its not possible
 96        to format the content to json or pandas df
 97    Expects:
 98        date to be in format of  "dd-mm-yyyy" eg: 30-04-2024
 99        all other cases will be invalidated
100    """
101    date = format_date(date, date_format='%d%m%Y')
102    if not date:
103        raise ValueError("Please provide date format in '%d-%m-%Y' format")
104
105    cookies = get_cookies()
106    url = f"{REPORT_URL}{SEC_BHAV_COPY_REPORT}sec_bhavdata_full_{date}.csv"
107    return fetch_csv(url, cookies, response_type=response_type)
108
109
110def get_fno_participant_wise_oi_data(date: str, response_type: str="panda_df"):
111    """
112    fno_participant_wise_oi_data
113
114    Args:\n
115        date (str): date for which to download market activity report\n
116        response_type (str, Optional): define the response type panda_df | json . Default json\n
117    Returns:
118        string: string content of the file as right now its not possible
119        to format the content to json or pandas df
120    Expects:
121        date to be in format of  "ddmmYY" eg: 30/04/2024 => 300424
122        all other cases will be invalidated
123    """
124    date = format_date(date, date_format='%d%m%Y')
125    if not date:
126        raise ValueError("Please provide date format in '%d-%m-%Y' format")
127
128    cookies = get_cookies()
129    url = f"{REPORT_URL}{NSCCL_REPORTS}fao_participant_oi_{date}.csv"
130    return fetch_csv(url, cookies, response_type=response_type, skip_rows=1)
131
132
133def get_fno_participant_wise_volume_data(date: str,response_type: str="panda_df"):
134    """
135    get_fno_participant_wise_volume_data
136
137    Args:\n
138        date (str): date for which to download market activity report\n
139        response_type (str, Optional): define the response type panda_df | json . Default json\n
140    Returns:
141        string: string content of the file as right now its not possible
142        to format the content to json or pandas df
143    Expects:
144        date to be in format of  "ddmmYY" eg: 30/04/2024 => 300424
145        all other cases will be invalidated
146    """
147    date = format_date(date, date_format='%d%m%Y')
148    if not date:
149        raise ValueError("Please provide date format in '%d-%m-%Y' format")
150
151    cookies = get_cookies()
152    url = f"{REPORT_URL}{NSCCL_REPORTS}fao_participant_vol_{date}.csv"
153    return fetch_csv(url, cookies, response_type=response_type, skip_rows=1)
log = <RootLogger root (INFO)>
def get_market_activity_report(date: str):
20def get_market_activity_report(date: str):
21    """
22    get_market_activity_report
23
24    Args:\n
25        date (str): date for which to download market activity report\n
26    Returns:
27        string: string content of the file as right now its not possible 
28        to format the content to json or pandas df
29    Expects:
30        date to be in format of  "dd-mm-yyyy" eg: 30-04-2024
31        all other cases will be invalidated
32    """
33    date = format_date(date, date_format='%d%m%y')
34    if not date:
35        raise ValueError("Please provide date format in '%d-%m-%Y' format")
36
37    cookies = get_cookies()
38    url = f"{REPORT_URL}{MARKET_ACTIVITY_REPORT}{date}.csv"
39    return fetch_csv(url, cookies, response_type="raw")

get_market_activity_report

Args:

date (str): date for which to download market activity report

Returns: string: string content of the file as right now its not possible to format the content to json or pandas df Expects: date to be in format of "dd-mm-yyyy" eg: 30-04-2024 all other cases will be invalidated

def get_volatility_report(date: str, response_type: str = 'panda_df'):
42def get_volatility_report(date: str, response_type: str="panda_df"):
43    """
44    get_volatility_report
45
46    Args:\n
47        date (str): date for which to download market activity report\n
48        response_type (str, Optional): define the response type panda_df | json . Default json\n
49    Returns:
50        string: string content of the file as right now its not possible
51        to format the content to json or pandas df
52    Expects:
53        date to be in format of  "dd-mm-yyyy" eg: 30-04-2024
54        all other cases will be invalidated
55    """
56    date = format_date(date, date_format='%d%m%Y')
57    if not date:
58        raise ValueError("Please provide date format in '%d-%m-%Y' format")
59    cookies = get_cookies()
60    url = f"{REPORT_URL}{NSCCL_VOLT}CMVOLT_{date}.CSV"
61    print(url)
62    return fetch_csv(url, cookies, response_type=response_type)

get_volatility_report

Args:

date (str): date for which to download market activity report

response_type (str, Optional): define the response type panda_df | json . Default json

Returns: string: string content of the file as right now its not possible to format the content to json or pandas df Expects: date to be in format of "dd-mm-yyyy" eg: 30-04-2024 all other cases will be invalidated

def get_bhav_copy_zip(date: str, response_type: str = 'panda_df'):
65def get_bhav_copy_zip(date: str, response_type: str="panda_df"):
66    """
67    get_market_activity_report
68
69    Args:\n
70        date (str): date for which to download market activity report\n
71        path (str): path to save the bhav copy zip
72    Returns:
73        bool: if the file is save to the local path or not
74    Expects:
75        date to be in format of  "dd-mm-yyyy" eg: 30-04-2024
76    """
77
78    date = format_date(date, date_format='%d%b%Y')
79    if not date:
80        raise ValueError("Please provide date format in '%d-%m-%Y' format")
81    date = date.upper()
82    cookies = get_cookies()
83    url = f"{REPORT_URL}{BHAV_COPY_REPORT}{date[2:5]}/cm{date}bhav.csv.zip"
84    file_name = url.split("/")[-1].replace(".zip", "")
85    return fetch_zip(url, cookies, file_name=file_name, response_type=response_type)

get_market_activity_report

Args:

date (str): date for which to download market activity report

path (str): path to save the bhav copy zip

Returns: bool: if the file is save to the local path or not Expects: date to be in format of "dd-mm-yyyy" eg: 30-04-2024

def get_sec_full_bhav_copy(date: str, response_type: str = 'panda_df'):
 88def get_sec_full_bhav_copy(date: str, response_type: str="panda_df"):
 89    """
 90    get_sec_full_bhav_copy
 91
 92    Args:\n
 93        date (str): date for which to download market activity report\n
 94        response_type (str, Optional): define the response type panda_df | json . Default json\n
 95    Returns:
 96        string: string content of the file as right now its not possible
 97        to format the content to json or pandas df
 98    Expects:
 99        date to be in format of  "dd-mm-yyyy" eg: 30-04-2024
100        all other cases will be invalidated
101    """
102    date = format_date(date, date_format='%d%m%Y')
103    if not date:
104        raise ValueError("Please provide date format in '%d-%m-%Y' format")
105
106    cookies = get_cookies()
107    url = f"{REPORT_URL}{SEC_BHAV_COPY_REPORT}sec_bhavdata_full_{date}.csv"
108    return fetch_csv(url, cookies, response_type=response_type)

get_sec_full_bhav_copy

Args:

date (str): date for which to download market activity report

response_type (str, Optional): define the response type panda_df | json . Default json

Returns: string: string content of the file as right now its not possible to format the content to json or pandas df Expects: date to be in format of "dd-mm-yyyy" eg: 30-04-2024 all other cases will be invalidated

def get_fno_participant_wise_oi_data(date: str, response_type: str = 'panda_df'):
111def get_fno_participant_wise_oi_data(date: str, response_type: str="panda_df"):
112    """
113    fno_participant_wise_oi_data
114
115    Args:\n
116        date (str): date for which to download market activity report\n
117        response_type (str, Optional): define the response type panda_df | json . Default json\n
118    Returns:
119        string: string content of the file as right now its not possible
120        to format the content to json or pandas df
121    Expects:
122        date to be in format of  "ddmmYY" eg: 30/04/2024 => 300424
123        all other cases will be invalidated
124    """
125    date = format_date(date, date_format='%d%m%Y')
126    if not date:
127        raise ValueError("Please provide date format in '%d-%m-%Y' format")
128
129    cookies = get_cookies()
130    url = f"{REPORT_URL}{NSCCL_REPORTS}fao_participant_oi_{date}.csv"
131    return fetch_csv(url, cookies, response_type=response_type, skip_rows=1)

fno_participant_wise_oi_data

Args:

date (str): date for which to download market activity report

response_type (str, Optional): define the response type panda_df | json . Default json

Returns: string: string content of the file as right now its not possible to format the content to json or pandas df Expects: date to be in format of "ddmmYY" eg: 30/04/2024 => 300424 all other cases will be invalidated

def get_fno_participant_wise_volume_data(date: str, response_type: str = 'panda_df'):
134def get_fno_participant_wise_volume_data(date: str,response_type: str="panda_df"):
135    """
136    get_fno_participant_wise_volume_data
137
138    Args:\n
139        date (str): date for which to download market activity report\n
140        response_type (str, Optional): define the response type panda_df | json . Default json\n
141    Returns:
142        string: string content of the file as right now its not possible
143        to format the content to json or pandas df
144    Expects:
145        date to be in format of  "ddmmYY" eg: 30/04/2024 => 300424
146        all other cases will be invalidated
147    """
148    date = format_date(date, date_format='%d%m%Y')
149    if not date:
150        raise ValueError("Please provide date format in '%d-%m-%Y' format")
151
152    cookies = get_cookies()
153    url = f"{REPORT_URL}{NSCCL_REPORTS}fao_participant_vol_{date}.csv"
154    return fetch_csv(url, cookies, response_type=response_type, skip_rows=1)

get_fno_participant_wise_volume_data

Args:

date (str): date for which to download market activity report

response_type (str, Optional): define the response type panda_df | json . Default json

Returns: string: string content of the file as right now its not possible to format the content to json or pandas df Expects: date to be in format of "ddmmYY" eg: 30/04/2024 => 300424 all other cases will be invalidated