Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get lot size of stocks with original stock name, instead of some other symbol... #123

Open
kishoretarun opened this issue Jun 7, 2021 · 1 comment

Comments

@kishoretarun
Copy link

how to get lot size of stocks with original stock name, instead of some other symbol...

for example- It is returing "banknifty" with its lot size.. but the original stock symbol is "NIFTY BANK"
is their any way to filter this out?

@seenureddy
Copy link

seenureddy commented Jun 14, 2021

@kishoretarun As of now this code won't support that feature. You can try this code to find "NIFTY BANK".

If you want stock name in nsetool library change these lines in get_fno_lot_sizes method.

(underlying_code, _,  name) = [x.strip() for x in line.split(',')[0:3]]
res_dict[underlying_code] = int(name)

Save this in stock.py file and run python stock.py.

import six
import re
from http.cookiejar import CookieJar
from urllib.request import build_opener, HTTPCookieProcessor, Request
from pprint import pprint # just for neatness of display


headers = {
	'Accept': '*/*',
	'Accept-Language': 'en-US,en;q=0.5',
	'Host': 'www1.nseindia.com',
	'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0',
	'X-Requested-With': 'XMLHttpRequest'
}

fno_lot_size_url = "https://www1.nseindia.com/content/fo/fo_mktlots.csv"
req = Request(fno_lot_size_url, None, headers, None, True)

cj = CookieJar()
opener = build_opener(HTTPCookieProcessor(cj))
res = opener.open(req)

strings = res.read().decode('latin-1')
fbuffer = six.StringIO(strings)

res_dict = {}
for line in fbuffer.read().split('\n'):
	if line != '' and re.search(',', line) and (line.casefold().find('symbol') == -1):
		(underlying_code, _,  name) = [x.strip() for x in line.split(',')[0:3]]
		res_dict[underlying_code] = int(name)
pprint(res_dict)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants