feat: phantom trade auto-closure system

- Auto-close phantom positions immediately via market order
- Return HTTP 200 (not 500) to allow n8n workflow continuation
- Save phantom trades to database with full P&L tracking
- Exit reason: 'manual' category for phantom auto-closes
- Protects user during unavailable hours (sleeping, no phone)
- Add Docker build best practices to instructions (background + tail)
- Document phantom system as Critical Component #1
- Add Common Pitfall #30: Phantom notification workflow

Why auto-close:
- User can't always respond to phantom alerts
- Unmonitored position = unlimited risk exposure
- Better to exit with small loss/gain than leave exposed
- Re-entry possible if setup actually good

Files changed:
- app/api/trading/execute/route.ts: Auto-close logic
- .github/copilot-instructions.md: Documentation + build pattern
This commit is contained in:
mindesbunister
2025-11-14 05:37:51 +01:00
parent 4ad509928f
commit 6590f4fb1e
7 changed files with 383 additions and 17 deletions

View File

@@ -11,6 +11,9 @@ services:
dockerfile: Dockerfile
container_name: trading-bot-v4
restart: unless-stopped
dns:
- 8.8.8.8
- 8.8.4.4
ports:
- "3001:3000"
environment:
@@ -80,6 +83,14 @@ services:
# ================================
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: