Scalping System for NSE Instruments

Job ID: 39760123

Budget: ₹100,000 – ₹120,000 INR

Advanced Zerodha-Compliant Scalper Algo (Auto / Semi-Auto)
1) Goals & Scope

Goal: Build a low-latency scalping system for NSE instruments (cash &/or futures) that executes automated or semi-automated entries/exits on 1-second to 1-minute horizons with strict risk, audit, and broker/exchange compliance.

Primary broker: Zerodha (Kite Connect).

Operating mode: Configurable — Auto, One-click (semi-auto), Paper, Backtest.

Non-goals: UI-heavy charting platform; discretionary long-term investment tooling.

2) Compliance & Risk (Hard Requirements)

Regulatory alignment: System must be designed to align with SEBI / Exchange norms and Zerodha’s policies on automation (incl. strategy “tagging”, logs, user consent, order markings). If fully-auto requires broker approval, incorporate the process & fallback to semi-auto mode.

Risk controls (pre-trade & intra-day):

Hard daily risk: Max daily loss, max drawdown, max trades, max open positions, cool-down after loss streak.

Per-trade: max % of capital at risk, ATR/volatility-aware stops, price band / circuit checks, market status checks (pre-open/auction/ban).

Kill-switch & auto-flatten on breach or connectivity failure.

Order hygiene & idempotency: Unique client order IDs, replay protection, exactly-once semantics on retries.

Audit & traceability: Immutable logs for signal → decision → order → fill, with timestamps, parameters, data snapshot hashes, P&L impact; exportable for audit.

PII & security: Secrets vault, token rotation, 2FA flow handling, encrypted at rest & in transit.

Rate limits & fairness: Respect Kite Connect QPS; backoff + jitter; queueing & throttling.

3) Strategy Engine (Baseline Spec)

Timeframes: 1s/3s/5s/15s/30s/1m configurable; multi-TF confirmation.

Signal stack (enable/disable + weights):

Trend & mean-reversion: EMA ribbon / HMA, VWAP & VWAP deviation, Bollinger, Keltner, Supertrend.

Momentum & exhaustion: RSI (classic + MFI), Stoch RSI, ROC, CCI, MACD, ADX.

Volatility & risk: ATR bands, True Range expansion, Gap filters.

Microstructure (if data available): Order book imbalance, best-bid/ask pressure, volume spike, tick delta.

Regime filter: Volatility/Trend regime (e.g., ADX/ATR & slope filters), news/market-wide halt filter.

Entry logic: Score-based (weighted signals > threshold), OR rule-based (e.g., pullback to VWAP + RSI reset + rising delta).

Exit logic: Layered exits — partial TP (R multiples), time-based exit, trailing stop (ATR), break-even move, opposite signal flip, volatility squeeze release.

Position sizing: Volatility-adjusted fixed-fraction, capped Kelly fraction, or unit-risk model (₹ risk per trade); include transaction costs & slippage.

Symbol universe: Configurable whitelist (e.g., highly liquid NIFTY100 stocks, FINNIFTY/BANKNIFTY futures); automatic exclusion of ban or low-liquidity names.

4) Execution Layer

Market data: Kite Ticker WebSocket; resilient reconnect, gap fill, clock sync (NTP), snapshot vs stream reconciliation.

Order types: Limit/Market, IOC, SL/SL-M, trailing SL emulation; iceberg/disclosed qty support where applicable.

Smart execution:

Slippage guard (limit price bands), last-trade vs best-bid/ask checks, partial fills handling.

Retry policy with idempotency, throttle, and state machine (Created → Acknowledged → Working → Filled/Cancelled/Rejected).

Portfolio sync: Real-time positions, margins, and P&L reconciliation with broker.

5) Architecture & Tech

Services:

Data Ingestor (WebSocket + persistence)

Strategy Engine (deterministic compute; plug-in strategies)

Execution Gateway (orders, risk, idempotency)

Risk Guardian (global checks, kill-switch)

Backtest/Simulator (event-driven; same codepath)

Paper Trading (live tick + simulated fills)

Monitoring & Alerting (latency, fills, drawdown, errors)

APIs & Minimal UI (config, status, overrides)

Suggested stack:

Python (core engine: numpy/pandas/numba), FastAPI for control plane

Go or Node.js optional for execution gateway (low-latency)

Redis (caches, queues), Postgres/TimescaleDB (events, ticks, logs)

Docker + IaC (Terraform), AWS/GCP (but single-tenant option on your server)

Non-functional:

Latency budget (tick→order): ≤ 50–150 ms target on coloc/nearest region; < 400 ms over public internet.

Uptime 99.5% trading hours; RTO ≤ 2 min; RPO ≤ 1 sec for decisions.

Test coverage ≥ 80% strategy logic; load tests for bursts (open/close).

6) Backtesting, Research & Robustness

Data model: Minute + tick (where lawful/available). Commission, fees, slippage model, latency model, price bands.

Walk-forward & OOS testing: Train/validate/test splits, rolling walk-forward, monte-carlo on trade sequence.

Parameter search: Grid/random/Bayesian with constraints to avoid overfit; report stability heatmaps.

Reports: Equity, drawdowns, heatmaps by hour/day, MAE/MFE, edge decay, regime performance, capacity.

Reproducibility: Seeded runs, config-as-code, versioned datasets, result artifacts.

7) Observability & Ops

Dashboards: Live P&L, exposure, win-rate, fills, rejects, slippage, latencies, health status.

Alerts: Drawdown breach, data disconnect, order rejects, CPU/mem spikes, strategy halt.

Runbooks: Recovery steps for broker disconnect, order stuck, time sync drift, API throttle, exchange outage.

Release flow: Dev → Paper → Small-risk Live → Scale; feature flags for strategies.

8) Deliverables

Architecture diagram + SRS (this doc refined)

Compliance checklist (broker/exchange), with automation mode toggles

Source code (modular), Docker, IaC

Test suite (unit/integration/simulation + load)

Backtest pack (data, configs, PDF report)

Ops pack (dashboards, alerts, runbooks)

Handover (deploy guide, env setup, credentials process)

9) Acceptance Criteria (Go/No-Go)

Strategy runs in Paper for 10 trading days with:

Max daily loss respected 100% of days

No duplicate or phantom orders (idempotency verified)

Live latency p95 within budget

Backtest vs paper P&L variance within agreed tolerance (after costs)

Audit log shows full trace for 100% of orders

Kill-switch tested and flattens in < 10 seconds

Developer Skill Set (Must-Haves)

Zerodha Kite Connect (REST & WebSocket), order lifecycle, rate limits, reconnection, historical data constraints.

Low-latency systems: async I/O, concurrency, state machines, idempotency, reliability under network jitter.

Quant/TA: indicator design, volatility modeling, slippage/cost models, event-driven sims.

Risk & compliance with Indian markets: price bands, auction sessions, OI/ban lists, RMS interactions.

Datastores & streaming: Postgres/Timescale, Redis, queues; schema design for ticks & events.

Testing & CI/CD: deterministic backtests, property-based tests, load tests.

Security: key management, secure auth flows, least-privilege infra, logging without leaking secrets.

Cloud & containers: Docker, Terraform, AWS/GCP; metrics/alerts (Prometheus/Grafana or similar).