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
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+)
kubectlconfigured- 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-2025What Gets Deployed:
- PostgreSQL instance (if
postgresql.enabled: trueinvalues.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.
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:
docker run -d --name postgres-tradingbot \
-e POSTGRES_PASSWORD=yourpassword \
-e POSTGRES_DB=tradingbot \
-p 5432:5432 \
postgres:17-alpine- Set Environment Variable:
export POSTGRES_URI="postgresql://postgres:yourpassword@localhost:5432/tradingbot"- Run Your Bot:
from tradingbot.utils.botclass import Bot
bot = MyBot()
bot.run() # Executes one iterationSee the Quick Start Guide for complete local development workflow.
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: 5432The 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
For local development, use the Docker command shown in Option 2 above.
Bots are deployed as Kubernetes CronJobs with configurable schedules:
# helm/tradingbots/values.yaml
bots:
- name: mybot
schedule: "*/5 * * * 1-5" # Every 5 minutes, Mon-FriEach bot runs automatically on its schedule. See Helm Charts for configuration details.
Run bots manually with bot.run():
bot = MyBot()
bot.run() # Execute one iterationFor scheduled execution locally, use cron or a task scheduler.
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-2025Security: Never commit .env files to version control. Add to .gitignore.
Bots receive environment variables from Kubernetes secrets:
env:
- name: POSTGRES_URI
valueFrom:
secretKeyRef:
name: tradingbot-secrets
key: POSTGRES_URIView 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>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}")- 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