How Do I Get The Live Option Chain?
How do I get the live option chain (every minute or if possible, every second)? Also, I want to refresh my excel each time which contains this data (exported from Python) so that c
Solution 1:
Try coding this way.
import requests
import json
import pandas as pd
from pandas.io.json import json_normalize
urlheader = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36",
"authority": "www.nseindia.com",
"scheme":"https"
}
expiry_dt = '28-Jan-2021'
url = 'https://www.nseindia.com/api/option-chain-indices?symbol=NIFTY'
data = requests.get(url, headers=urlheader).content
data2 = data.decode('utf-8')
df = json.loads(data2)
json_ce = eval("[data['CE'] for data in df['records']['data'] if 'CE' in data and data['expiryDate'] == '" + expiry_dt + "']")
df_ce = json_normalize(json_ce)
print('*** NIFTY Call Options Data with Expiry Date: '+ expiry_dt + ' *** \n', df_ce)
json_pe = eval("[data['CE'] for data in df['records']['data'] if 'PE' in data and data['expiryDate'] == '" + expiry_dt + "']")
df_pe = json_normalize(json_pe)
print('*** NIFTY Put Options Data with Expiry Date: '+ expiry_dt + ' *** \n', df_pe)
Post a Comment for "How Do I Get The Live Option Chain?"