Problems with derivative_history API

Hi,
I used ‘equity_history’ function to retrieve historical prices of stocks.
But when i’m using ‘derivative_history’ it is returning an empty dataframe. I have inputed all the parameters correctly.
will you please look into this.

Paste your entire code.

Here is the code :-

symbol = "TCS"
start_date = "20-04-2023"
end_date = "21-04-2023"
instrument_type = "options"
expiry_date = "27-05-2023"
strike_price = 3180
option_type = "CE"

derivative_data = derivative_history(symbol, start_date, end_date, instrument_type,
                                      expiry_date, strike_price, option_type)

print(derivative_data)

Did you get the resolution for this?

Your problem is similar to his problem?

Check here once nsepython/nsepython/rahu.py at master · aeron7/nsepython · GitHub.

I will check it properly as well shortly.

Hey!
Any Updates regarding the code??

Wrote these three today -

https://unofficed.com/lessons/backtest-entropy-bollinger-band-strategy-using-python/
Backtest Entropy Bollinger Band Strategy Using Python with Futures Data Part II - Unofficed
Backtest Entropy Bollinger Band Strategy Using Python with Equities Data Part III - Unofficed

Tomorrow’s (Today’s) free time goes to NSEPython. Will resolve all problems.

Okay, Please ping whenever code gets updated.

I just ran. This indeed throw empty dataframe.

I need you help here. My wrapper only fetches the stuff which is already there in NSE. As I did logging.getLogger().setLevel(logging.INFO) in the code to debug, I got this -

INFO:root:Starting Date: 2023-04-20 00:00:00
INFO:root:Ending Date: 2023-04-21 00:00:00
INFO:root:Total Number of Days: 1
INFO:root:Total FOR Loops in the program: 0
INFO:root:Remainder Loop: 1
INFO:root:End Loop
INFO:root:====
INFO:root:Starting Date: 20-04-2023
INFO:root:Ending Date: 21-04-2023
INFO:root:====
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   155  100   155    0     0   2482      0 --:--:-- --:--:-- --:--:--  2500
INFO:root:https://www.nseindia.com/api/historical/fo/derivatives?&from=20-04-2023&to=21-04-2023&optionType=CE&strikePrice=3180.00&expiryDate=27-05-2023&instrumentType=OPTSTK&symbol=TCS
INFO:root:{'data': [], 'meta': {'symbol': 'TCS', 'optionType': 'CE', 'expiryDate': '27-05-2023', 'strikePrice': '3180.00', 'instrumentType': 'OPTSTK', 'year': '2023', 'fromDate': '20-04-2023', 'toDate': '21-04-2023'}}
/nseworks/rahu.py:632: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
  total=total.append(derivative_history_virgin(symbol,start_date,end_date,instrumentType,expiry_date,strikePrice,optionType))
INFO:root:Finale
INFO:root:Length of the Total Dataset: 0

This URL is returning empty. You tell me what URL should work. I will fix accordingly and immediately.
https://www.nseindia.com/api/historical/fo/derivatives?&from=20-04-2023&to=21-04-2023&optionType=CE&strikePrice=3180.00&expiryDate=27-05-2023&instrumentType=OPTSTK&symbol=TCS

In the documentation of NSEPy Functions - Unofficed

The example used -

symbol = "SBIN"
start_date = "15-05-2021"
end_date ="15-06-2021"
instrumentType = "options"
expiry_date ="24-Jun-2021"
strikePrice = 300
optionType="PE"
print(derivative_history(symbol,start_date,end_date,instrumentType,expiry_date,strikePrice,optionType))

worked fine.

It is fetching this URL → https://www.nseindia.com/api/historical/fo/derivatives?&from=15-05-2021&to=15-06-2021&optionType=PE&strikePrice=300.00&expiryDate=24-Jun-2021&instrumentType=OPTSTK&symbol=SBIN

So in context of that code, I think you made a minor fuckup and a major fuckup and Your correct code should be →

symbol = "TCS"
start_date = "20-04-2023"
end_date = "21-04-2023"
instrument_type = "options"
expiry_date = "25-May-2023"
strike_price = 3180
option_type = "CE"

