Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

πŸ“Š Upstox Analytics β€” AI-Powered SMC Market Analysis Platform

Python Docker DeepSeek Upstox

A multi-market, multi-strategy terminal-based trading analysis platform that fuses institutional Smart Money Concepts (SMC) with DeepSeek AI to generate high-confidence trade signals across Indian equities, crypto, and forex β€” all from a single CLI command.


🧠 What Problem Does This Solve?

Retail traders rely on lagging indicators (RSI, MACD, moving averages) that institutions exploit as liquidity traps. This platform shifts the paradigm by implementing the "Guardeeer SMC Last Defense Liquidity Model" β€” a professional institutional framework that tracks where smart money is accumulating and where retail stops are being hunted, giving the user the same structural edge that institutions use.


πŸ“ˆ Core Metrics & Signals

πŸ”’ Technical Indicators (Traditional Engine)

Metric Description Default
RSI (14) Relative Strength Index β€” overbought > 70, oversold < 30 14-period
EMA Short (9) Fast exponential moving average for crossover detection 9-period
EMA Long (21) Slow exponential moving average for trend confirmation 21-period
Trend Strength Composite score (1–10) based on EMA crossover, RSI, and price position Dynamic
Support Levels Pivot-point and rolling-swing derived price floors Top 3 levels
Resistance Levels Pivot-point and rolling-swing derived price ceilings Top 3 levels
Confidence Bar Visual 10-segment bar (β–“β–“β–“β–“β–“β–‘β–‘β–‘β–‘β–‘) per signal 1–10

πŸ›οΈ SMC (Smart Money Concepts) Engine β€” Guardeer's Framework

SMC Metric Description
Swing Highs / Swing Lows Candles with higher/lower extremes than 2 neighbors on each side
ITH (Institutional Term High) Most recent untaken major swing high
ITL (Institutional Term Low) Most recent untaken major swing low
Order Blocks (OB) Last opposing candle before a 3+ candle directional impulse β€” unmitigated only
Fair Value Gaps (FVG) 3-candle patterns where wicks don't overlap β€” institutional imbalance zones
Liquidity Sweep Price breaks a swing high/low then closes back inside β€” stop-loss hunt detected
POI (Point of Interest) Confluence of unmitigated OB + overlapping FVG on the structural leg
Market Structure Bullish (HH/HL) or Bearish (LH/LL) determined by sequential swing points
Risk-Reward Ratio (R:R) Minimum 2:1 filter β€” calculated from OB entry to opposing structural target
OB Midpoint Entry Precision entry at 50% of the Order Block zone
Buffer-Based Stop Loss Structural invalidation Β± 0.5% buffer on OB boundary

πŸ’° Options Metrics

Metric Description
Put-Call Ratio (PCR) Total Put OI Γ· Total Call OI β€” sentiment gauge
OTM % Distance of strike from underlying price in percentage
Option Premium Live last-traded price for each strike
Open Interest (OI) Number of outstanding contracts per strike
Call Writing Opportunities Top 5 OTM calls ranked by premium
Put Writing Opportunities Top 5 OTM puts ranked by premium

🎯 Impact: How This Application Creates Real Trading Edge

1. Eliminates Emotional & Lagging-Indicator Trading

Instead of relying on RSI crossovers that fire after the move, the SMC engine detects institutional accumulation zones before price explodes. The rule-based signal engine removes human bias β€” every BUY/SELL has a defined entry, stop, target, confidence score, and rationale.

2. Identifies "Stop-Hunt" Liquidity Traps

The liquidity sweep detector identifies when price intentionally pierces a swing high/low to trigger retail stop-losses, then reverses β€” a classic institutional footprint. The platform flags these sweeps and waits for the 1H "last defense" Order Block before generating an entry, ensuring the user piggybacks the smart money reversal, not the fake-out.

3. Multi-Market, Single Interface

Built for traders operating across asset classes:

  • Indian Stocks β†’ Upstox API (NSE/BSE) with OAuth 2.0 full access
  • Crypto β†’ Binance public API (BTC, ETH, and all USDT pairs)
  • Forex β†’ Yahoo Finance fallback

No need to switch between 3 different platforms. One CLI command covers all.

4. AI-Augmented Decision Confidence

DeepSeek AI analyzes the complete technical picture (trend, RSI, support/resistance, options chain, PCR) and outputs a structured 5-section trading recommendation:

  1. πŸ“Š Market Overview
  2. πŸ“ˆ Technical Analysis
  3. πŸ’° Options Strategy (specific strikes)
  4. ⚑ Action Plan with confidence levels
  5. πŸ›‘οΈ Risk Management (stop loss, position sizing)

5. Options Selling Strategy Automation

The platform automatically identifies the best OTM call/put writing opportunities by analyzing the live option chain for premium-to-distance ratios. It ranks strikes by premium yield while filtering out deep ITM noise β€” turning complex options data into actionable SELL_CALL / SELL_PUT signals.

6. Dockerized Deployment Ready

A single docker build && docker run deploys the entire platform anywhere β€” cloud VMs, on-prem servers, or CI/CD pipelines. Non-root user execution and multi-stage builds ensure security and minimal image size.


