Nazgul
April 28, 2023, 6:50pm
1
Whenever, i’m trying to fetch, index historical option data i’m getting null dataframe. But the code is working well for stock historical option data. I have also check on NSE website regarding my parameters.
Below is my code : -
symbol = "NIFTY"
start_date = "24-04-2023"
end_date = "25-04-2023"
instrument_type = "options"
expiry_date = "04-May-2023"
strike_price = 17900.00
option_type = "CE"
derivative_data = derivative_history(symbol, start_date, end_date, instrument_type,expiry_date,strike_price, option_type)
dexter
April 29, 2023, 5:46am
2
Nazgul:
symbol = "NIFTY"
start_date = "24-04-2023"
end_date = "25-04-2023"
instrument_type = "options"
expiry_date = "04-May-2023"
strike_price = 17900.00
option_type = "CE"
derivative_data = derivative_history(symbol, start_date, end_date, instrument_type,expiry_date,strike_price, option_type)
Update the nsepython
library and try again. It will work.
There was a conditional error in the derivative_history function which I have fixed.
if(instrumentType=="options"):
instrumentType="OPTSTK"
if("NIFTY" in symbol): instrumentType="OPTIDX"
if(instrumentType=="futures"):
instrumentType="FUTSTK"
if("NIFTY" in symbol): instrumentType="FUTIDX"
I had never used options history that much so I did not noticed it earlier
Nazgul
April 29, 2023, 11:01am
3
Thank you for fixing the code.
I have another query, whenever i’m fetching historical equity data, latest data is fetched only till 20-03-2023.
Below is a snapshot of my code and the resulted dataframe.
Nazgul
April 29, 2023, 5:48pm
4
@dexter The code you have fixed only retrieving recent historical option data of index.
But when i’m fetching data of year 2021 and before it is giving me null dataframe, will you please look into it.
Below i’m attaching the snapshot.
dexter
April 29, 2023, 5:59pm
5
I will respond to all the queries of everyone at once after couple of days. I am going out for next two days. Pardon me
Hey dexter!
Did you looked into this, actually i’m making a model which requires historical data and i’m not able to fetch nifty historical option data before 2022.
Not yet. Will do in friday. Use nsefetch() meanwhile with the accurate URL.
Hi dexter
Have you fixed the issue?
Slight way. Busy in Gann Project. I will do it by tonight.
Nazgul
May 9, 2023, 12:05pm
10
okay, also there is no showing of volume in index history !
The API which is pulled by Index History does not give volume. So how you will get volume?
dexter
Split this topic
May 12, 2023, 8:33am
12
2 posts were split to a new topic: I am still getting NULL dataframe
dexter
May 12, 2023, 8:37am
13
I ran
symbol = “NIFTY”
start_date = “01-06-2021”
end_date = “01-06-2021”
instrument_type = “options”
expiry_date = “03-Jun-2021”
strike_price = 13500
option_type = “CE”
derivative_data = derivative_history(symbol, start_date, end_date, instrument_type,
expiry_date, strike_price, option_type)
print(derivative_data)
and got
INFO:root:Starting Date: 2021-06-01 00:00:00
INFO:root:Ending Date: 2021-06-01 00:00:00
INFO:root:Total Number of Days: 0
INFO:root:Total FOR Loops in the program: 0
INFO:root:Remainder Loop: 0
INFO:root:End Loop
INFO:root:====
INFO:root:Starting Date: 01-06-2021
INFO:root:Ending Date: 01-06-2021
INFO:root:====
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 158 100 158 0 0 1203 0 --:--:-- --:--:-- --:--:-- 1206
INFO:root:https://www.nseindia.com/api/historical/fo/derivatives?&from=01-06-2021&to=01-06-2021&optionType=CE&strikePrice=13500.00&expiryDate=03-Jun-2021&instrumentType=OPTIDX&symbol=NIFTY
INFO:root:{'data': [], 'meta': {'symbol': 'NIFTY', 'optionType': 'CE', 'expiryDate': '03-Jun-2021', 'strikePrice': '13500.00', 'instrumentType': 'OPTIDX', 'year': '2021', 'fromDate': '01-06-2021', 'toDate': '01-06-2021'}}
INFO:root:Finale
INFO:root:Length of the Total Dataset: 0
Empty DataFrame
Columns: []
Index: []
The format of this URL is correct. But Can you confirm if the URL structure is wrong or right?
https://www.nseindia.com/api/historical/fo/derivatives?&from=01-06-2021&to=01-06-2021&optionType=CE&strikePrice=13500.00&expiryDate=03-Jun-2021&instrumentType=OPTIDX&symbol=NIFTY
Will this fix work for BANKNIFTY and FINNIFTY ??
dexter
May 13, 2023, 4:28pm
15
Why will it not? It should as long as NSE does not change URL structure.
Nazgul
May 15, 2023, 10:04am
16
1 Like
dexter
May 15, 2023, 10:13am
17
No that is not URL Structure.
See the datasource. I mean from where it is getting the data. check
VIDEO
See how I got it from inspect element,