Skip to main content

A Production-Ready Portfolio Dashboard for Kotak Neo API

Project description

Kotak Neo Portfolio Dashboard ๐Ÿ“ˆ

A professional, production-ready Python dashboard for tracking your Kotak Securities portfolio in real-time. Built with Streamlit, this application connects to the Kotak Neo API to provide live P&L tracking, sector analytics, and visual portfolio insights.

๐Ÿš€ Features

๐Ÿ“Š Live Portfolio Hydration

  • Automatically fetches live market quotes (LTP)
  • Updates your portfolio value in real-time

๐Ÿง  Intelligent Caching

  • Smart fallback logic
  • Calculates Day's Change using OHLC data if the live feed is incomplete

๐Ÿ“ˆ Visual Analytics

  • Day's P&L Tracking: See exactly how much your portfolio moved today
  • Sector Allocation: Interactive Donut charts showing exposure by sector
  • Allocation Bar Chart: Visual breakdown of investment distribution

๐Ÿ” Secure Authentication

  • Uses TOTP (Time-based OTP) for seamless 2FA login
  • Credentials stored securely in a local .env file (never hardcoded)

๐Ÿงฑ Robust Architecture

  • Modular backend design
  • Separation of:
    • Authentication
    • Data Fetching
    • Analytics

๐Ÿ“‚ Project Structure

kotak-dashboard/
โ”œโ”€โ”€ .devcontainer/       # VS Code Dev Container configuration
โ”œโ”€โ”€ .github/workflows/   # CI/CD Pipelines
โ”œโ”€โ”€ kotak_dashboard/     # Main Application Package
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ app.py           # Streamlit UI Layer
โ”‚   โ”œโ”€โ”€ backend.py       # Core Logic (Auth, API, Math)
โ”‚   โ””โ”€โ”€ cli.py           # Command-line entry point
โ”œโ”€โ”€ tests/               # Test Suite
โ”‚   โ”œโ”€โ”€ conftest.py
โ”‚   โ”œโ”€โ”€ test_backend_analytics.py
โ”‚   โ””โ”€โ”€ test_backend_data.py
โ”œโ”€โ”€ .env.example         # Template for API credentials
โ”œโ”€โ”€ Dockerfile           # Production-ready Docker image
โ”œโ”€โ”€ pyproject.toml       # Modern Python dependency management
โ””โ”€โ”€ README.md            # Documentation

๐Ÿ› ๏ธ Prerequisites

Python Environment

  • Python 3.11+ (Strict requirement for neo_api_client compatibility)

Kotak Neo API Credentials

You will need the following from the Kotak Neo API Portal:

  • Consumer Key
  • Mobile Number
  • UCC (User Client Code)
  • TOTP Secret Key (The alphanumeric key used to generate 2FA codes)
  • MPIN

โš™๏ธ Installation & Setup

Option 1: Standard Local Install (Recommended)

  1. Clone the repository

    git clone https://github.com/yourusername/kotak-dashboard.git
    cd kotak-dashboard
    
  2. Create a Virtual Environment (Python 3.11)

    # macOS/Linux
    python3.11 -m venv .venv
    source .venv/bin/activate
    
    # Windows
    py -3.11 -m venv .venv
    .venv\Scripts\activate
    
  3. Install Dependencies We use pip to install the package in editable mode.

    pip install --upgrade pip
    pip install -e .
    

Option 2: Using Docker ๐Ÿณ

Run the dashboard in an isolated container without installing Python locally.

  1. Build the image

    docker build -t kotak-dashboard .
    
  2. Run the container

    docker run -p 8501:8501 -v $(pwd)/.env:/app/.env kotak-dashboard
    

Option 3: VS Code Dev Container

  1. Open the project folder in VS Code.
  2. Install the Dev Containers extension.
  3. Press F1 and select "Dev Containers: Reopen in Container".
  4. VS Code will build a fully configured environment for you.

๐Ÿงช Running Tests

This project uses pytest for unit testing. The test suite covers:

  • Authentication flows
  • Data hydration logic
  • Analytics calculations

Install Test Dependencies

pip install -e .[test]

๐Ÿš€ CI/CD Pipeline

The project includes a GitHub Actions workflow (.github/workflows/ci_cd.yml) that automatically:

  • Sets up Python 3.11
  • Runs the full test suite with pytest
  • Builds the Python package (Source Distribution & Wheel)
  • Uploads the build artifacts to GitHub

๐Ÿ”‘ Configuration

First Run Setup

When you run the app for the first time, a sidebar will appear asking for your credentials.

  1. Enter your Consumer Key, Mobile, UCC, TOTP Secret, and MPIN.
  2. Click "Save & Login".
  3. This will automatically create a .env file in your project root.

Manual Setup (Optional)

Copy the example file and fill it in manually:

cp .env.example .env

Edit .env:

KOTAK_CONSUMER_KEY=your_key_here
KOTAK_MOBILE=9876543210
KOTAK_UCC=YA004
KOTAK_TOTP_SECRET=YOURSECRETKEY123
KOTAK_MPIN=123456

๐Ÿƒโ€โ™‚๏ธ Usage

Once installed, you can start the dashboard using the command line:

kotak-dashboard

Or directly via Streamlit:

streamlit run kotak_dashboard/app.py

Open your browser to http://localhost:8501 to view your portfolio.

โš ๏ธ Disclaimer

This application is an unofficial tool built for educational and personal tracking purposes. It interacts with the Kotak Neo API but is not affiliated with Kotak Securities.

  • Trading Risk: Stock market investments are subject to market risks. This tool does not provide financial advice.
  • Security: Your credentials are stored locally on your machine in the .env file. Do not share this file or commit it to public repositories.

Built with โค๏ธ using Python & Streamlit.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kotak_dashboard-1.0.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kotak_dashboard-1.0.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file kotak_dashboard-1.0.0.tar.gz.

File metadata

  • Download URL: kotak_dashboard-1.0.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kotak_dashboard-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fcfba1765ba2ed0bcf1aab6918c8458becfd95737dbf778494e82303d76d41bd
MD5 f299515b5b9226a237ac0911be927de8
BLAKE2b-256 0d3eca54bdaf57f24bfa84697d79806ac12131bbaca922b4146bebe1d22ec123

See more details on using hashes here.

File details

Details for the file kotak_dashboard-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for kotak_dashboard-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23cbfd515073aff19996d53036cbe43ae615a268afa40f4cb11a10e809e1bcad
MD5 a0ac9a27d7d2b19c3c02a5b7ce2968ab
BLAKE2b-256 154115268d05622d46c5c49a3ed3394bb0d40db2b97b53bf820a2c0f2821a36e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page