πŸ—οΈ Architecture

                                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                 β”‚            User (CLI)               β”‚
                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                β”‚
                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚      main.py           β”‚
                                    β”‚  (Rich CLI + Argparse)  β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                β”‚
               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
               β”‚                                β”‚                                β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚   DecisionEngine     β”‚          β”‚  TechnicalAnalyzer β”‚          β”‚      AIAdvisor         β”‚
    β”‚  (Signal Generator)  β”‚          β”‚  (S/R, EMA, RSI)   β”‚          β”‚   (DeepSeek API)       β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚                                β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚   smc_strategy.py    β”‚          β”‚   data_fetcher.py  β”‚
    β”‚  (OB, FVG, Sweeps,   β”‚          β”‚  (Upstox API v2)   β”‚
    β”‚   ITH/ITL Detection) β”‚          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  crypto_fetcher.py   β”‚
    β”‚  (Binance API)       β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

File Structure

upstox-analytics/
β”œβ”€β”€ main.py               # CLI entry point + interactive shell
β”œβ”€β”€ config.py             # Environment config + token management
β”œβ”€β”€ data_fetcher.py       # Upstox API v2 (historical, quotes, options)
β”œβ”€β”€ crypto_fetcher.py     # Binance public API (crypto OHLCV)
β”œβ”€β”€ analyzer.py           # Traditional TA (S/R, EMA, RSI, options)
β”œβ”€β”€ smc_strategy.py       # SMC engine (OB, FVG, sweeps, ITH/ITL)
β”œβ”€β”€ ai_advisor.py         # DeepSeek AI chat completions
β”œβ”€β”€ decision.py           # Unified signal generator (SMC + default)
β”œβ”€β”€ requirements.txt      # Python dependencies
β”œβ”€β”€ Dockerfile            # Multi-stage container build
β”œβ”€β”€ .env                  # API keys (gitignored)
β”œβ”€β”€ strategy1.txt         # Guardeer 4H-1H OB Sweep Strategy
β”œβ”€β”€ strategy2.txt         # Guardeer "Last Defense" Liquidity Model
└── SMC_Three_Strategies_System.txt  # 3-strategy complete system

πŸ”¬ The Tech Stack Uniqueness

1. Dual-Engine Architecture with Runtime Strategy Switching

Unlike most trading bots that use a single strategy, this platform implements two independent signal engines that can be toggled at runtime:

  • --default flag β†’ Traditional RSI/EMA engine
  • Default mode β†’ SMC institutional engine

Both engines feed into the same DecisionEngine β†’ TradingSignal pipeline, allowing direct A/B comparison of strategy performance.

2. SMC Engine Built from Original Guardeer Methodology

The SMC implementation is not a generic "ICT concepts" wrapper. It faithfully implements the specific Guardeer 4H-1H Institutional Order Block Sweep Strategy documented in strategy1.txt and strategy2.txt:

  • True 2-candle-side swing point detection (not just fractals)
  • Untaken ITH/ITL tracking β€” an ITH is only valid if no subsequent candle's high exceeded it
  • Impulse-based Order Block identification β€” requires 3+ consecutive directional candles before the opposing OB qualifies
  • Liquidity sweep confirmation β€” price must break the swing level AND close back inside
  • OB midpoint entries β€” precision execution at 50% of the zone
  • Buffer-based structural stops β€” Β±0.5% on OB boundaries, not arbitrary ATR multiples

3. Multi-Source Data Fetcher with Intelligent Fallback

The data pipeline is resilient by design:

Upstox OAuth Token (full access)
        β”‚
        β–Ό
   Upstox API v2 ←── Primary source (stocks, indices, options)
        β”‚
        β”‚ Failure?
        β–Ό
  Yahoo Finance   ←── Fallback (no auth, always available)

For crypto, Binance's public API is used directly β€” no API key needed. This architecture ensures the platform never fails due to a single API outage or rate limit.

4. In-Memory Caching Layer with Per-Endpoint TTLs

Every API call is wrapped in a caching layer with endpoint-specific expiry:

  • Candle data: 60s cache (rate-limit protection)
  • Options chain: 30s cache
  • Live quotes: 5s cache
  • Crypto prices: 10s cache

This prevents redundant API calls when analyzing the same symbol in quick succession and respects the Upstox rate limits.

5. DeepSeek AI Integration β€” Not Just a Chatbot

The AI advisor is integrated as a structured analysis layer, not a generic chat interface:

  • System prompt enforces a 5-section structured output (Overview β†’ TA β†’ Options β†’ Action β†’ Risk)
  • Prompt builder programmatically constructs the analysis context from all computed metrics
  • Temperature is set to 0.7 for balanced creativity vs. factual precision
  • 30-second timeout with graceful degradation (shows error panel, does not crash)

6. OAuth 2.0 Auto-Login Flow

The --login command spins up a temporary HTTP server on localhost:8080, opens the browser for Upstox authorization, captures the OAuth code, exchanges it for an access token, and writes it to .env β€” all automated. No manual copy-paste of tokens.

