Unofficial library to interface with nepalstock.com Deciphers the authentication key to access the api.
- Make sure your python version >= 3.8.0
- Download this git repo into your local computer.
- Change the directory to NepseUnofficialApi
- Install the package
git clone https://github.com/basic-bgnr/NepseUnofficialApi.git
cd NepseUnofficialApi
pip3 install .
pip install git+https://github.com/basic-bgnr/NepseUnofficialApi
from nepse import Nepse
nepse = Nepse()
nepse.setTLSVerification(False) #This is temporary, until nepse sorts its ssl certificate problem
nepse.getCompanyList()
After installing the package, nepse-cli
cmdline tool is available
dev└─ $ nepse-cli --help
usage: nepse-cli [-h] [-v] [--start-server] [--show-status] [--get-floorsheet] [--output-file FILE] [--to-csv] [--hide-progressbar]
cmdline interface to nepalstock.com
options:
-h, --help show this help message and exit
-v, --version displays the version info
--start-server starts local server at 0.0.0.0:8000
--show-status dumps Nepse status to the standard output
--get-floorsheet dumps Nepse's floorsheet to the standard output
--output-file FILE sets the output file for dumping the content
--to-csv sets the output format from default[JSON] to CSV
--hide-progressbar sets the visibility of progress base to False
To Download the entire floorsheet of the day into file floor.json
in JSON
format, you can.
nepse-cli --get-floorsheet --output-file floor.json
To Download the entire floorsheet of the day into file floor.csv
in CSV
format, you can.
nepse-cli --get-floorsheet --to-csv --output-file floor.csv
The example folder contains /example/NepseServer.py
an implementation of
this library. The following runs a local flask server on localhost:8000
.
cd example
python3 NepseServer.py
Running the following command will remove the package from the system.
pip uninstall nepse
- [Apr 14, 2024]
- Added new cmd-line flag [--version]
- [Apr 11, 2024]
- Added new cmd-line flag [--to-csv]
- removed bug on empty argument to nepse-cli
- [Apr 10, 2024]
- Handled httpx.RemoteProtocolError when sending multiple request to nepse's server.
- Added new cmd-line flags [--get-floorsheet, --output-file]
- [Apr 09, 2024]
- APIs now make use of HTTP2 request to nepse's server
- Added tool
nepse-cli
which can be directly used from the terminal after installing the package
- [Apr 08, 2024]
- APIs can now be called without rate limitation or raising Exception (no need to add delay between API calls),
- Speed Improvement ( getFloorSheet() and getFloorSheetOf() calls are ~3 times faster)
- [Apr 07, 2024] getFloorSheet and getFloorSheetOf now works without raising exception
- [Apr 05, 2024] Speed Improvement (remove dependency from requests to httpx, http calls are now faster)
- [Mar 23, 2024] add setup.py to ease installation process.
- [Oct 20, 2023] moved api_endpoints, headers, and dummy_data to loadable json file
- [Oct 10, 2023] Module(files, folders) restructuring
- [Sep 24, 2023] Fixed SSL CERTIFICATE_VERIFY_FAILED.
- [Sep 24, 2023] Branch
15_feb_2023
is now merged with the master branch. - [Feb 15, 2023]
checkout new branch 15_feb_2023 to adjust for new change in Nepse.
Recently there was a PR in this repo by @Prabesh01 to merge few changes to fix SSL issue that he was facing.
requests.exceptions.SSLError:
HTTPSConnectionPool(host='www.nepalstock.com.np', port=443):
Max retries exceeded with url: /api/authenticate/prove
(Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED]
certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)')))
The day when I actually received that PR, I too was facing similar issue with Nepse's website, so I thought the issue was serverside and left it as it is.
Fast-forward today, upon diving a little deeper, It appears that the issue can be solved entirely from clientside. But it has nothing to do with code in this repository, it was because my linux distribution(and maybe others too, I haven't checked) doesn't have ca-certificate of Certificate Authority GeoTrust that signs the ssl certificate of Nepse. The mistake is primarily due to Nepse as it means that the certificate chain used by Nepse is incomplete.
- Find out the ssl certificate details of Nepse using ssllabs.com.
- Copy the .pem file from the ssllabs and save it into your
/usr/local/share/ca-certificates/
folder using the following command1.
sudo curl -A "Mozilla Chrome Safari" "https://www.ssllabs.com/ssltest/getTestCertificate?d=nepalstock.com.np&cid=3a83c9a7e960f29b48e5719510e2e8582c37f72f3abf35e6f400eaacec38aad2&time=1695547628855" >> geotrust.pem
sudo curl -A "Mozilla Chrome Safari" "https://www.ssllabs.com/ssltest/getTestChain?d=nepalstock.com.np&cid=3a83c9a7e960f29b48e5719510e2e8582c37f72f3abf35e6f400eaacec38aad2&time=1695547628855" >> geotrust_alt.pem
- and, finally you've to run the following command1 to include the added CA details into the system.
sudo update-ca-certificates