Organization: - Created docs/ with setup/, guides/, history/ subdirectories - Created workflows/ with trading/, analytics/, telegram/, archive/ subdirectories - Created scripts/ with docker/, setup/, testing/ subdirectories - Created tests/ for TypeScript test files - Created archive/ for unused reference files Moved files: - 17 documentation files → docs/ - 16 workflow JSON files → workflows/ - 10 shell scripts → scripts/ - 4 test files → tests/ - 5 unused files → archive/ Updated: - README.md with new file structure and documentation paths Deleted: - data/ (empty directory) - screenshots/ (empty directory) Critical files remain in root: - telegram_command_bot.py (active bot - used by Dockerfile) - watch-restart.sh (systemd service dependency) - All Dockerfiles and docker-compose files - All environment files Validation: Containers running (trading-bot-v4, telegram-trade-bot, postgres) API responding (positions endpoint tested) Telegram bot functional (/status command tested) All critical files present in root No code changes - purely organizational. System continues running without interruption. Recovery: git revert HEAD or git reset --hard cleanup-before
4.5 KiB
4.5 KiB
🚀 Phase 2 Quick Reference
What's New
✅ Fully Autonomous Trading
- Opens positions from signals
- Monitors prices in real-time
- Closes automatically at TP/SL
- Adjusts stops dynamically
Quick Start
1. Install
./install-phase2.sh
2. Configure
# Edit .env.local:
DRIFT_WALLET_PRIVATE_KEY=your_key
SOLANA_RPC_URL=your_rpc
API_KEY=your_secret
3. Test
cd v4
# Test price monitoring
npx tsx test-price-monitor.ts
# Test position manager
npx tsx test-position-manager.ts
# Test full flow (REAL TRADE!)
npx tsx test-full-flow.ts
4. Trade
# Start server
npm run dev
# Trigger TradingView alert
# Bot handles everything!
Key Features
Smart Exits
- TP1 (+0.7%): Close 50%, move SL to breakeven
- TP2 (+1.5%): Close remaining 50%
- SL (-1.5%): Close 100%
- Emergency (-2.0%): Hard stop
Dynamic SL
- After TP1: Move to breakeven
- At +1.0% profit: Move to +0.4%
- Never moves backward
- Protects all gains
Real-Time
- Pyth WebSocket (~400ms)
- Polling fallback (2s)
- Checks every 2 seconds
- Market orders for speed
API Endpoints
Execute Trade
POST /api/trading/execute
{
"symbol": "SOLUSDT",
"direction": "long",
"timeframe": "5"
}
Get Positions
GET /api/trading/positions
Trade Example
Entry
Signal: LONG SOL @ $140.00
Position: $1,000 (10x = $10,000)
SL: $137.90 (-1.5% = -$150)
TP1: $140.98 (+0.7% = +$70)
TP2: $142.10 (+1.5% = +$150)
TP1 Hit
✅ Price: $140.98
→ Close 50% (+$70)
→ Move SL to $140.21 (breakeven)
→ Risk = $0
TP2 Hit
✅ Price: $142.10
→ Close 50% (+$150)
→ Total P&L: +$220 (+22%)
→ Trade complete!
Testing Checklist
- Run install-phase2.sh
- Configure .env.local
- Test price monitor (no risk)
- Test position manager (no risk)
- Test full flow with $10-50 position
- Watch first 5-10 auto-exits
- Verify on Drift UI
- Scale up gradually
Configuration
Risk Parameters
MAX_POSITION_SIZE_USD=1000
LEVERAGE=10
STOP_LOSS_PERCENT=-1.5
TAKE_PROFIT_1_PERCENT=0.7
TAKE_PROFIT_2_PERCENT=1.5
EMERGENCY_STOP_PERCENT=-2.0
Monitoring
PRICE_CHECK_INTERVAL_MS=2000
SLIPPAGE_TOLERANCE=1.0
Troubleshooting
"Cannot find module"
npm install @pythnetwork/price-service-client
"Drift service not initialized"
# Check .env.local has:
DRIFT_WALLET_PRIVATE_KEY=...
SOLANA_RPC_URL=...
"WebSocket disconnected"
Normal - will reconnect automatically
Polling fallback handles updates
"Position not closing"
Check:
1. Is price hitting targets?
2. Are logs showing price checks?
3. Is position manager running?
Most likely: Targets not hit yet!
Performance Targets
5-Minute Scalping
- Win Rate: 60-70%
- Avg Win: +7% to +22%
- Avg Loss: -15%
- Daily Target: +2% to +5%
- Trades/Day: 5-15
Example Day
Trade 1: +7% (TP1)
Trade 2: +22% (TP1+TP2)
Trade 3: -15% (SL)
Trade 4: +7% (TP1)
Trade 5: +22% (TP1+TP2)
Daily: +43% 🎉
Safety Rules
- Start small: $10-50 positions
- Monitor closely: First 10 trades
- Verify exits: Check Drift UI
- Scale gradually: Increase 2x weekly
- Max risk: Never > 20% per trade
Documentation
PHASE_2_COMPLETE.md- Full featuresPHASE_2_SUMMARY.md- OverviewTESTING.md- Testing guideSETUP.md- Setup instructionsTRADING_BOT_V4_MANUAL.md- Complete manual
What's Next (Phase 3)
- Database integration
- Trade history persistence
- Risk manager enforcement
- Enhanced notifications
- Performance analytics
- Web dashboard
But you can trade NOW!
Support
Common Commands
# Install Phase 2
./install-phase2.sh
# Test monitoring
cd v4 && npx tsx test-price-monitor.ts
# Test manager
cd v4 && npx tsx test-position-manager.ts
# Test full flow
cd v4 && npx tsx test-full-flow.ts
# Start server
npm run dev
# Check positions
curl http://localhost:3000/api/trading/positions \
-H "Authorization: Bearer YOUR_API_KEY"
Files Changed
New:
+ v4/lib/pyth/price-monitor.ts
+ v4/lib/trading/position-manager.ts
+ v4/app/api/trading/positions/route.ts
+ v4/test-price-monitor.ts
+ v4/test-position-manager.ts
+ v4/test-full-flow.ts
+ v4/PHASE_2_COMPLETE.md
+ v4/PHASE_2_SUMMARY.md
+ v4/TESTING.md
+ install-phase2.sh
Updated:
~ v4/app/api/trading/execute/route.ts
~ v4/SETUP.md
Phase 2 Complete! Let the bot trade! 🚀
Start small, monitor closely, scale gradually!