nsepython icon indicating copy to clipboard operation
nsepython copied to clipboard

NSE Lot Sizes function throws error

Open pratham-darooka opened this issue 1 year ago • 7 comments

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?

pratham-darooka avatar Apr 29 '24 07:04 pratham-darooka

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

mdtanveer avatar May 02 '24 14:05 mdtanveer

Thanks @aeron7

pratham-darooka avatar May 04 '24 04:05 pratham-darooka

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.

mirajgodha avatar May 04 '24 16:05 mirajgodha

@mirajgodha you can use this:

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

cc: @aeron7

pratham-darooka avatar May 13 '24 16:05 pratham-darooka

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 avatar May 24 '24 07:05 buzzvolt

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 avatar May 24 '24 07:05 buzzvolt

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.

buzzvolt avatar May 24 '24 08:05 buzzvolt

Use https://forum.unofficed.com/ to address.

aeron7 avatar Nov 10 '24 12:11 aeron7