39 - Strategy Module
Overview
Architecture Diagram
┌──────────────────────────────────────────────────────────────────────────────┐
│ Strategy Module Architecture │
└──────────────────────────────────────────────────────────────────────────────┘
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ TradingView │ │ Amibroker │ │ ChartInk │
│ Webhook │ │ Webhook │ │ Webhook │
└────────┬────────┘ └────────┬────────┘ └────────┬────────┘
│ │ │
└────────────────────┼────────────────────┘
│
▼
┌──────────────────────────────────────────────────────────────────────────────┐
│ Strategy Webhook Endpoint │
│ POST /strategy/webhook/<webhook_id> │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ 1. Rate Limiting (100/min for webhooks) │ │
│ │ 2. Validate webhook_id → Get strategy │ │
│ │ 3. Check strategy enabled & time window │ │
│ │ 4. Parse signal (action, symbol, quantity) │ │
│ │ 5. Apply symbol mapping overrides │ │
│ │ 6. Queue order for execution │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────────────────────────────────┐
│ Order Queueing System │
│ │
│ ┌──────────────────────┐ ┌──────────────────────┐ │
│ │ Regular Queue │ │ Smart Order Queue │ │
│ │ (placeorder) │ │ (placesmartorder) │ │
│ │ │ │ │ │
│ │ Rate: 10/sec │ │ Rate: 1/sec │ │
│ │ (ORDER_RATE_LIMIT) │ │ (SMART_ORDER_RATE) │ │
│ └──────────┬───────────┘ └──────────┬───────────┘ │
│ │ │ │
│ └───────────────┬───────────────┘ │
│ │ │
│ ▼ │
│ ┌────────────────┐ │
│ │ Order Processor │ │
│ │ (Background) │ │
│ └────────┬───────┘ │
│ │ │
└─────────────────────────────┼───────────────────────────────────────────────┘
│
▼
┌────────────────┐
│ REST API │
│ /api/v1/... │
└────────────────┘Strategy Configuration
Database Schema
Time Validation
Webhook Signal Format
TradingView Format
Amibroker Format
Supported Actions
Action
Description
Symbol Mapping
Order Queuing System
Dual Queue Architecture
Rate Limiting
Order Type
Rate Limit
Queue
Automatic Square-Off
APScheduler Integration
Square-Off Logic
API Endpoints
Endpoint
Method
Description
Trading Modes
Mode
Allowed Actions
Use Case
Strategy Time Window
Configuration
Environment Variables
Key Files Reference
File
Purpose
Last updated