Requirement Specification Document Project Title: Automated ORB Breakout Trading with Webull via TradingView 1. Objective Build an automated trading system that executes trades on Webull based on signals generated from a TradingView strategy/indicator. 2. System Overview * TradingView (Frontend Signal Source): o Pine Script strategy will generate buy/sell signals based on ORB breakout logic with Kalman filter confirmation. o Signals will be sent via webhooks. * Middleware (Integration Layer): o A Python (preferred) or Node.js server will listen to TradingView webhook alerts. o The server will parse JSON payloads and place trades through the Webull API. * Broker (Execution Platform): o All trades are executed on Webull brokerage account. o Both stock and option orders should be supported (phase 2). 3. Functional Requirements 3.1 TradingView Strategy / Indicator * Detect ORB breakout (first 5 min range). * Confirmation via Kalman filters (2 EMAs approximation). * Trading rules: o Buy 2 shares/contracts on breakout. o Scale out: * Exit 1 unit at PT1 ($X profit). * Exit 2nd unit at PT2 ($Y profit). o Stop Loss = ORB mid-level. o Forced exit of open position at 2:57 PM. * Generate alerts: o BUY signal o SELL signal o EXIT signal (when TP/SL or time exit occurs) * Each alert should include structured JSON: * { * "signal": "BUY", * "ticker": "{{ticker}}", * "qty": 2, * "strategy": "ORB_Kalman", * "timestamp": "{{timenow}}" * } 3.2 Middleware / Bridge * Technology: Python (Flask/FastAPI) or Node.js (Express). * Endpoints: o /webhook ? POST endpoint to receive TradingView alerts. * Functions: o Parse incoming JSON. o Authenticate with Webull API. o Place orders: * Market Buy/Sell * Stop Loss order at ORB midpoint * Profit Target orders (bracket orders if possible) o Log all requests/responses (for debugging). o Handle errors & retries (e.g., failed API call). 3.3 Webull API Integration * Use unofficial Webull Python SDK (https://pypi.org/project/webull/). * Requirements: o Login & session refresh (MFA handling must be considered). o Place stock orders (BUY / SELL) with specified quantity. o Phase 2: Support option orders (needs contract ID lookup). 4. Non-Functional Requirements * Security: o No credentials hardcoded; must use environment variables or config file. o HTTPS webhook endpoint (via ngrok or hosted server). * Scalability: Should handle at least 10 alerts per minute. * Reliability: Must ensure trades are executed only once per signal (idempotency). * Logging: Save all alerts + execution status into log file or DB. 5. Deliverables 1. Pine Script strategy with alertconditions. 2. Python/Node.js middleware: o Webhook listener o Webull trade executor o Logging system 3. Documentation: o How to deploy middleware (local + ngrok / cloud VPS) o How to configure TradingView alerts o How to test trades with paper trading before going live 6. Future Enhancements (Phase 2) * Options trading (nearest Friday expiry selection logic). * Telegram/Slack notifications for each trade. * Multi-account support. * Dashboard to monitor trades.