System Architecture Wireframe
High-level view of NiftyBot components and trading flow.
High-Level Architecture
graph TD
subgraph External APIs
UPSTOX[Upstox API REST & WS]
TG[Telegram API]
end
subgraph Data Layer
DB[(PostgreSQL Database)]
Cache[Live OHLC Cache]
end
subgraph Core Services
MC[Main App / FastAPI]
TC[Trading Controller]
SF[Strategy Feedback Loop]
MD[Market Data Service]
PB[Paper Broker]
end
subgraph Strategy Engine
SE[Signal Engine]
Renko[Renko Builder]
Ind[Indicators & Patterns]
Risk[Risk Manager]
end
subgraph Web / UI
API[FastAPI Routes]
WS[WebSocket Manager]
OBS[System Observability UI]
end
UPSTOX -- Market Data / Orders --> MD
UPSTOX -- Market Data / Orders --> TC
TC -- Send Alerts --> TG
TG -- Commands --> TC
MC --> TC
MC --> SF
TC -- Requests signals --> SE
SE --> Renko
SE --> Ind
SE --> Risk
TC -- Execute Live --> UPSTOX
TC -- Execute Paper --> PB
TC -- Read/Write State --> DB
SF -- Fetch History / Tune --> DB
MC -. System Log Stream .-> OBS
DB -. Code Memory Files .-> OBS
Core Trading Loop Workflow
sequenceDiagram
participant Loop as Main Trading Loop
participant TC as Trading Controller
participant SE as Signal Engine
participant MD as Market Data
participant DB as PostgreSQL
participant TG as Telegram Bot
Loop->>TC: monitor_open_positions()
Note over TC: Check Spot SL, Premium SL, T1 (Partial Book) and EMA Trail
Loop->>TC: check_time_stops()
Note over TC: Check if 45 mins passed or 3:00 PM Hard Exit
Loop->>TC: evaluate_and_trade()
TC->>MD: Fetch VIX, OHLC, Option Chain
TC->>SE: Evaluate (OHLC, Renko, VIX, PCR)
SE-->>TC: Returns SignalResult (Buy CE/PE or NO TRADE)
alt Signal == Valid Trade
TC->>TC: Compute Adaptive Risk (Lot Size)
TC->>DB: Save Trade to Database
TC->>TG: Send Telegram Alert (Autonomous Trade Executed)
else Signal == NO TRADE
TC->>TC: Update last_activity = "Monitoring..."
end