Skip to content
Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ˆ Stock Discovery & Market Analysis Platform

CI Python License Platform Broker

A modular, Streamlit-based stock market analysis application built on top of the Zerodha Kite Connect API. Below is a clean, polished, open-source–ready README refactored from your earlier version. This version is suitable for GitHub public repositories, recruiters, contributors, and maintainers. Tone is neutral, professional, and community-friendly, while still explaining internals clearly.

You can use this as-is for README.md.


πŸ“ˆ Stock Discovery & Market Analysis Platform

A modular, Streamlit-based stock market analysis application built on top of the Zerodha Kite Connect API. The project emphasizes clean architecture, separation of concerns, and performance, making it easy to extend for backtesting, algo trading, or multi-broker integrations.


πŸš€ Features

  • πŸ” Stock search by symbol or company name
  • πŸ“Š Live price & historical OHLC data
  • πŸ“ˆ High-performance candlestick charts (Lightweight Charts)
  • ⭐ Favorites / watchlist management
  • πŸ‘€ User profile, funds & margins view
  • ⚑ Instrument caching for fast search
  • πŸ” Secure environment-based configuration

🧱 Architecture Overview

The application follows a layered architecture:

UI Layer (Streamlit)
        ↓
Service Layer (Business Logic)
        ↓
Broker Client Layer (Zerodha Kite)
        ↓
External Broker APIs

Core Principles

  • UI never communicates directly with broker APIs
  • All broker logic is isolated in services
  • Configuration and secrets are environment-driven
  • Services are reusable and testable

πŸ“ Project Structure

β”‚
β”œβ”€β”€ main.py
β”‚
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ settings.py
β”‚   └── env.py
β”‚
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ kite_client.py
β”‚   β”œβ”€β”€ profile_service.py
β”‚   β”œβ”€β”€ search_service.py
β”‚   β”œβ”€β”€ data_service.py
β”‚   └── fav_service.py
β”‚
β”œβ”€β”€ ui/
β”‚   β”œβ”€β”€ profile.py
β”‚   β”œβ”€β”€ search.py
β”‚   β”œβ”€β”€ saved.py
β”‚   └── lightweight_charts.py
β”‚
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ instruments.py
β”‚   β”œβ”€β”€ charts.py
β”‚   └── downloader.py
β”‚
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ favorites.json
β”‚   └── cache/
β”‚
β”œβ”€β”€ requirements.txt
└── .env

🧩 Detailed Component Explanation

main.py β€” Application Entry Point

  • Initializes Streamlit
  • Configures page layout and navigation
  • Creates shared service instances
  • Acts as the orchestration layer for the app

config/ β€” Configuration Layer

settings.py

  • Centralized application constants
  • Time intervals, feature flags, defaults
  • Keeps configuration out of business logic

env.py

  • Loads environment variables from .env
  • Prevents secrets from being hardcoded
  • Enables easy environment switching

services/ β€” Business Logic Layer

kite_client.py

  • Initializes and manages the KiteConnect client
  • Implemented as a singleton
  • Handles authentication and session reuse

profile_service.py

  • Fetches user profile information
  • Retrieves funds and margin details
  • Normalizes broker responses for UI

search_service.py

  • Performs stock search using cached instruments
  • Maps company names β†’ trading symbols

data_service.py

  • Fetches historical OHLC data
  • Retrieves live market quotes
  • Prepares data for chart rendering

fav_service.py

  • Manages favorites/watchlist persistence
  • Abstracts storage away from UI

ui/ β€” Presentation Layer

search.py

  • Core trading interface
  • Search bar and symbol selection
  • Triggers data fetch and chart updates

profile.py

  • Displays user profile and account data
  • Uses profile_service exclusively

saved.py

  • Displays saved/watchlisted stocks
  • Loads data via fav_service

lightweight_charts.py

  • High-performance chart renderer
  • Candlestick, volume, and indicator support
  • Optimized for real-time updates

utils/ β€” Utility Layer

instruments.py

  • Loads and caches instrument dump
  • Enables fast symbol-to-token mapping
  • Avoids repeated API calls

charts.py

  • Shared Plotly helper functions
  • Used for non-real-time visualizations

downloader.py

  • CSV export utilities
  • Enables data downloads

data/ β€” Local Persistence

  • favorites.json stores user watchlists
  • cache/ holds cached instrument dumps
  • Designed for easy migration to DB/Redis later

πŸ”„ Application Workflow

Startup

main.py
 β†’ load env
   β†’ load settings
     β†’ initialize Kite client
       β†’ load instrument cache

Stock Search

UI (search.py)
 β†’ SearchService
   β†’ InstrumentCache

Market Data

UI (search.py)
 β†’ DataService
   β†’ KiteClient
     β†’ Zerodha API

Profile & Funds