derivative_data = derivative_history(symbol, start_date, end_date, instrument_type,
                                      expiry_date, strike_price, option_type)

print(derivative_data)

It works fine

INFO:root:Starting Date: 2023-04-20 00:00:00
INFO:root:Ending Date: 2023-04-21 00:00:00
INFO:root:Total Number of Days: 1
INFO:root:Total FOR Loops in the program: 0
INFO:root:Remainder Loop: 1
INFO:root:End Loop
INFO:root:====
INFO:root:Starting Date: 20-04-2023
INFO:root:Ending Date: 21-04-2023
INFO:root:====
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   548  100   548    0     0   3941      0 --:--:-- --:--:-- --:--:--  3971
INFO:root:https://www.nseindia.com/api/historical/fo/derivatives?&from=20-04-2023&to=21-04-2023&optionType=CE&strikePrice=3180.00&expiryDate=25-May-2023&instrumentType=OPTSTK&symbol=TCS
INFO:root:{'data': [{'_id': '64428e4ebf1903287137982b', 'FH_INSTRUMENT': 'OPTSTK', 'FH_SYMBOL': 'TCS', 'FH_EXPIRY_DT': '25-May-2023', 'FH_STRIKE_PRICE': '3180.00', 'FH_OPTION_TYPE': 'CE', 'FH_MARKET_TYPE': 'N', 'FH_OPENING_PRICE': '45.05', 'FH_TRADE_HIGH_PRICE': '63.85', 'FH_TRADE_LOW_PRICE': '45.00', 'FH_CLOSING_PRICE': '62.80', 'FH_LAST_TRADED_PRICE': '62.15', 'FH_PREV_CLS': '46.95', 'FH_SETTLE_PRICE': '62.80', 'FH_TOT_TRADED_QTY': '47075', 'FH_TOT_TRADED_VAL': '152377653.75', 'FH_OPEN_INT': '23275', 'FH_CHANGE_IN_OI': '4375.00', 'FH_MARKET_LOT': '175', 'FH_TIMESTAMP': '21-Apr-2023', 'TIMESTAMP': '2023-04-20T18:30:00.000Z', 'FH_UNDERLYING_VALUE': 3160.85, 'CALCULATED_PREMIUM_VAL': 2679153.75}, {'_id': '644149f7bf19032871200da2', 'FH_INSTRUMENT': 'OPTSTK', 'FH_SYMBOL': 'TCS', 'FH_EXPIRY_DT': '25-May-2023', 'FH_STRIKE_PRICE': '3180.00', 'FH_OPTION_TYPE': 'CE', 'FH_MARKET_TYPE': 'N', 'FH_OPENING_PRICE': '46.95', 'FH_TRADE_HIGH_PRICE': '49.50', 'FH_TRADE_LOW_PRICE': '42.00', 'FH_CLOSING_PRICE': '46.95', 'FH_LAST_TRADED_PRICE': '47.10', 'FH_PREV_CLS': '43.10', 'FH_SETTLE_PRICE': '46.95', 'FH_TOT_TRADED_QTY': '24675', 'FH_TOT_TRADED_VAL': '79599353.75', 'FH_OPEN_INT': '18900', 'FH_CHANGE_IN_OI': '-1225.00', 'FH_MARKET_LOT': '175', 'FH_TIMESTAMP': '20-Apr-2023', 'TIMESTAMP': '2023-04-19T18:30:00.000Z', 'FH_UNDERLYING_VALUE': 3104.8, 'CALCULATED_PREMIUM_VAL': 1132853.75}], 'meta': {'symbol': 'TCS', 'optionType': 'CE', 'expiryDate': '25-May-2023', 'strikePrice': '3180.00', 'instrumentType': 'OPTSTK', 'year': '2023', 'fromDate': '20-04-2023', 'toDate': '21-04-2023'}}
/root/apps/nseworks/rahu.py:632: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
  total=total.append(derivative_history_virgin(symbol,start_date,end_date,instrumentType,expiry_date,strikePrice,optionType))
INFO:root:Finale
INFO:root:Length of the Total Dataset: 2
  1. You wrote the expiry wrong.
  2. You wrote the format of expiry wrong.