7. Rich Terminal UI with Visual Confidence Bars

Signals are rendered with:

  • Color-coded tables (green=BUY, red=SELL, yellow=HOLD)
  • Confidence bars using block characters (β–“β–“β–“β–“β–“β–“β–“β–‘β–‘β–‘ for 7/10)
  • Nested panels for AI advice
  • Real-time progress spinners during analysis

8. Docker Multi-Stage Build with Non-Root User

The Dockerfile uses a builder stage for dependency installation (cache-friendly) and a slim runtime stage with:

  • Dedicated analyst user (UID 1001) β€” no root execution
  • PYTHONUNBUFFERED=1 for real-time log output
  • No build tools in the final image (minimal attack surface)

πŸš€ Quick Start

Prerequisites

Installation

# Clone the repository
git clone https://github.com/Aditya365x/stockAnalyser.git
cd stockAnalyser

# Install dependencies
pip install -r requirements.txt

# Configure API keys
cp .env.example .env
# Edit .env with your keys:
#   UPSTOX_ANALYTICS_TOKEN=your-token
#   DEEPSEEK_API_KEY=your-deepseek-key

OAuth Login (Full Stock Access)

python main.py --login
# Opens browser β†’ login to Upstox β†’ token auto-saved to .env

Basic Usage

# Analyze a stock with SMC strategy
python main.py RELIANCE

# Analyze with options chain
python main.py RELIANCE --options

# Analyze crypto (Binance)
python main.py BTCUSDT --crypto

# Analyze forex (Yahoo Finance)
python main.py EURUSD --forex

# Use traditional RSI/EMA strategy instead of SMC
python main.py RELIANCE --default

# Skip AI analysis (offline mode)
python main.py RELIANCE --no-ai

# Interactive shell mode
python main.py
> RELIANCE
> crypto ETHUSDT
> forex GBPUSD
> quit

Docker Deployment

# Build the image
docker build -t upstox-analytics .

# Run with your .env file
docker run --rm -it --env-file .env upstox-analytics RELIANCE

# Interactive mode
docker run --rm -it --env-file .env upstox-analytics

πŸ“Š Example Output

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Market Analysis                                   β”‚
β”‚ RELIANCE - β‚Ή2,847.30                             β”‚
β”‚ Analyzed: 2026-05-29 19:12:30                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Technical Indicators                    β”‚
β”‚ Indicator   β”‚ Value                     β”‚
β”‚ Trend       β”‚ BULLISH                   β”‚
β”‚ Strength    β”‚ 7/10                      β”‚
β”‚ RSI         β”‚ 56.32                     β”‚
β”‚ EMA Short   β”‚ β‚Ή2,834.50                 β”‚
β”‚ EMA Long    β”‚ β‚Ή2,812.10                 β”‚
β”‚ Signals     β”‚ ABOVE_LONG_EMA            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Trading Signals                               β”‚
β”‚ Signal β”‚ Confidence β”‚ Entry    β”‚ Target  β”‚ SL β”‚
β”‚ BUY    β”‚ 7/10       β”‚ 2847.30 β”‚ 2910.00 β”‚ .. β”‚
β”‚        β”‚ β–“β–“β–“β–“β–“β–“β–“β–‘β–‘β–‘ β”‚         β”‚         β”‚    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
BUY: Bullish structure (HH/HL) | Swept level: 2812.5

β”Œβ”€ DeepSeek Analysis ────────────────────────────┐
β”‚ πŸ“Š Market Overview: RELIANCE shows bullish     β”‚
β”‚ momentum with price above both EMAs...         β”‚
β”‚                                                β”‚
β”‚ πŸ“ˆ Technical Analysis: Strong uptrend with     β”‚
β”‚ RSI at 56 showing room to run...               β”‚
β”‚                                                β”‚
β”‚ πŸ’° Options Strategy: Sell 2950 CE at β‚Ή18.50    β”‚
β”‚ (3.6% OTM, good risk-reward)...                β”‚
β”‚                                                β”‚
β”‚ ⚑ Action Plan: BUY with 7/10 confidence.      β”‚
β”‚ Entry at CMP β‚Ή2847, target β‚Ή2910...            β”‚
β”‚                                                β”‚
β”‚ πŸ›‘οΈ Risk Management: Stop loss at β‚Ή2810...      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”’ Security

  • All API keys stored in .env (gitignored)
  • Docker runs as non-root analyst user (UID 1001)
  • OAuth tokens are never committed β€” auto-generated via --login
  • Cached API responses are in-memory only (no disk persistence)
  • PYTHONUNBUFFERED=1 ensures logs are not buffered in container environments

⚠️ Disclaimer

This tool is for educational and informational purposes only. It does not constitute financial advice. Trading stocks, options, crypto, and forex involves substantial risk of loss. Past performance is not indicative of future results. Always conduct your own research and consult a licensed financial advisor before making trading decisions.


πŸ“œ License

MIT License β€” See LICENSE file for details.


πŸ™ Credits


Built with ❀️ for traders who think like institutions, not retail.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages