Implementation:HKUDS AI Trader Main Parallel
| Knowledge Sources | |
|---|---|
| Domains | Concurrency, Backtesting |
| Last Updated | 2026-02-09 14:00 GMT |
Overview
Concrete tool for running multiple LLM trading agents in parallel subprocesses using asyncio.
Description
The main_parrallel.py module provides three key functions: main() loads config and orchestrates execution, _spawn_model_subprocesses() creates one asyncio subprocess per enabled model, and _run_model_in_current_process() handles single-model execution. The parallel runner uses asyncio.create_subprocess_exec() to spawn isolated Python processes, each re-invoking main_parrallel.py with a --signature flag.
Usage
Run from command line: python main_parrallel.py [--config path] to launch all enabled models in parallel. For programmatic use, call await main(config_path).
Code Reference
Source Location
- Repository: AI-Trader
- File: main_parrallel.py
- Lines: L191-263 (main), L171-188 (_spawn_model_subprocesses), L100-168 (_run_model_in_current_process)
Signature
async def main(config_path=None, only_signature: str | None = None):
"""
Main entry point for parallel agent execution.
Args:
config_path: Path to JSON config (default: configs/default_config.json)
only_signature: If set, only run the model with this signature
Returns:
None. Each agent writes its own position.jsonl and logs.
"""
async def _spawn_model_subprocesses(config_path, enabled_models):
"""Spawn one subprocess per enabled model and wait for all to complete."""
async def _run_model_in_current_process(AgentClass, model_config, INIT_DATE, END_DATE, agent_config, log_config):
"""Run a single model in the current process (no subprocess)."""
Import
# CLI usage:
# python main_parrallel.py --config configs/default_config.json
# Programmatic:
from main_parrallel import main
import asyncio
asyncio.run(main("configs/default_config.json"))
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config_path | Optional[str] | No | Path to config JSON (default: configs/default_config.json) |
| only_signature | Optional[str] | No | Single-model filter (used by subprocess mode) |
| INIT_DATE | str (env) | No | Override start date |
| END_DATE | str (env) | No | Override end date |
Outputs
| Name | Type | Description |
|---|---|---|
| position.jsonl | File (per agent) | Each agent writes its own position log |
| log/ | Directory (per agent) | Each agent writes its own conversation logs |
Usage Examples
Run All Enabled Models
import asyncio
from main_parrallel import main
# Run all enabled models from default config in parallel
asyncio.run(main())
From Shell
# Run with default config
python main_parrallel.py
# Run with custom config
python main_parrallel.py --config configs/astock_config.json