%LTP change for NSE option chain

Hi Imran,

I want to build trading symbol from the strike price obtained from options data. Do we have any function for this? This way i can pass the trading symbol to the get_long_term_historical_data function.

hi @vedvishwa

Since in option chain we get the strike only, we need to construct trading_symbol manually.

Where getting underlying, strike, and right as easy tasks.

expiry we can give manually

underlying = 'NIFTY'   
expiry     = '12 MAY' # expiry we can give manually
strike     = "24300"   # this we get from option chain
right      = "CALL"

trading_symbol = f"{underlying} {expiry} {strike} {right}"

now we have got our trading_symbol, we can pass this to get_long_term_historical_data

@vedvishwa
Also there is a second method to get %ltp change

we can call quote data.. it contains, ltp and previous close values.. and then calculate pct change
see solution

symbol_name    = 'NIFTY 12 MAY 24400 CALL'
quote_data     = tsl.get_quote_data(names=[symbol_name])[symbol_name]
previous_close = quote_data['ohlc']['close']
ltp            = quote_data['last_price']
ltp_pct_change = ((ltp-previous_close)/previous_close)*100

and the same info matched with dhan charts as well

Hello Imran…

I’m getting error from the given function call…error details in the next post.

Is this error due to missing/incorrect parameters for the function call, or is it due to non-availability of the service during weekends ?

Dear forum moderators,

Now this error from the channel is also frustrating…

How can we explain our issues with just one screenshot? And btw, who is a new user after posting 25 messages?

HI @vedvishwa
There may be 3 probable causes

  1. Dhan Tradehull library version needs to be upgraded to 3.3.0
pip install Dhan-Tradehull
  1. Do delete the dependencies folder. This will also remove instruments file inside of it.. which may be cause the issue for “unable to find the correct expiry for nifty” .
    and then use a new token for login. this will create fresh dependencies folder, and thus fresh instrument file

  2. Check if the Dhan api data subscription is active

  3. Also I tried to run same on my end, api seems to be working fine

1 Like

adding @Dhan for same

Hello Imran…

I have…

  1. Updated the dependencies
  2. Deleted the existing dependencies folder
  3. Renewed Api subscription.

But still the data is not coming…

Is anything still missing in the code…

Hi @vedvishwa
there is a bit change in code for exchange , where exchange=“INDEX”

I have added working code below

atm, option_chain = tsl.get_option_chain(Underlying="NIFTY", exchange="INDEX", expiry=0, num_strikes=10)