Deployment Overview
The trading bot system supports two deployment approaches:
- Kubernetes with Helm (Production) - Deploys PostgreSQL and bots as CronJobs
- Local Development - Run PostgreSQL locally, execute bots manually
Deployment Options
Option 1: Kubernetes with Helm (Production)
Deploy the entire system to Kubernetes, including PostgreSQL and all trading bots as scheduled CronJobs.
Benefits: - Automated scheduling via Kubernetes CronJobs - PostgreSQL deployed in-cluster - Centralized configuration via Helm - Production-ready with resource limits and monitoring
Prerequisites:
- Kubernetes cluster (1.20+)
- kubectl configured
- Helm 3.x installed
Quick Deploy:
# 1. Create namespace
kubectl create namespace tradingbots-2025
# 2. Create secrets from .env file
kubectl create secret generic tradingbot-secrets \
--from-env-file=.env \
--namespace=tradingbots-2025
# 3. Deploy with Helm
helm upgrade --install tradingbots \
./helm/tradingbots \
--create-namespace \
--namespace tradingbots-2025
What Gets Deployed:
- PostgreSQL instance (if postgresql.enabled: true in values.yaml)
- Trading bot CronJobs (one per bot in values.yaml)
- Visualization dashboard (if visualization.enabled: true)
- All configured with secrets and environment variables
See Kubernetes Deployment and Helm Charts for detailed configuration.
Option 2: Local Development
Run PostgreSQL locally and execute bots manually with bot.run().
Benefits: - Fast iteration and testing - No Kubernetes cluster required - Easy debugging and development
Setup:
-
Run PostgreSQL with Docker:
-
Set Environment Variable:
-
Run Your Bot:
See the Quick Start Guide for complete local development workflow.
PostgreSQL Deployment
Kubernetes (via Helm)
PostgreSQL is automatically deployed when postgresql.enabled: true in helm/tradingbots/values.yaml:
postgresql:
enabled: true
image:
repository: postgres
tag: 17-alpine
database: postgres
service:
name: psql-service
port: 5432
The Helm chart creates:
- PostgreSQL Deployment
- PostgreSQL Service (accessible at psql-service:5432)
- Persistent storage (configured in values.yaml)
Connection String: postgresql://postgres:${POSTGRES_PASSWORD}@psql-service:5432/postgres
Local (Docker)
For local development, use the Docker command shown in Option 2 above.
Bot Deployment
Kubernetes (CronJobs)
Bots are deployed as Kubernetes CronJobs with configurable schedules:
# helm/tradingbots/values.yaml
bots:
- name: mybot
schedule: "*/5 * * * 1-5" # Every 5 minutes, Mon-Fri
Each bot runs automatically on its schedule. See Helm Charts for configuration details.
Local (Manual Execution)
Run bots manually with bot.run():
For scheduled execution locally, use cron or a task scheduler.
Configuration
Secrets Management
All secrets (database passwords, API keys) are stored in a single Kubernetes secret:
# Create .env file with:
# POSTGRES_PASSWORD=yourpassword
# POSTGRES_URI=postgresql://postgres:yourpassword@psql-service:5432/postgres
# OPENROUTER_API_KEY=yourkey
# BASIC_AUTH_PASSWORD=yourpassword
# Create secret
kubectl create secret generic tradingbot-secrets \
--from-env-file=.env \
--namespace=tradingbots-2025
Security: Never commit .env files to version control. Add to .gitignore.
Environment Variables
Bots receive environment variables from Kubernetes secrets:
Monitoring
Kubernetes
View bot execution logs:
# List CronJobs
kubectl get cronjobs -n tradingbots-2025
# List recent jobs
kubectl get jobs -n tradingbots-2025
# View logs
kubectl logs -n tradingbots-2025 job/<job-name>
Local
Check database for run logs:
from tradingbot.utils.db import get_db_session, RunLog
with get_db_session() as session:
logs = session.query(RunLog).filter(
RunLog.bot_name == "MyBot"
).order_by(RunLog.timestamp.desc()).limit(10).all()
for log in logs:
print(f"{log.timestamp}: {log.success} - {log.result}")
Next Steps
- Kubernetes Setup: See Kubernetes Deployment for cluster setup
- Helm Configuration: See Helm Charts for bot scheduling and configuration
- Local Development: See Quick Start Guide for local setup
- Creating Bots: See Creating a Bot for bot development