@Moderator_3 Hi,
I placed the same request.
I am able to extract data for days where market is open but does not work for days where market is closed.
Data download success for this request: {'exchange': 'NSE', 'symboltoken': '1333', 'interval': 'ONE_MINUTE', 'fromdate': '2024-05-13 08:00', 'todate': '2024-05-13 17:00'}
Data download failed for this request: {'exchange': 'NSE', 'symboltoken': '1333', 'interval': 'ONE_MINUTE', 'fromdate': '2024-05-12 08:00', 'todate': '2024-05-12 17:00'}
And the error from the failed attempt is breaking my try
and except
block.
Can you try and replicate this and see is this works for you?
Here is the code that I attempted.
>>> data_list = []
>>> target_date = datetime.today().date()
>>> target_date_str = target_date.strftime("%Y-%m-%d")
>>> target_datetime_end_string = f"{target_date_str} 17:00"
>>> target_datetime_start_string = f"{target_date_str} 08:00"
>>> exchange = "NSE"
>>> token = "1333"
>>> for i in range(7):
... try:
... data = hmd.historical_market_data(
... exchange=exchange,
... symboltoken = token,
... interval = "ONE_MINUTE",
... fromdate = target_datetime_start_string,
... todate = target_datetime_end_string
... )
... except:
... print(target_date_str)
... data_list.extend(data)
... target_date = target_date - timedelta(days=1)
... target_date_str = target_date.strftime("%Y-%m-%d")
... target_datetime_end_string = f"{target_date_str} 17:00"
... target_datetime_start_string = f"{target_date_str} 08:00"
...
{'exchange': 'NSE', 'symboltoken': '1333', 'interval': 'ONE_MINUTE', 'fromdate': '2024-05-13 08:00', 'todate': '2024-05-13 17:00'}
{'exchange': 'NSE', 'symboltoken': '1333', 'interval': 'ONE_MINUTE', 'fromdate': '2024-05-12 08:00', 'todate': '2024-05-12 17:00'}
[E 240513 20:44:31 smartConnect:243] Error occurred while making a POST request to https://apiconnect.angelbroking.com/rest/secure/angelbroking/historical/v1/getCandleData. Error: Something Went Wrong, Please Try After Sometime. URL: https://apiconnect.angelbroking.com/rest/secure/angelbroking/historical/v1/getCandleData, Headers: {'Content-type': 'application/json', 'X-ClientLocalIP': '127.0.0.1', 'X-ClientPublicIP': '106.193.147.98', 'X-MACAddress': '30:03:c8:68:51:0a', 'Accept': 'application/json', 'X-PrivateKey': 'B4aGvizX', 'X-UserType': 'USER', 'X-SourceID': 'WEB'}, Request: {'exchange': 'NSE', 'symboltoken': '1333', 'interval': 'ONE_MINUTE', 'fromdate': '2024-05-12 08:00', 'todate': '2024-05-12 17:00'}, Response: {'message': 'Something Went Wrong, Please Try After Sometime', 'errorcode': 'AB1004', 'status': False, 'data': None}
Traceback (most recent call last):
File "<stdin>", line 12, in <module>
TypeError: 'NoneType' object is not iterable
>>> data_list
[['2024-05-13T09:15:00+05:30', 1432.1, 1438.95, 1431.65, 1437.95, 219344], ['2024-05-13T09:16:00+05:30', 1437.85, 1439.3, 1437.2, 1437.65, 107900], ['2024-05-13T09:17:00+05:30', 1438.15, 1439.25, 1437.5, 1439.2, 91194], ['2024-05-13T09:18:00+05:30', 1439.2, 1439.75, 1436.0, 1436.8, 171212], ['2024-05-13T09:19:00+05:30', 1436.55, 1437.35, 1436.2, 1436.65, 59633], ['2024-05-13T09:20:00+05:30', 1436.9, 1437.7, 1434.65, 1434.75, 67935], ['2024-05-13T09:21:00+05:30', 1434.8, 1436.0, 1434.75, 1435.75, 44552], ['2024-05-13T09:22:00+05:30', 1436.0, 1436.45, 1435.4, 1435.55, 23884], ['2024-05-13T09:23:00+05:30', 1435.55, 1435.55, 1434.55, 1434.6, 32563], ['2024-05-13T09:24:00+05:30', 1434.75, 1434.95, 1434.6, 1434.8, 23405], ['2024-05-13T09:25:00+05:30', 1434.85, 1435.95, 1434.7, 1435.25, 40982], ['2024-05-13T09:26:00+05:30', 1435.25, 1436.4, 1435.2, 1436.0, 32047], ['2024-05-13T09:27:00+05:30', 1435.95, 1436.0, 1435.2, 1435.25, 15229], ['2024-05-13T09:28:00+05:30', 1435.25, 1436.4, 1435.0, 1435.65, 29298], ['2024-05-13T09:29:00+05:30', 1435.65, 1436.15, 1435.4, 1435.5, 23863], ['2024-05-13T09:30:00+05:30', 1435.45, 1436.0, 1435.0, 1435.0, 20221], ['2024-05-13T09:31:00+05:30', 1434.9, 1435.95, 1434.55, 1434.75, 47584], ['2024-05-13T09:32:00+05:30', 1435.0, 1435.2, 1434.6, 1434.8, 24303], ['2024-05-13T09:33:00+05:30', 1434.8, 1434.85, 1434.05, 1434.3, 40985], ['2024-05-13T09:34:00+05:30', 1434.1, 1435.0, 1433.75, 1434.5, 38476], ['2024-05-13T09:35:00+05:30', 1434.5, 1435.5, 1434.05, 1434.45, 36908], ['2024-05-13T09:36:00+05:30', 1434.45, 1435.0, 1434.05, 1434.9, 32948],