This project is a real-time stock price monitoring web application built with Flask, Kafka, and Plotly. It allows users to track real-time and historical stock prices of selected companies.
Before you begin, ensure you have met the following requirements:
- Python 3.7 or higher installed on your system.
- Access to a Confluent Cloud Kafka cluster.
- Confluent Kafka Python library installed (included in requirements.txt).
- A valid API key and secret for accessing the Confluent Cloud Kafka cluster.
To get this project up and running on your local machine, follow these steps:
git clone https://github.com/Shikha-code36/Real-Time-Stock-Price-Tracker-using-Kafka.git
cd Real-Time-Stock-Price-Tracker-using-Kafka
It's a good practice to create a virtual environment to isolate project dependencies. Run the following commands to create and activate a virtual environment:
python -m venv venv
venv\Scripts\activate # On Windows
source ./venv/bin/activate # On Linux & Mac OS X
Use pip to install the project's dependencies from the requirements.txt file:
pip install -r requirements.txt
Edit the config.py file and provide the following details:
- KAFKA_BOOTSTRAP_SERVERS: The Confluent Cloud
- Kafka cluster's bootstrap servers.
- KAFKA_TOPIC: The Kafka topic where stock prices will be published and consumed.
- API_KEY: Your Confluent Cloud API key.
- API_SECRET: Your Confluent Cloud API secret.
Start the Flask web application by running the following command:
python main.py
The app should now be available at http://localhost:5000/.
- Visit http://localhost:5000 to access the main dashboard.
- You can start and stop data production and consumption by clicking the respective buttons.
- Real-time and historical stock price charts will be displayed on the dashboard.
- producer.py: Handles fetching real-time stock prices and publishing them to Kafka.
- consumer.py: Consumes stock price data from Kafka and places it in a queue for the main thread.
- main.py: The main Flask application that serves the web interface.
- config.py: Configuration file for Kafka and API credentials.
- templates/: Contains HTML templates for the web pages.
In the config.py file, you can configure the following settings:
- KAFKA_BOOTSTRAP_SERVERS: The Kafka bootstrap servers.
- KAFKA_TOPIC: The Kafka topic for stock price data.
- API_KEY: Your Confluent Cloud API key.
- API_SECRET: Your Confluent Cloud API secret.
This project is licensed under the MIT License. See the LICENSE file for details.