Downloading and searching symbols in Flattrade symbolmaster
==> This code needs python 3.11 and latest pandas (above 2.0) to run correctly.
==> BFO Exchange is still not implemented.
==> It is still in development phase and may produce various errors.
==> Sometimes it is stucked when fetching symbolmaster(from web). I couldn't figure out the reason till now.
==> get_exchange will not work correctly if "NSE" and "NFO" both exchange are initialised at same instance. Some common symbols creates that issue.
***So two separate instances needed to run thing correctly as for now.***
from symbolsearch import SearchScrip
sc = SearchScrip()
Now its needed to initialize symbols of the required exchanges.
It will not not download the symbolmaster for a exchange within the same day twice unless
it is specified by using hard_refresh=True
exch_list = ['NSE', 'NFO']
sc.initialize_symbols(exch_list=exch_list)
get_expiry(exch, instrument, symbol, expiry) By default, it returns current expiry of banknifty options
sc.get_expiry()
datetime.date(2023, 7, 13)
sc.get_expiry(exch='NFO', instrument='FUTIDX', symbol='FINNIFTY',expiry='current')
datetime.date(2023, 7, 25)
search_scrip(exch, **kwargs)
The function will return in 3 different ways depending on the inputs
1. if **kwargs params are symbol, instrument, optiontype, expiry, strikeprice then it
will return corresponding tradingsymbol and token
2. if **kwargs params are same as point 1 but lacks any of the input then it will
return a dict of tradingsymbols and tokens
3. if **kwargs input is tradingsymbol then it will return the corresponding token
sc.search_scrip(exch='NFO', symbol='BANKNIFTY', instrument='OPTIDX',
optiontype='CE', expiry="13-7-2023", strikeprice=44000)
array(['BANKNIFTY13JUL23C44000', 41702], dtype=object)
sc.search_scrip(exch='NFO', symbol='BANKNIFTY', instrument='OPTIDX',
expiry="13-7-2023", strikeprice=44000)
{'BANKNIFTY13JUL23P44000': 41703, 'BANKNIFTY13JUL23C44000': 41702}
sc.search_scrip(exch='NFO', tradingsymbol='BANKNIFTY13JUL23C44000')
41702
get_tradingsymbol(exch, **kwargs)
Returns tradingsymbol
**kwargs params are symbol, instrument, optiontype, strikeprice, expiry for 'NFO',
'MCX' & 'CDS'
**kwargs params are symbol, instrument for 'NSE'
sc.get_tradingsymbol(exch='NFO', symbol='BANKNIFTY', instrument='OPTIDX',
optiontype='CE', expiry="13-7-2023", strikeprice=44000)
'BANKNIFTY13JUL23C44000'
sc.get_tradingsymbol(exch='NSE', symbol='HDFC', instrument='EQ')
'HDFC-EQ'
get_lotsize(exch, **kwargs)
Returns lotsize of the given symbol.
1. **kwargs -> tradingsymbol
2. **kwargs -> symbol, expiry
3. **kwargs -> symbol (lacks accuracy as it will return the lotsize
regardless of expiry.)
sc.get_lotsize(exch='NFO', symbol='BANKNIFTY')
25
sc.get_lotsize(exch='NFO', symbol='BANKNIFTY', expiry='27-7-2023')
15
get_exchange(tradingsymbol)
Returns the corresponding exchange name for the given tradingsymbol.
sc.get_exchange(tradingsymbol="BANKNIFTY27JUL23C52000")
'NFO'
get_strikediff(exch,symbol)
Returns Option strikeprice difference for the given symbol. 'NFO' is the default exchange.
sc.get_strikediff(symbol="HDFCBANK")
10.0
sc.get_strikediff(exch='MCX', symbol='CRUDEOIL')
50.0