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

NSE Lot Sizes function throws error #42

Open
pratham-darooka opened this issue Apr 29, 2024 · 7 comments
Open

NSE Lot Sizes function throws error #42

pratham-darooka opened this issue Apr 29, 2024 · 7 comments

Comments

@pratham-darooka
Copy link

File .venv/lib/python3.12/site-packages/nsepython/rahu.py", line 484, in nse_get_fno_lot_sizes (code, name) = [x.strip() for x in line.split(',')[1:3]] ^^^^^^^^^^^^ ValueError: not enough values to unpack (expected 2, got 1)

Seems like the problem is in the url:
url="https://archives.nseindia.com/content/fo/fo_mktlots.csv"

Throws 404. Perhaps need a new URL?

@mdtanveer
Copy link

mdtanveer commented May 2, 2024

Temporarily using dhan.co for getting lot sizes until this is fixed.

from memoization import cached
import jmespath, requests, json
@cached(ttl=30 * 24 * 3600)
def get_lot_sizes_dhan():
res = requests.post("https://open-web-scanx.dhan.co/scanx/allfut",
json=json.loads('{"Data":{"Seg":2,"Instrument":"FUT","Count":200,"Page_no":1,"ExpCode":-1}}'),
headers={
"content-type": "application/json; charset=UTF-8"
},
cookies={},
auth=(),
)
lots = jmespath.search("data.list[*].[sym, fo_dt[0].lot_type]", res.json())
result = {x[0]:int(x[1].split()[0]) for x in lots}
return result

@pratham-darooka
Copy link
Author

Thanks @aeron7

@mirajgodha
Copy link

url="https://archives.nseindia.com/content/fo/fo_mktlots.csv"
not able to find the new location of this url, did anyone found it or temporary have old csv which can work as a temporary solution.

@pratham-darooka
Copy link
Author

@mirajgodha you can use this:

lot_size = nsepython.nse_quote(symbol=<symbol>)['stocks'][i]['marketDeptOrderBook']['tradeInfo']['marketLot’]

cc: @aeron7

@buzzvolt
Copy link

I would suggest to take a look at NSE Circulars dated March 15th here at https://nsearchives.nseindia.com/content/circulars/FAOP61157.pdf

It is the problem of NSE and users (us) -- not the authors' -- not that he would care anyway. You will have to use the forums in general. NSE website should ideally have resorted to 404 code but they hook you and make you think something is wrong with your code. thankfully! circulars give you more information.

Not that you are on your own here, but I would suggest to take a look at the other API methods available in the nsepython library and see if you can deduce the lot size from there and see if you could provide a working patch for the same? hope that is constructive. Please feel free to revert.

@buzzvolt
Copy link

Temporarily using dhan.co for getting lot sizes until this is fixed.

from memoization import cached import jmespath, requests, json @cached(ttl=30 * 24 * 3600) def get_lot_sizes_dhan(): res = requests.post("https://open-web-scanx.dhan.co/scanx/allfut", json=json.loads('{"Data":{"Seg":2,"Instrument":"FUT","Count":200,"Page_no":1,"ExpCode":-1}}'), headers={ "content-type": "application/json; charset=UTF-8" }, cookies={}, auth=(), ) lots = jmespath.search("data.list[*].[sym, fo_dt[0].lot_type]", res.json()) result = {x[0]:int(x[1].split()[0]) for x in lots} return result

thanks @mdtanveer this is cool as an alternative .. infact, I was debugging dhan get fno lot size webpage but this seems to be what is needed.

@buzzvolt
Copy link

I think we all most possibly agree that we could prefer something from the original source, i.e., NSE website itself. So, perhaps exploring more on the NSE website and looking up for any REST urls could be useful and then backtracking the same into library update would be awesome.

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

4 participants