Task Scheduling
The system is designed to operate as a continuous monitoring engine, automating the flow from data collection to multi-agent analysis and trade execution. Task scheduling ensures that your trading strategy remains responsive to market volatility and new information without manual intervention.
Automated Monitoring Workflows
The system automates the decision-making pipeline by orchestrating two primary cycles: Data Acquisition and Agent Analysis.
Data Acquisition Cycle
The system leverages the NewsAPIConnector and various market data tools to refresh the context used by agents. For optimal performance, the following data refresh frequencies are recommended:
- Market Price Data: Every 1–5 minutes (handled via the Technical Agent tools).
- Sentiment/News Data: Every 15–30 minutes (handled via
NewsAPIConnector). - On-Chain/Fundamental Data: Every 4–24 hours.
Periodic Trading Analysis
The TradingOrchestrator serves as the entry point for automated runs. When triggered, it executes the full multi-phase analysis (Phase 1: Analysis, Phase 2: Conflict Check, Phase 3: Debate, Phase 4: Final Decision).
To run a scheduled analysis, you can wrap the orchestrator in a periodic task:
from orchestrator import TradingOrchestrator
import time
def run_scheduled_trade():
orchestrator = TradingOrchestrator(backend="ollama")
# Define your recurring query or automated context fetcher
query = "Analyze current BTC market conditions and news sentiment for potential trades."
# Execute full analysis with debate enabled
result = orchestrator.analyze(query, enable_debate=True)
# The orchestrator handles logging to the database automatically
orchestrator.print_final_decision(result)
# Example of a simple loop (for development)
while True:
run_scheduled_trade()
time.sleep(3600) # Run every hour
Deployment and Automation Options
Depending on your environment, you can schedule the trading system using standard automation tools.
1. Crontab (Linux/macOS)
The most reliable way to schedule periodic runs is via cron. This ensures the system runs at specific intervals and can be easily managed at the OS level.
To run an analysis every 30 minutes, add the following to your crontab (crontab -e):
*/30 * * * * /usr/bin/python3 /path/to/project/main_orchestration_script.py >> /path/to/project/logs/cron.log 2>&1
2. Internal Background Tasks (FastAPI)
The dashboard backend (dashboard/backend/main.py) can be extended to handle scheduling internally using FastAPI's background tasks or a library like APScheduler. This allows the system to push real-time updates to the dashboard via WebSockets immediately after an automated analysis completes.
3. Docker Compose
If running in a containerized environment, you can use a separate "worker" container that executes the orchestration logic on a loop or via an internal scheduler, sharing the same database and Redis instance as the Dashboard API.
Real-time Dashboard Updates
The task scheduler is tightly integrated with the system's WebSocket architecture. Whenever a scheduled task results in a trade or a significant change in recommendation:
- The
TradingOrchestratorcommits the results to the database. - The Backend API broadcasts a message via the
/wsendpoint. - The React Frontend automatically refreshes the Trade Table and Equity Curve components to reflect the latest automated decision.
This ensures that while the system runs autonomously in the background, you maintain full visibility into its operations through the live dashboard.