我可以使这个工作:
#!/usr/bin/python
from nsepy import get_quote
from nsepy.derivatives import get_expiry_date
expiry = get_expiry_date(year=2019, month=9)
print(expiry)
data = get_quote('NIFTY', series='EQ', instrument='FUTIDX', expiry=expiry, option_type='CE', strike=300)
print(data)
输出:
building dictionary
2019-09-26
{'annualisedVolatility': 18.15, 'bestBuy': 10.5, 'totalSellQuantity': 263550, 'vwap': 11032.65, 'clientWisePositionLimits': 14074147, 'optionType': '-', 'highPrice': 11118.0, 'dailyVolatility': 0.95, 'bestSell': 11.31, 'marketLot': 75, 'sellQuantity5': 450, 'marketWidePositionLimits': '-', 'sellQuantity4': 150, 'sellQuantity3': 375, 'sellQuantity2': 150, 'underlying': 'NIFTY', 'sellQuantity1': 1275, 'pChange': 1.07, 'premiumTurnover': '-', 'totalBuyQuantity': 538425, 'turnoverinRsLakhs': 1219692.56, 'changeinOpenInterest': -377325, 'strikePrice': '-', 'openInterest': 16778250, 'buyPrice2': 11110.95, 'buyPrice1': 11111.0, 'openPrice': 10990.0, 'prevClose': 10996.45, 'expiryDate': '26SEP2019', 'lowPrice': 10962.15, 'buyPrice4': 11110.2, 'buyPrice3': 11110.45, 'buyPrice5': 11110.15, 'numberOfContractsTraded': 147404, 'instrumentType': 'FUTIDX', 'sellPrice1': 11113.7, 'sellPrice2': 11114.0, 'sellPrice3': 11114.5, 'sellPrice4': 11114.6, 'sellPrice5': 11114.7, 'change': 118.05, 'pchangeinOpenInterest': -2.2, 'ltp': 11.54, 'impliedVolatility': '-', 'underlyingValue': 11075.9, 'buyQuantity4': 1425, 'buyQuantity3': 75, 'buyQuantity2': 75, 'buyQuantity1': 1500, 'buyQuantity5': 150, 'settlementPrice': 11105.55, 'closePrice': 11105.55, 'lastPrice': 11114.5}
NSEpy 库中的文档似乎不正确,它说expiry
应该是 ( ddMMMyyyy
) 格式并且strike
(strike_price) 是一个强制性参数。
def get_quote(symbol, series='EQ', instrument=None, expiry=None, option_type=None, strike=None):
"""
1. Underlying security (stock symbol or index name)
2. instrument (FUTSTK, OPTSTK, FUTIDX, OPTIDX)
3. expiry (ddMMMyyyy)
4. type (CE/PE for options, - for futures
5. strike (strike price upto two decimal places
"""
https://nsepy.readthedocs.io/en/latest/#quick-hand-on