All long-running compute operations in the Hedge Fund Backend — model training, hyperparameter tuning, feature generation, backtest execution, parameter sweeps, signal generation, walk-forward validation, and CPCV validation — can be dispatched to the Celery worker pool. When dispatched asynchronously the API returns immediately with aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/najmulhossainnj/Hedge-fund-backend/llms.txt
Use this file to discover all available pages before exploring further.
task_id; the client then polls a lightweight status endpoint until the task completes. This design keeps the FastAPI event loop free for interactive requests while expensive CPU/GPU work runs in isolated worker processes.
Available Async Endpoints
Every compute-heavy domain exposes a dedicated async route alongside its synchronous counterpart:| Endpoint | Celery task name | Description |
|---|---|---|
POST /api/v1/models/{id}/train/async | training.train_model | Train a registered ML model on assembled feature data |
POST /api/v1/models/tune/async | training.tune_model | Run an Optuna hyperparameter search over a defined parameter space |
POST /api/v1/features/{id}/generate | features.generate | Compute and persist a feature dataset for a symbol/timeframe window |
POST /api/v1/backtests/{id}/execute/async | backtests.execute | Execute a single backtest run against vectorbt or Backtrader |
POST /api/v1/backtests/sweep | backtests.sweep | Run a parameter grid sweep and return a ranked leaderboard |
POST /api/v1/signals/generate/async | signals.generate | Generate trade signals from a trained model over a date range |
POST /api/v1/validation/walk-forward/async | validation.walk_forward | Walk-forward validation with configurable rolling/expanding splits |
POST /api/v1/validation/cpcv/async | validation.cpcv | Combinatorially Purged Cross-Validation (CPCV) with PBO and deflated Sharpe |
Polling Task Status
UseGET /api/v1/tasks/{task_id} to check progress. The response shape varies by state:
- PENDING
- STARTED
- SUCCESS
- FAILURE
Celery Worker Setup
Workers require the same
requirements.txt as the API server. In Docker this is handled automatically by Dockerfile.worker. For local development:The worker will connect to
CELERY_BROKER_URL and begin consuming tasks from all registered modules.Worker Configuration
The Celery application is configured inapp/workers/celery_app.py:
task_acks_late=True— the task message is acknowledged only after the task finishes, preventing data loss if a worker crashes mid-execution.worker_prefetch_multiplier=1— each worker process holds at most one task at a time, preventing memory exhaustion on large training jobs.task_track_started=True— enables theSTARTEDstate so polling clients can distinguish “queued” from “running”.
Available Task Modules
| Module | Task names registered |
|---|---|
app.workers.training_tasks | training.train_model, training.tune_model |
app.workers.feature_tasks | features.generate |
app.workers.backtest_tasks | backtests.execute |
app.workers.signal_tasks | signals.generate |
app.workers.validation_tasks | validation.walk_forward, validation.cpcv |
app.workers.sweep_tasks | backtests.sweep |