Files
trading_bot_v3/v4
mindesbunister 8bb2f64568 feat: Add complete Docker containerization for v4
Production & Development Setup:
- Multi-stage Dockerfile with optimized build (node:20-alpine)
- docker-compose.yml for production with PostgreSQL
- docker-compose.dev.yml for development with hot reload
- Dockerfile.dev for development environment
- .dockerignore to reduce build context

Features:
- Health checks for both app and database
- Non-root user security (nextjs:nodejs)
- Resource limits (CPU/memory)
- Volume persistence for logs and database
- PostgreSQL 16 with automatic initialization
- Network isolation with custom bridge network

Helper Scripts:
- docker-build.sh - Build production image
- docker-start.sh - Start all services
- docker-stop.sh - Stop containers safely
- docker-logs.sh - View real-time logs

Documentation:
- DOCKER.md - Complete deployment guide with:
  * Quick start commands
  * Production deployment steps
  * Development hot reload setup
  * Configuration examples
  * Docker commands reference
  * Troubleshooting guide
  * Best practices for security & performance

Configuration:
- Environment-based configuration via .env
- Safe defaults for testing ($50 positions)
- Separate dev/prod compose files
- Debug mode with Node.js inspector (port 9229)
- Log rotation and resource monitoring

Ready for deployment with:
  cd v4 && ./docker-start.sh
2025-10-23 14:57:49 +02:00
..

Trading Bot v4 🚀

Fully Autonomous Trading Bot for TradingView → n8n → Drift Protocol (Solana)

Status

Phase Status Description
Phase 1 COMPLETE Trade execution from TradingView signals
Phase 2 COMPLETE Real-time monitoring & automatic exits
Phase 3 🚧 PLANNED Database, risk manager, notifications

What It Does

  1. Receives signals from TradingView (5-minute chart)
  2. Executes trades on Drift Protocol (Solana DEX)
  3. Monitors prices in real-time via Pyth Network
  4. Closes positions automatically at TP1/TP2/SL
  5. Adjusts stops dynamically (breakeven, profit lock)

100% autonomous. No manual intervention required!

Quick Start

1. Install Phase 2

# From project root
./install-phase2.sh

2. Configure

# Edit .env.local
DRIFT_WALLET_PRIVATE_KEY=your_base58_key
SOLANA_RPC_URL=https://mainnet.helius-rpc.com/?api-key=YOUR_KEY
API_KEY=your_random_secret_key

3. Test

cd v4

# Test price monitoring (safe)
npx tsx test-price-monitor.ts

# Test position manager (safe)  
npx tsx test-position-manager.ts

# Test full flow (REAL TRADE - use small size!)
npx tsx test-full-flow.ts

4. Trade

# Start server
npm run dev

# Configure TradingView alerts → n8n webhook
# Bot handles everything automatically!

Features

Phase 1: Trade Execution

  • Drift Protocol integration
  • Market order execution
  • TradingView signal normalization
  • n8n webhook endpoint
  • Risk validation API

Phase 2: Autonomous Trading

  • Pyth price monitoring (WebSocket + polling)
  • Position manager (tracks all trades)
  • Automatic exits (TP1/TP2/SL/Emergency)
  • Dynamic SL (breakeven + profit lock)
  • Multi-position support
  • Real-time P&L tracking

Phase 3: Coming Soon 🚧

  • Database persistence (PostgreSQL/Prisma)
  • Advanced risk manager
  • Trade history & analytics
  • Enhanced notifications
  • Web dashboard

File Structure

v4/
├── README.md                        ← You are here
├── QUICKREF_PHASE2.md              ← Quick reference
├── PHASE_2_COMPLETE.md             ← Phase 2 features
├── PHASE_2_SUMMARY.md              ← Detailed summary
├── TESTING.md                      ← Testing guide
├── SETUP.md                        ← Setup instructions
│
├── config/
│   └── trading.ts                  ← Trading configuration
│
├── lib/
│   ├── drift/
│   │   ├── client.ts               ← Drift SDK wrapper
│   │   └── orders.ts               ← Order execution
│   ├── pyth/
│   │   └── price-monitor.ts        ← Real-time prices
│   └── trading/
│       └── position-manager.ts     ← Auto-exit logic
│
├── app/
│   └── api/
│       └── trading/
│           ├── execute/
│           │   └── route.ts        ← Execute trade
│           ├── check-risk/
│           │   └── route.ts        ← Risk validation
│           └── positions/
│               └── route.ts        ← Query positions
│
└── test-*.ts                       ← Test scripts

Documentation

Document Purpose
README.md This overview
QUICKREF_PHASE2.md Quick reference card
SETUP.md Detailed setup instructions
TESTING.md Comprehensive testing guide
PHASE_2_COMPLETE.md Phase 2 feature overview
PHASE_2_SUMMARY.md Detailed Phase 2 summary

Root documentation:

  • ../TRADING_BOT_V4_MANUAL.md - Complete manual
  • ../QUICKSTART_V4.md - Quick start guide
  • ../N8N_SETUP_GUIDE.md - n8n configuration

Trade Example

Entry Signal

TradingView: LONG SOL @ $140.00
Position: $1,000 (10x = $10,000)
SL: $137.90 (-1.5%)
TP1: $140.98 (+0.7%)
TP2: $142.10 (+1.5%)

TP1 Hit

✅ Price reaches $140.98
→ Auto-close 50% (+$70)
→ Move SL to $140.21 (breakeven)
→ Trade is now RISK-FREE

TP2 Hit

✅ Price reaches $142.10
→ Auto-close remaining 50% (+$150)
→ Total P&L: +$220 (+22% account)
→ Trade complete!

Safety Guidelines

  1. Start Small: Use $10-50 positions first
  2. Test Thoroughly: Run all test scripts
  3. Monitor Closely: Watch first 10 auto-exits
  4. Verify Fills: Check Drift UI after exits
  5. Scale Gradually: Increase size weekly

Resources


Ready to trade autonomously? Read QUICKREF_PHASE2.md to get started! 🚀

Start small, monitor closely, scale gradually!