UI (profile.py)
 β†’ ProfileService
   β†’ KiteClient

Favorites

UI (saved.py)
 β†’ FavService
   β†’ favorites.json

πŸ›  Installation & Setup

Prerequisites

  • Python 3.9+
  • Zerodha Kite Connect account

Install Dependencies

pip install -r requirements.txt

Environment Variables

Create a .env file:

KITE_API_KEY=your_api_key
KITE_ACCESS_TOKEN=your_access_token

Run the App

streamlit run main.py

πŸ§ͺ Extensibility & Roadmap

Planned or easily extendable features:

  • WebSocket live tick streaming
  • Backtesting engine
  • Algo trading execution
  • Multi-broker support (AngelOne, Upstox)
  • Database-backed persistence
  • Strategy indicators & signals

🧩 System Design Diagram

Image

Image

Image

Image


πŸ— High-Level System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        User Browser         β”‚
β”‚  (Search β€’ Charts β€’ Profile)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Streamlit UI Layer      β”‚
β”‚  ───────────────────────── β”‚
β”‚  β€’ search.py                β”‚
β”‚  β€’ profile.py               β”‚
β”‚  β€’ saved.py                 β”‚
β”‚  β€’ lightweight_charts.py    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Service Layer           β”‚
β”‚  ───────────────────────── β”‚
β”‚  β€’ SearchService            β”‚
β”‚  β€’ DataService              β”‚
β”‚  β€’ ProfileService           β”‚
β”‚  β€’ FavService               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Broker Client Layer       β”‚
β”‚  ───────────────────────── β”‚
β”‚  β€’ KiteClient (Singleton)   β”‚
β”‚  β€’ Auth / Session Handling  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Zerodha Kite Connect API  β”‚
β”‚  ───────────────────────── β”‚
β”‚  β€’ Quotes                   β”‚
β”‚  β€’ Historical OHLC          β”‚
β”‚  β€’ Profile & Margins        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Local Storage & Cache     β”‚
β”‚  ───────────────────────── β”‚
β”‚  β€’ Instrument Cache         β”‚
β”‚  β€’ favorites.json           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ” Component Responsibilities

1️⃣ User / Browser

  • Interacts with the application via Streamlit UI
  • Requests data through UI actions (search, select stock, view profile)

2️⃣ UI Layer (Streamlit)

Role

  • Presentation & interaction only
  • No broker logic
  • No raw API calls

Key Responsibilities

  • Render search interface
  • Display charts and tables
  • Trigger service calls
  • Maintain UI state across reruns

3️⃣ Service Layer (Business Logic)

Why this layer exists

  • Isolates business rules
  • Makes logic testable and reusable
  • Prevents UI β†’ Broker coupling

Responsibilities

  • Search logic using cached instruments
  • Fetch & normalize market data
  • Fetch profile, funds, margins
  • Handle favorites persistence

4️⃣ Broker Client Layer (KiteClient)

Key Characteristics

  • Singleton pattern
  • Authenticated session reuse
  • Centralized API error handling

Why singleton

  • Streamlit reruns scripts frequently
  • Prevents repeated login / token issues
  • Avoids rate-limit problems

5️⃣ Zerodha Kite Connect API

Provides

  • Live market quotes
  • Historical OHLC candles
  • User profile & margin data

Access Rules

  • Accessed only through KiteClient
  • Never directly from UI

6️⃣ Cache & Local Storage

Instrument Cache

  • Loaded once at startup
  • Enables instant symbol search
  • Avoids heavy repeated API calls

favorites.json

  • Lightweight persistence
  • User watchlist storage
  • Easily replaceable with DB later

πŸ”„ End-to-End Data Flow

πŸ” Stock Search

User
 β†’ UI (search.py)
   β†’ SearchService
     β†’ Instrument Cache

πŸ“Š Market Data

User
 β†’ UI
   β†’ DataService
     β†’ KiteClient
       β†’ Zerodha API

πŸ‘€ Profile & Funds

User
 β†’ UI (profile.py)
   β†’ ProfileService
     β†’ KiteClient

⭐ Favorites

User
 β†’ UI (saved.py)
   β†’ FavService
     β†’ favorites.json

🎯 Why This Design Is Strong

  • Clean separation of concerns

  • Scalable to multi-broker support

  • Interview-grade architecture

  • Easy migration to:

    • WebSockets
    • Databases
    • Algo-trading engines
  • Open-source contributor friendly


πŸš€ Future Architecture Extensions

  • WebSocket live ticks
  • Redis instrument cache
  • Backtesting engine
  • Strategy execution engine
  • Cloud deployment (Docker)

About

This application uses a layered architecture where Streamlit handles UI, services manage business logic, and a singleton Kite client communicates with Zerodha APIs. Instrument caching improves performance, and local storage manages favorites. The design is scalable, clean, and easy to extend.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages