This project consists of a series of Python scripts designed to fetch, process, and analyze stock data. The following scripts are included in this project:
config.py
generate_request_token.py
generate_access_token.py
fetch_data.py
process_data.py
sort_and_trim_data.py
latest_entry.py
filter_latest_entries.py
consolidate_analysis.py
- Python 3.x
To clone the project from GitHub, use the following command:
git clone https://github.com/anurag265/sharekhan_api.git
cd sharekhan_api
Make sure you have the required Python packages installed. You can install them using the provided requirements.txt
file:
pip install -r requirements.txt
This script sets up the necessary configuration parameters for the Sharekhan API, including API keys and other authentication details.
This script generates a login URL for the Sharekhan API. Users need to log in using the URL and obtain the request token.
python generate_request_token.py
This script generates the session and access token using the request token obtained from the login URL.
python generate_access_token.py
This script fetches historical stock data using the Sharekhan API and saves the data as CSV files in the stock_data
directory.
python fetch_data.py
This script processes the fetched stock data by calculating the 5-day moving average and relative volume change. The processed data is saved back to the stock_data
directory.
python process_data.py
This script sorts and trims the processed data based on the relative volume change and saves the trimmed data to the trimmed
directory.
python sort_and_trim_data.py
This script extracts the latest entry from each CSV file in the stock_data
directory and consolidates them into a single CSV file named latest_entries.csv
.
python latest_entry.py
This script filters the consolidated latest entries based on a relative volume change threshold and sorts the entries from large to small. The filtered data is saved to a new CSV file named filtered_latest_entries.csv
.
python filter_latest_entries.py
This script consolidates all analysis CSV files from the trimmed
directory into a single Excel sheet named consolidated_stock_analysis.xlsx
.
python consolidate_analysis.py
To run the entire pipeline, execute the scripts in the following order:
generate_request_token.py
generate_access_token.py
fetch_data.py
process_data.py
sort_and_trim_data.py
latest_entry.py
filter_latest_entries.py
consolidate_analysis.py
This will fetch, process, and analyze the stock data, resulting in a consolidated analysis Excel file containing the relevant stock data insights.
If you encounter the following error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[15], line 17
15 # Generate session and access token
16 if version_id:
---> 17 session = login.generate_session(request_token, secret_key)
18 access_token_response = login.get_access_token(api_key, session, state, versionId=version_id)
19 else:
File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\SharekhanApi\sharekhanConnect.py:242, in SharekhanConnect.generate_session(self, request_token, secret_key)
241 import base64
--> 242 from Crypto.Cipher import AES
243 from Crypto.Util.Padding import pad
244 from cryptography.hazmat.backends import default_backend
ModuleNotFoundError: No module named 'Crypto'
You can resolve it by uninstalling conflicting packages and reinstalling pycryptodome
:
pip uninstall crypto
pip uninstall pycryptodome
pip uninstall pycrypto
pip install pycryptodome
This project is licensed under the MIT License.