# Full self-contained stack for the Momentum System. # # docker compose up -d # postgres + loop + dashboard + qabot + transcripts + scheduler # docker compose --profile monitoring up -d # also start Grafana # docker compose run --rm nightly-tune # run a job on demand # # Secrets come from .env (never baked into the image). DATABASE_URL is # overridden below to the in-stack postgres so the stack is self-contained — # migrating from the LAN Postgres (192.168.1.5) is a pg_dump/restore into the # pg-data volume; see deploy/docker/README.md. To run the app services against # the LAN Postgres instead (transition mode), comment out the DATABASE_URL # override and let .env's value through. # # TZ is America/New_York in the image: the loop's market clock thinks in ET. x-app: &app build: . image: momentum-app:latest env_file: - path: .env required: false volumes: - app-data:/app/data depends_on: postgres: condition: service_healthy restart: unless-stopped logging: driver: json-file options: { max-size: "20m", max-file: "3" } x-app-env: &app-env # Self-contained default: the in-stack postgres. Overrides .env. DATABASE_URL: postgresql://${POSTGRES_USER:-momentum}:${POSTGRES_PASSWORD:-momentum}@postgres:5432/${POSTGRES_DB:-momentum} PG_SKIP_SCHEMA: "0" services: postgres: image: postgres:18 environment: POSTGRES_USER: ${POSTGRES_USER:-momentum} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-momentum} POSTGRES_DB: ${POSTGRES_DB:-momentum} PGDATA: /var/lib/postgresql/data/pgdata volumes: - pg-data:/var/lib/postgresql/data ports: - "5432:5432" # psql/Grafana-on-host debugging; remove if not needed healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-momentum} -d ${POSTGRES_DB:-momentum}"] interval: 10s timeout: 5s retries: 5 restart: unless-stopped loop: <<: *app container_name: momentum-loop command: ["python", "-u", "run_live_paper.py", "--no-dashboard"] environment: <<: *app-env healthcheck: # heartbeat: the loop must have written SOME event in the last 5 minutes # (module ticks flow around the clock, not just market hours) test: ["CMD", "python", "-c", "import datetime,sys; from research.multi_schema import open_research_db; r=open_research_db('market').execute('SELECT max(timestamp) FROM events').fetchall()[0][0]; sys.exit(0 if r and (datetime.datetime.now()-r).total_seconds()<300 else 1)"] interval: 60s timeout: 20s retries: 5 start_period: 180s dashboard: <<: *app container_name: momentum-dashboard command: ["python", "-u", "dashboard_api.py"] environment: <<: *app-env DASHBOARD_HOST: "0.0.0.0" DASHBOARD_PORT: "8765" ports: - "8765:8765" healthcheck: test: ["CMD", "curl", "-sf", "http://localhost:8765/"] interval: 30s timeout: 10s retries: 3 start_period: 30s qabot: <<: *app container_name: momentum-qabot command: ["python", "-u", "telegram_bot.py"] environment: <<: *app-env transcripts: <<: *app container_name: momentum-transcripts command: ["python", "-u", "-m", "youtube_claims.run", "run"] environment: <<: *app-env scheduler: # Weekday-evening premarket eval + DB/log housekeeping at 20:00 ET — # replaces the momentum-premarket-eval systemd timer. <<: *app container_name: momentum-scheduler environment: <<: *app-env command: - /bin/sh - -c - | echo "[scheduler] up; will fire 20:00 ET Mon-Fri" while true; do if [ "$$(date +%H:%M)" = "20:00" ] && [ "$$(date +%u)" -le 5 ]; then echo "[scheduler] premarket_eval $$(date)" python -m research.premarket_eval || echo "[scheduler] eval FAILED" sleep 120 fi sleep 20 done # ---- On-demand jobs: docker compose run --rm journal: <<: *app profiles: ["jobs"] command: ["python", "momentum_cli.py", "journal"] environment: *app-env restart: "no" eod-replay: <<: *app profiles: ["jobs"] command: ["python", "eod_replay.py"] environment: *app-env restart: "no" nightly-tune: <<: *app profiles: ["jobs"] command: ["python", "nightly_tune.py"] environment: *app-env restart: "no" # ---- Grafana (optional): docker compose --profile monitoring up -d grafana: image: grafana/grafana:11.2.0 profiles: ["monitoring"] environment: GF_AUTH_ANONYMOUS_ENABLED: "true" GF_AUTH_ANONYMOUS_ORG_ROLE: "Admin" GF_AUTH_DISABLE_LOGIN_FORM: "true" GF_DASHBOARDS_MIN_REFRESH_INTERVAL: "2s" PG_USER: ${POSTGRES_USER:-momentum} PG_PASSWORD: ${POSTGRES_PASSWORD:-momentum} PG_DATABASE: ${POSTGRES_DB:-momentum} ports: - "3000:3000" volumes: - ./deploy/compose/grafana/datasources:/etc/grafana/provisioning/datasources:ro - ./grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards:ro - grafana-data:/var/lib/grafana depends_on: postgres: condition: service_healthy restart: unless-stopped volumes: pg-data: app-data: grafana-data: