Commit Graph

13 Commits

Author SHA1 Message Date
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
mindesbunister
a294f44a06 fix: Add adaptive leverage env vars to docker-compose.yml
Added 4 adaptive leverage environment variables to docker-compose.yml
so they are properly passed to the container:

- USE_ADAPTIVE_LEVERAGE (default: true)
- HIGH_QUALITY_LEVERAGE (default: 5)
- LOW_QUALITY_LEVERAGE (default: 1)
- QUALITY_LEVERAGE_THRESHOLD (default: 95)

Without these in the environment section, the container couldn't
access them via process.env, causing the settings API to return null.

Now the settings UI can properly load and save adaptive leverage
configuration via the web interface.
2025-12-01 08:52:07 +01:00
mindesbunister
cc56b72df2 fix: Database-first cluster status detection + Stop button clarification
CRITICAL FIX (Nov 30, 2025):
- Dashboard showed 'idle' despite 22+ worker processes running
- Root cause: SSH-based worker detection timing out
- Solution: Check database for running chunks FIRST

Changes:
1. app/api/cluster/status/route.ts:
   - Query exploration database before SSH detection
   - If running chunks exist, mark workers 'active' even if SSH fails
   - Override worker status: 'offline' → 'active' when chunks running
   - Log: ' Cluster status: ACTIVE (database shows running chunks)'
   - Database is source of truth, SSH only for supplementary metrics

2. app/cluster/page.tsx:
   - Stop button ALREADY EXISTS (conditionally shown)
   - Shows Start when status='idle', Stop when status='active'
   - No code changes needed - fixed by status detection

Result:
- Dashboard now shows 'ACTIVE' with 2 workers (correct)
- Workers show 'active' status (was 'offline')
- Stop button automatically visible when cluster active
- System resilient to SSH timeouts/network issues

Verified:
- Container restarted: Nov 30 21:18 UTC
- API tested: Returns status='active', activeWorkers=2
- Logs confirm: Database-first logic working
- Workers confirmed running: 22+ processes on worker1, workers on worker2
2025-11-30 22:23:01 +01:00
mindesbunister
40ddac5a95 feat: Revenge timing Option 2 - 90s confirmation (DEPLOYED)
- Changed both LONG and SHORT revenge to require 90-second confirmation
- OLD: LONG immediate entry, SHORT 60s confirmation
- NEW: Both require 90s (1.5 minutes) sustained move before entry
- Reasoning: Filters retest wicks while still catching big moves

Real-world scenario (Nov 26, 2025):
- Stop-out: $138.00 at 14:51 CET
- Would enter immediately: $136.32
- Retest bounce: $137.50 (would stop out again at $137.96)
- Actual move: $136 → $144.50 (+$530 opportunity)
- OLD system: Enters $136.32, stops $137.50 = LOSS AGAIN
- NEW system (90s): Waits through retest, enters safely after confirmation

Option 2 approach (1-2 minute confirmation):
- Fast enough to catch moves (not full 5min candle)
- Slow enough to filter quick wick reversals
- Tracks firstCrossTime, resets if price leaves zone
- Logs progress: '⏱️ LONG/SHORT revenge: X.Xmin in zone (need 1.5min)'

Files changed:
- lib/trading/stop-hunt-tracker.ts (lines 254-310)

Deployment:
- Container restarted: 2025-11-26 20:52:55 CET
- Build time: 71.8s compilation
- Status:  DEPLOYED and VERIFIED

Future consideration:
- User suggested TradingView signals every 1 minute for better granularity
- Decision: Validate 90s approach first with real stop-outs
2025-11-26 20:53:35 +01:00
mindesbunister
0baac4f137 feat: Automated failover system with certificate sync and DNS monitoring
Certificate Synchronization (COMPLETE):
- Created cert-push-to-hostinger.sh on srvrevproxy02
- Hourly cron job pushes /etc/letsencrypt/ from srvrevproxy02 to Hostinger
- SSH key authentication (id_ed25519_hostinger) configured
- 22MB of Let's Encrypt certificates synced successfully
- Automatic nginx reload on Hostinger after sync
- Log: /var/log/cert-push-hostinger.log

DNS Failover Monitor (READY):
- Python script: dns-failover-monitor.py on Hostinger
- INWX API integration for automatic DNS updates
- Health monitoring every 30s, failover after 3 failures (90s)
- Systemd service with auto-restart
- Setup script: setup-inwx-env.sh for INWX credentials
- Log: /var/log/dns-failover.log

Architecture:
- Primary: srvrevproxy02 (10.0.0.29) - Certificate source
- Secondary: Hostinger (72.62.39.24) - Failover target
- Nginx on Hostinger now uses flow.egonetix.de certificate

Next Steps:
- Run /root/setup-inwx-env.sh on Hostinger
- Enter INWX credentials
- Start monitoring: systemctl start dns-failover
2025-11-25 16:01:15 +01:00
mindesbunister
357626b392 fix: Add direction-specific quality thresholds to docker-compose.yml
- Added MIN_SIGNAL_QUALITY_SCORE_LONG, _SHORT, and global to environment section
- Required for ENV variables to be available in Node.js process.env
- Without this, container couldn't read .env values for direction-specific thresholds

Testing verified:
- LONG quality 90:  ALLOWED (threshold 90)
- SHORT quality 70:  BLOCKED (threshold 95)
- Direction-specific logic working correctly
2025-11-23 15:06:01 +01:00
mindesbunister
9673457326 feat: add Berlin timezone support to containers
- Add tzdata package to Dockerfile runner stage
- Set TZ=Europe/Berlin in docker-compose.yml for both trading-bot and postgres
- All container timestamps now show CET instead of UTC
- User-friendly log times matching local time

Files changed:
- Dockerfile: Added tzdata to runner stage
- docker-compose.yml: Added TZ environment variable
2025-11-14 05:56:03 +01:00
mindesbunister
6590f4fb1e 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
2025-11-14 05:37:51 +01:00
mindesbunister
b82ceb49a4 feat: add position size and leverage to Telegram confirmation message 2025-10-27 01:06:51 +01:00
mindesbunister
993ae64c64 fix: Add TP size environment variables to docker-compose
- Added TAKE_PROFIT_1_SIZE_PERCENT env var
- Added TAKE_PROFIT_2_SIZE_PERCENT env var
- These were missing causing container to use defaults
- Requires 'docker compose up -d --force-recreate' not just restart
2025-10-24 15:47:33 +02:00
mindesbunister
1c4cc5d1fb feat: Add customizable TP size percentages and fix settings save
**New Features:**
- Added TAKE_PROFIT_1_SIZE_PERCENT (default: 50%)
- Added TAKE_PROFIT_2_SIZE_PERCENT (default: 50%)
- Users can now control WHAT % to close at each TP level
- Risk calculator now shows actual TP sizes dynamically

**Bug Fixes:**
- Fixed settings save failure by mounting .env file to container
- Added .env volume mount in docker-compose.yml
- Fixed permission issues (.env must be chmod 666)

**UI Changes:**
- Split TP controls into Price % and Size %
- TP1 Price: When to exit first partial
- TP1 Size: What % of position to close (1-100%)
- TP2 Price: When to exit second partial
- TP2 Size: What % of remaining to close (1-100%)
- Risk calculator displays dynamic percentages

**Example:**
- TP1 at +1% price, close 60% of position
- TP2 at +2% price, close 40% of remaining (24% of original)
- Total exit: 84% of position at TP levels
2025-10-24 15:35:36 +02:00
mindesbunister
26864c10f2 feat: Add container restart functionality from web UI
- Added restart button to settings page
- Created /api/restart endpoint (file-flag based)
- Implemented watch-restart.sh daemon
- Added systemd service for restart watcher
- Updated README with restart setup instructions
- Container automatically restarts when settings changed

Settings flow:
1. User edits settings in web UI
2. Click 'Save Settings' to persist to .env
3. Click 'Restart Bot' to apply changes
4. Watcher detects flag and restarts container
5. New settings loaded automatically
2025-10-24 15:06:26 +02:00
mindesbunister
2405bff68a feat: Complete Trading Bot v4 with Drift Protocol integration
Features:
- Autonomous trading system with Drift Protocol on Solana
- Real-time position monitoring with Pyth price feeds
- Dynamic stop-loss and take-profit management
- n8n workflow integration for TradingView signals
- Beautiful web UI for settings management
- REST API for trade execution and monitoring

- Next.js 15 with standalone output mode
- TypeScript with strict typing
- Docker containerization with multi-stage builds
- PostgreSQL database for trade history
- Singleton pattern for Drift client connection pooling
- BN.js for BigNumber handling (Drift SDK requirement)

- Configurable stop-loss and take-profit levels
- Breakeven trigger and profit locking
- Daily loss limits and trade cooldowns
- Slippage tolerance controls
- DRY_RUN mode for safe testing

- Real-time risk calculator
- Interactive sliders for all parameters
- Live preview of trade outcomes
- Position sizing and leverage controls
- Beautiful gradient design with Tailwind CSS

- POST /api/trading/execute - Execute trades
- POST /api/trading/close - Close positions
- GET /api/trading/positions - Monitor active trades
- GET /api/trading/check-risk - Validate trade signals
- GET /api/settings - View configuration
- POST /api/settings - Update configuration

- Fixed Borsh serialization errors (simplified order params)
- Resolved RPC rate limiting with singleton pattern
- Fixed BigInt vs BN type mismatches
- Corrected order execution flow
- Improved position state management

- Complete setup guides
- Docker deployment instructions
- n8n workflow configuration
- API reference documentation
- Risk management guidelines

- Runs on port 3001 (external), 3000 (internal)
- Uses Helius RPC for optimal performance
- Production-ready with error handling
- Health monitoring and logging
2025-10-24 14:24:36 +02:00