Skip to content

Commit d2ce7d4

Browse files
committed
1
1 parent eff361d commit d2ce7d4

2 files changed

Lines changed: 62 additions & 22 deletions

File tree

nsepython/rahu.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,10 @@ def nse_quote_ltp(symbol,expiryDate="latest",optionType="-",strikePrice=0):
183183
#https://stackoverflow.com/questions/7961363/removing-duplicates-in-lists
184184
#https://stackoverflow.com/questions/19199984/sort-a-list-in-python
185185
if(expiryDate=="latest") or (expiryDate=="next"):
186-
if(optionType!="Fut"):
187-
dates=list(set((payload["expiryDates"])))
188-
dates.sort(key = lambda date: datetime.datetime.strptime(date, '%d-%b-%Y'))
189-
expiryDate=dates[0]
190-
if(expiryDate=="next"):expiryDate=dates[1]
186+
dates=list(set((payload["expiryDates"])))
187+
dates.sort(key = lambda date: datetime.datetime.strptime(date, '%d-%b-%Y'))
188+
if(expiryDate=="latest"): expiryDate=dates[0]
189+
if(expiryDate=="next"): expiryDate=dates[1]
191190

192191
meta = "Options"
193192
if(optionType=="Fut"): meta = "Futures"
@@ -198,26 +197,31 @@ def nse_quote_ltp(symbol,expiryDate="latest",optionType="-",strikePrice=0):
198197
for i in payload['stocks']:
199198
if meta in i['metadata']['instrumentType']:
200199
#print(i['metadata'])
201-
if(expiryDate=="latest"):
202-
lastPrice = i['metadata']['lastPrice']
203-
break
204-
205-
if (i['metadata']["expiryDate"]==expiryDate):
206-
if (i['metadata']["optionType"]==optionType):
207-
if (i['metadata']["strikePrice"]==strikePrice):
208-
#print(i['metadata'])
200+
if(optionType=="Fut"):
201+
if(i['metadata']['expiryDate']==expiryDate):
209202
lastPrice = i['metadata']['lastPrice']
210203

204+
if((optionType=="Put")or(optionType=="Call")):
205+
if (i['metadata']["expiryDate"]==expiryDate):
206+
if (i['metadata']["optionType"]==optionType):
207+
if (i['metadata']["strikePrice"]==strikePrice):
208+
#print(i['metadata'])
209+
lastPrice = i['metadata']['lastPrice']
210+
211211
if(optionType=="-"):
212212
lastPrice = payload['underlyingValue']
213213

214214
return lastPrice
215215

216-
# print(nse_quote_ltp("BANKNIFTY"))
217-
# print(nse_quote_ltp("RELIANCE","latest","Fut"))
218-
# print(nse_quote_ltp("RELIANCE"))
219-
# print(nse_quote_ltp("BANKNIFTY","13-Aug-2020","PE",21000))
220-
# print(nse_quote_ltp("RELIANCE","latest","PE",2300))
216+
# print(nse_quote_ltp("RELIANCE"))
217+
# print(nse_quote_ltp("RELIANCE","latest","Fut"))
218+
# print(nse_quote_ltp("RELIANCE","next","Fut"))
219+
# print(nse_quote_ltp("BANKNIFTY","latest","PE",32000))
220+
# print(nse_quote_ltp("BANKNIFTY","next","PE",32000))
221+
# print(nse_quote_ltp("BANKNIFTY","10-Jun-2021","PE",32000))
222+
# print(nse_quote_ltp("BANKNIFTY","17-Jun-2021","PE",32000))
223+
# print(nse_quote_ltp("RELIANCE","latest","PE",2300))
224+
# print(nse_quote_ltp("RELIANCE","next","PE",2300))
221225

222226
def nse_optionchain_ltp(payload,strikePrice,optionType,inp=0,intent=""):
223227
expiryDate=payload['records']['expiryDates'][inp]
@@ -293,11 +297,20 @@ def nse_past_results(symbol):
293297
symbol = nsesymbolpurify(symbol)
294298
return nsefetch('https://www.nseindia.com/api/results-comparision?symbol='+symbol)
295299

296-
def expiry_list(symbol):
300+
def expiry_list(symbol,type="list"):
297301
logging.info("Getting Expiry List of: "+ symbol)
298-
payload = nse_optionchain_scrapper(symbol)
299-
payload = pd.DataFrame({'Date':payload['records']['expiryDates']})
300-
return payload
302+
303+
if(type!="list"):
304+
payload = nse_optionchain_scrapper(symbol)
305+
payload = pd.DataFrame({'Date':payload['records']['expiryDates']})
306+
return payload
307+
308+
if(type=="list"):
309+
payload = nse_quote(symbol)
310+
dates=list(set((payload["expiryDates"])))
311+
dates.sort(key = lambda date: datetime.datetime.strptime(date, '%d-%b-%Y'))
312+
return dates
313+
301314

302315
def nse_custom_function_secfno(symbol,attribute="lastPrice"):
303316
positions = nsefetch('https://www.nseindia.com/api/equity-stockIndices?index=SECURITIES%20IN%20F%26O')

setup.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import setuptools
2+
3+
with open("README.md", "r") as fh:
4+
long_description = fh.read()
5+
6+
setuptools.setup(
7+
name = 'nsepython',
8+
packages=setuptools.find_packages(),
9+
version = '0.0.954',
10+
include_package_data=True,
11+
description = 'Python library for NSE India APIs',
12+
long_description=long_description,
13+
long_description_content_type="text/markdown", author = 'Aeron7',
14+
author_email = 'hello@aeron7.com',
15+
url = 'https://github.com/aeron7/nsepython',
16+
install_requires=['requests', 'pandas'],
17+
keywords = ['nseindia', 'nse', 'python', 'sdk', 'trading', 'stock markets'],
18+
classifiers=[
19+
'Intended Audience :: Developers',
20+
'Natural Language :: English',
21+
'Operating System :: OS Independent',
22+
'Programming Language :: Python',
23+
'Programming Language :: Python :: 3',
24+
'Programming Language :: Python :: Implementation :: PyPy',
25+
'Topic :: Software Development :: Libraries :: Python Modules'
26+
],
27+
)

0 commit comments

Comments
 (0)