38 - Python Strategies Hosting
Overview
Architecture Diagram
┌──────────────────────────────────────────────────────────────────────────────┐
│ Python Strategy Hosting Architecture │
└──────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────┐
│ Web Interface (/python) │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Upload │ │ Start │ │ Schedule │ │ Delete │ │
│ │ Strategy │ │ Strategy │ │ Strategy │ │ Strategy │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │ │ │
└─────────┴────────────────┴────────────────┴────────────────┴────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Strategy Management Layer │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ RUNNING_STRATEGIES = {} # {strategy_id: {'process', 'started'}} │ │
│ │ STRATEGY_CONFIGS = {} # {strategy_id: config_dict} │ │
│ │ SCHEDULER (APScheduler) # Background job scheduler │ │
│ │ PROCESS_LOCK # Thread-safe process operations │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Process Isolation Layer │
│ │
│ ┌────────────────┐ ┌────────────────┐ ┌────────────────┐ │
│ │ Strategy 1 │ │ Strategy 2 │ │ Strategy 3 │ ... │
│ │ (subprocess) │ │ (subprocess) │ │ (subprocess) │ │
│ │ │ │ │ │ │ │
│ │ - Own PID │ │ - Own PID │ │ - Own PID │ │
│ │ - Own memory │ │ - Own memory │ │ - Own memory │ │
│ │ - Own stdout │ │ - Own stdout │ │ - Own stdout │ │
│ │ - Own stderr │ │ - Own stderr │ │ - Own stderr │ │
│ └────────────────┘ └────────────────┘ └────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ File System │
│ │
│ strategies/ │
│ ├── scripts/ # Strategy Python files │
│ │ ├── strategy_1.py │
│ │ ├── strategy_2.py │
│ │ └── ... │
│ └── strategy_configs.json # Persistent configuration │
│ │
│ log/ │
│ └── strategies/ # Strategy output logs │
│ ├── strategy_1.log │
│ ├── strategy_2.log │
│ └── ... │
└─────────────────────────────────────────────────────────────────────────────┘Directory Structure
Key Features
Process Isolation
Cross-Platform Support
Platform
Support
Notes
Strategy Lifecycle
Scheduling with APScheduler
Scheduler Configuration
Schedule Options
Schedule Type
Description
Example
Market-Aware Scheduling
User Ownership & Security
Strategy Ownership Verification
Security Features
Feature
Implementation
Server-Sent Events (SSE)
API Endpoints
Endpoint
Method
Description
Configuration Persistence
Operational Guidelines
Best Practices
Example Strategy Template
Log Monitoring
Resource Configuration
Memory Limits
Container RAM
Recommended Limit
Max Concurrent Strategies
Thread Limiting for Docker
Variable
Purpose
Key Files Reference
File
Purpose
Last updated