Files
trading_bot_v4/docker-compose.yml
mindesbunister 67ef5b1ac6 feat: Add direction-specific quality thresholds and dynamic collateral display
- Split QUALITY_LEVERAGE_THRESHOLD into separate LONG and SHORT variants
- Added /api/drift/account-health endpoint for real-time collateral data
- Updated settings UI to show separate controls for LONG/SHORT thresholds
- Position size calculations now use dynamic collateral from Drift account
- Updated .env and docker-compose.yml with new environment variables
- LONG threshold: 95, SHORT threshold: 90 (configurable independently)

Files changed:
- app/api/drift/account-health/route.ts (NEW) - Account health API endpoint
- app/settings/page.tsx - Added collateral state, separate threshold inputs
- app/api/settings/route.ts - GET/POST handlers for LONG/SHORT thresholds
- .env - Added QUALITY_LEVERAGE_THRESHOLD_LONG/SHORT variables
- docker-compose.yml - Added new env vars with fallback defaults

Impact:
- Users can now configure quality thresholds independently for LONG vs SHORT signals
- Position size display dynamically updates based on actual Drift account collateral
- More flexible risk management with direction-specific leverage tiers
2025-12-01 09:09:30 +01:00

170 lines
5.0 KiB
YAML

# Trading Bot v4 - Docker Compose Configuration
# Production-ready setup with PostgreSQL and monitoring
services:
# ================================
# Trading Bot Application
# ================================
trading-bot:
build:
context: .
dockerfile: Dockerfile
container_name: trading-bot-v4
restart: unless-stopped
dns:
- 8.8.8.8
- 8.8.4.4
ports:
- "3001:3000"
environment:
# Timezone
TZ: Europe/Berlin
# Node environment
NODE_ENV: production
PORT: 3000
# Load from .env file (create from .env.example)
DRIFT_WALLET_PRIVATE_KEY: ${DRIFT_WALLET_PRIVATE_KEY}
DRIFT_ENV: ${DRIFT_ENV:-mainnet-beta}
API_SECRET_KEY: ${API_SECRET_KEY}
SOLANA_RPC_URL: ${SOLANA_RPC_URL}
PYTH_HERMES_URL: ${PYTH_HERMES_URL:-https://hermes.pyth.network}
# Trading configuration
MAX_POSITION_SIZE_USD: ${MAX_POSITION_SIZE_USD:-50}
LEVERAGE: ${LEVERAGE:-10}
STOP_LOSS_PERCENT: ${STOP_LOSS_PERCENT:--1.5}
TAKE_PROFIT_1_PERCENT: ${TAKE_PROFIT_1_PERCENT:-0.7}
TAKE_PROFIT_1_SIZE_PERCENT: ${TAKE_PROFIT_1_SIZE_PERCENT:-50}
TAKE_PROFIT_2_PERCENT: ${TAKE_PROFIT_2_PERCENT:-1.5}
TAKE_PROFIT_2_SIZE_PERCENT: ${TAKE_PROFIT_2_SIZE_PERCENT:-50}
# Signal quality thresholds (Nov 23, 2025 - direction-specific)
MIN_SIGNAL_QUALITY_SCORE: ${MIN_SIGNAL_QUALITY_SCORE:-91}
MIN_SIGNAL_QUALITY_SCORE_LONG: ${MIN_SIGNAL_QUALITY_SCORE_LONG:-90}
MIN_SIGNAL_QUALITY_SCORE_SHORT: ${MIN_SIGNAL_QUALITY_SCORE_SHORT:-95}
# Adaptive Leverage (Dec 1, 2025 - quality-based position sizing)
USE_ADAPTIVE_LEVERAGE: ${USE_ADAPTIVE_LEVERAGE:-true}
HIGH_QUALITY_LEVERAGE: ${HIGH_QUALITY_LEVERAGE:-5}
LOW_QUALITY_LEVERAGE: ${LOW_QUALITY_LEVERAGE:-1}
QUALITY_LEVERAGE_THRESHOLD_LONG: ${QUALITY_LEVERAGE_THRESHOLD_LONG:-95}
QUALITY_LEVERAGE_THRESHOLD_SHORT: ${QUALITY_LEVERAGE_THRESHOLD_SHORT:-90}
QUALITY_LEVERAGE_THRESHOLD: ${QUALITY_LEVERAGE_THRESHOLD:-95} # Backward compatibility
# Database (if using PostgreSQL)
DATABASE_URL: ${DATABASE_URL:-postgresql://postgres:postgres@postgres:5432/trading_bot_v4}
# Notifications
TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN:-}
TELEGRAM_CHAT_ID: ${TELEGRAM_CHAT_ID:-}
DISCORD_WEBHOOK_URL: ${DISCORD_WEBHOOK_URL:-}
# n8n integration
N8N_WEBHOOK_URL: ${N8N_WEBHOOK_URL:-}
TRADINGVIEW_WEBHOOK_SECRET: ${TRADINGVIEW_WEBHOOK_SECRET:-}
# Monitoring
LOG_LEVEL: ${LOG_LEVEL:-info}
DRY_RUN: ${DRY_RUN:-false}
volumes:
# Mount .env file for settings persistence
- ./.env:/app/.env
# Mount logs directory
- ./logs:/app/logs
# Mount cluster directory for exploration database
- ./cluster:/app/cluster
# Mount Docker socket for container restart capability
- /var/run/docker.sock:/var/run/docker.sock
# Mount for hot reload in development (comment out in production)
# - ./v4:/app/v4:ro
networks:
- trading-net
depends_on:
- postgres
deploy:
resources:
limits:
memory: 2G
cpus: '2.0'
reservations:
memory: 512M
cpus: '0.5'
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/api/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"]
interval: 30s
timeout: 10s
retries: 3
# ================================
# PostgreSQL Database (Optional)
# ================================
postgres:
image: postgres:16-alpine
command: |
postgres
-c shared_buffers=128MB
-c effective_cache_size=512MB
-c work_mem=8MB
-c maintenance_work_mem=64MB
-c max_connections=20
-c random_page_cost=1.1
container_name: trading-bot-postgres
restart: unless-stopped
ports:
- "55432:5432"
environment:
TZ: Europe/Berlin
POSTGRES_DB: trading_bot_v4
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
POSTGRES_INITDB_ARGS: "--encoding=UTF8 --locale=en_US.UTF-8"
volumes:
# Persist database data
- postgres-data:/var/lib/postgresql/data
# Custom initialization scripts (optional)
- ./prisma/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
networks:
- trading-net
deploy:
resources:
limits:
memory: 1G
cpus: '1.0'
reservations:
memory: 512M
cpus: '0.25'
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
# ================================
# Networks
# ================================
networks:
trading-net:
driver: bridge
ipam:
config:
- subnet: 172.28.0.0/16
# ================================
# Volumes
# ================================
volumes:
postgres-data:
driver: local