**Documentation Structure:** - Created docs/ subdirectory organization (analysis/, architecture/, bugs/, cluster/, deployments/, roadmaps/, setup/, archived/) - Moved 68 root markdown files to appropriate categories - Root directory now clean (only README.md remains) - Total: 83 markdown files now organized by purpose **New Content:** - Added comprehensive Environment Variable Reference to copilot-instructions.md - 100+ ENV variables documented with types, defaults, purpose, notes - Organized by category: Required (Drift/RPC/Pyth), Trading Config (quality/ leverage/sizing), ATR System, Runner System, Risk Limits, Notifications, etc. - Includes usage examples (correct vs wrong patterns) **File Distribution:** - docs/analysis/ - Performance analyses, blocked signals, profit projections - docs/architecture/ - Adaptive leverage, ATR trailing, indicator tracking - docs/bugs/ - CRITICAL_*.md, FIXES_*.md bug reports (7 files) - docs/cluster/ - EPYC setup, distributed computing docs (3 files) - docs/deployments/ - *_COMPLETE.md, DEPLOYMENT_*.md status (12 files) - docs/roadmaps/ - All *ROADMAP*.md strategic planning files (7 files) - docs/setup/ - TradingView guides, signal quality, n8n setup (8 files) - docs/archived/2025_pre_nov/ - Obsolete verification checklist (1 file) **Key Improvements:** - ENV variable reference: Single source of truth for all configuration - Common Pitfalls #68-71: Already complete, verified during audit - Better findability: Category-based navigation vs 68 files in root - Preserves history: All files git mv (rename), not copy/delete - Zero broken functionality: Only documentation moved, no code changes **Verification:** - 83 markdown files now in docs/ subdirectories - Root directory cleaned: 68 files → 0 files (except README.md) - Git history preserved for all moved files - Container running: trading-bot-v4 (no restart needed) **Next Steps:** - Create README.md files in each docs subdirectory - Add navigation index - Update main README.md with new structure - Consolidate duplicate deployment docs - Archive truly obsolete files (old SQL backups) See: docs/analysis/CLEANUP_PLAN.md for complete reorganization strategy
336 lines
8.1 KiB
Markdown
336 lines
8.1 KiB
Markdown
# 🚨 CLEANUP RECOVERY PLAN
|
|
|
|
## 📋 Pre-Execution State (Backup)
|
|
|
|
**Date:** October 27, 2025
|
|
**Git Commit:** Current HEAD before cleanup
|
|
**System Status:** All containers running
|
|
|
|
### Current Git State
|
|
```bash
|
|
# Get current commit hash
|
|
git rev-parse HEAD
|
|
# This is our recovery point
|
|
```
|
|
|
|
---
|
|
|
|
## 🔄 RECOVERY METHODS
|
|
|
|
### Method 1: Git Revert (Safest - Use This First)
|
|
If anything breaks after cleanup:
|
|
|
|
```bash
|
|
# Find the cleanup commit
|
|
git log --oneline -5
|
|
|
|
# Revert the cleanup commit (replace COMMIT_HASH)
|
|
git revert COMMIT_HASH
|
|
|
|
# This creates a new commit that undoes all file moves
|
|
# System returns to previous state
|
|
```
|
|
|
|
### Method 2: Git Reset (Nuclear Option)
|
|
If git revert doesn't work:
|
|
|
|
```bash
|
|
# Get commit hash BEFORE cleanup
|
|
git log --oneline -10
|
|
|
|
# Reset to commit before cleanup (replace COMMIT_HASH)
|
|
git reset --hard COMMIT_HASH
|
|
|
|
# Force push if already pushed
|
|
git push --force origin master
|
|
```
|
|
|
|
### Method 3: Manual Recovery
|
|
If git fails, manual file restoration:
|
|
|
|
```bash
|
|
# All original file locations are documented below
|
|
# Simply move files back to root directory
|
|
```
|
|
|
|
---
|
|
|
|
## 📍 ORIGINAL FILE LOCATIONS (Pre-Cleanup)
|
|
|
|
### Documentation Files (Currently in Root)
|
|
```
|
|
/home/icke/traderv4/SETUP.md
|
|
/home/icke/traderv4/DOCKER.md
|
|
/home/icke/traderv4/N8N_WORKFLOW_SETUP.md
|
|
/home/icke/traderv4/N8N_DATABASE_SETUP.md
|
|
/home/icke/traderv4/SETTINGS_SETUP.md
|
|
/home/icke/traderv4/TELEGRAM_BOT_README.md
|
|
/home/icke/traderv4/N8N_WORKFLOW_GUIDE.md
|
|
/home/icke/traderv4/TESTING.md
|
|
/home/icke/traderv4/WORKFLOW_VERIFICATION.md
|
|
/home/icke/traderv4/PHASE_1_COMPLETE.md
|
|
/home/icke/traderv4/PHASE_2_COMPLETE.md
|
|
/home/icke/traderv4/PHASE_2_SUMMARY.md
|
|
/home/icke/traderv4/QUICKREF_PHASE2.md
|
|
/home/icke/traderv4/EXIT_ORDERS_TEST_RESULTS.md
|
|
/home/icke/traderv4/TEST_STATUS_COMMAND.md
|
|
/home/icke/traderv4/TELEGRAM_STATUS_IMPLEMENTATION.md
|
|
/home/icke/traderv4/STATUS_COMMAND_QUICKREF.txt
|
|
```
|
|
|
|
### n8n Workflow Files (Currently in Root)
|
|
```
|
|
/home/icke/traderv4/Money_Machine.json
|
|
/home/icke/traderv4/n8n-complete-workflow.json
|
|
/home/icke/traderv4/n8n-daily-report.json
|
|
/home/icke/traderv4/n8n-database-analytics.json
|
|
/home/icke/traderv4/n8n-pattern-analysis.json
|
|
/home/icke/traderv4/n8n-stop-loss-analysis.json
|
|
/home/icke/traderv4/telegram-manual-trade-FINAL.json
|
|
/home/icke/traderv4/telegram-webhook-FINAL.json
|
|
/home/icke/traderv4/n8n-trader-workflow.json
|
|
/home/icke/traderv4/n8n-trader-workflow-updated.json
|
|
/home/icke/traderv4/n8n-workflow-simple.json
|
|
/home/icke/traderv4/telegram-listener-simple.json
|
|
/home/icke/traderv4/telegram-n8n-listener.json
|
|
/home/icke/traderv4/telegram-polling-addon.json
|
|
/home/icke/traderv4/telegram-trigger-addon.json
|
|
```
|
|
|
|
### Shell Scripts (Currently in Root)
|
|
```
|
|
/home/icke/traderv4/docker-build.sh
|
|
/home/icke/traderv4/docker-start.sh
|
|
/home/icke/traderv4/docker-stop.sh
|
|
/home/icke/traderv4/docker-logs.sh
|
|
/home/icke/traderv4/complete_telegram_setup.sh
|
|
/home/icke/traderv4/setup_telegram_bot.sh
|
|
/home/icke/traderv4/GET_BOT_TOKEN.sh
|
|
/home/icke/traderv4/send_trade.sh
|
|
/home/icke/traderv4/trade.sh
|
|
/home/icke/traderv4/test-exit-orders.sh
|
|
```
|
|
|
|
### Test Files (Currently in Root)
|
|
```
|
|
/home/icke/traderv4/test-drift-v4.ts
|
|
/home/icke/traderv4/test-full-flow.ts
|
|
/home/icke/traderv4/test-position-manager.ts
|
|
/home/icke/traderv4/test-price-monitor.ts
|
|
```
|
|
|
|
### Archive Files (Currently in Root)
|
|
```
|
|
/home/icke/traderv4/telegram_trade_bot.py
|
|
/home/icke/traderv4/telegram-to-webhook.py
|
|
/home/icke/traderv4/quick-trade.html
|
|
/home/icke/traderv4/webapp-trade.html
|
|
/home/icke/traderv4/CREATE_NEW_BOT.md
|
|
```
|
|
|
|
---
|
|
|
|
## 🎯 NEW FILE LOCATIONS (Post-Cleanup)
|
|
|
|
Documented in CLEANUP_PLAN.md - see proposed structure
|
|
|
|
---
|
|
|
|
## ✅ VALIDATION CHECKLIST
|
|
|
|
After cleanup, verify these are working:
|
|
|
|
### 1. Docker Containers
|
|
```bash
|
|
docker ps | grep -E "(trading-bot|telegram-trade-bot|postgres)"
|
|
# All 3 should be running
|
|
```
|
|
|
|
### 2. Trading Bot API
|
|
```bash
|
|
curl -s -H "Authorization: Bearer 2a344f0149442c857fb56c038c0c7d1b113883b830bec792c76f1e0efa15d6bb" \
|
|
http://localhost:3001/api/trading/positions | jq .success
|
|
# Should return: true
|
|
```
|
|
|
|
### 3. Telegram Bot
|
|
```bash
|
|
docker logs telegram-trade-bot --tail 5
|
|
# Should show: "🤖 Bot ready! Send commands to your Telegram."
|
|
```
|
|
|
|
### 4. Watch Restart Service
|
|
```bash
|
|
systemctl status trading-bot-restart-watcher.service
|
|
# Should be: active (running)
|
|
```
|
|
|
|
### 5. Critical Files in Root
|
|
```bash
|
|
ls -la /home/icke/traderv4/ | grep -E "(telegram_command_bot.py|watch-restart.sh|docker-compose.yml)"
|
|
# All 3 should exist in root
|
|
```
|
|
|
|
---
|
|
|
|
## 🚨 ROLLBACK PROCEDURE
|
|
|
|
### If System Breaks:
|
|
|
|
**Step 1: Check what's broken**
|
|
```bash
|
|
# Check containers
|
|
docker ps -a | grep trading-bot
|
|
|
|
# Check logs
|
|
docker logs trading-bot-v4 --tail 50
|
|
docker logs telegram-trade-bot --tail 50
|
|
|
|
# Check systemd
|
|
systemctl status trading-bot-restart-watcher.service
|
|
```
|
|
|
|
**Step 2: Quick Fix (If Docker Issue)**
|
|
```bash
|
|
# Restart containers
|
|
docker-compose down
|
|
docker-compose up -d
|
|
|
|
# Restart telegram bot
|
|
docker-compose -f docker-compose.telegram-bot.yml down
|
|
docker-compose -f docker-compose.telegram-bot.yml up -d
|
|
```
|
|
|
|
**Step 3: Git Revert (If Files Missing)**
|
|
```bash
|
|
# See recent commits
|
|
git log --oneline -5
|
|
|
|
# Revert the cleanup commit
|
|
git revert HEAD
|
|
|
|
# Verify files back
|
|
ls -la *.md *.json *.sh
|
|
```
|
|
|
|
**Step 4: Nuclear Option (If All Else Fails)**
|
|
```bash
|
|
# Get commit before cleanup
|
|
BEFORE_CLEANUP=$(git log --oneline -10 | grep "Add /status" | cut -d' ' -f1)
|
|
|
|
# Reset to that commit
|
|
git reset --hard $BEFORE_CLEANUP
|
|
|
|
# Restart everything
|
|
docker-compose down
|
|
docker-compose up -d
|
|
```
|
|
|
|
---
|
|
|
|
## 📊 SYSTEM STATE SNAPSHOT
|
|
|
|
### Before Cleanup:
|
|
- **Containers Running:** 3 (trading-bot-v4, telegram-trade-bot, postgres)
|
|
- **Services Active:** trading-bot-restart-watcher.service
|
|
- **API Status:** Responding on port 3001
|
|
- **Files in Root:** 87 files (docs, scripts, workflows mixed)
|
|
|
|
### Expected After Cleanup:
|
|
- **Containers Running:** 3 (no change - containers don't rebuild)
|
|
- **Services Active:** trading-bot-restart-watcher.service (no change)
|
|
- **API Status:** Responding on port 3001 (no change)
|
|
- **Files in Root:** ~30 files (only essential configs)
|
|
|
|
---
|
|
|
|
## 🔍 WHAT CAN'T BREAK
|
|
|
|
These will NOT be affected by cleanup:
|
|
- ✅ Running containers (not rebuilding)
|
|
- ✅ Database data (no schema changes)
|
|
- ✅ Environment variables (no changes)
|
|
- ✅ Docker networks (no changes)
|
|
- ✅ Active trades (Position Manager in memory)
|
|
- ✅ Systemd service (file it references stays in root)
|
|
|
|
---
|
|
|
|
## 📝 COMMIT MESSAGE
|
|
|
|
Will use this format:
|
|
```
|
|
chore: Organize workspace structure - move docs, workflows, scripts to subdirectories
|
|
|
|
- Created docs/ for all documentation (setup, guides, history)
|
|
- Created workflows/ for n8n JSON files (trading, analytics, telegram, archive)
|
|
- Created scripts/ for shell scripts (docker, setup, testing)
|
|
- Created tests/ for TypeScript test files
|
|
- Created archive/ for unused reference files
|
|
- Updated README.md documentation links
|
|
- Deleted empty directories (data, screenshots)
|
|
|
|
All critical files remain in root:
|
|
- telegram_command_bot.py (active bot)
|
|
- watch-restart.sh (systemd service)
|
|
- Dockerfiles and docker-compose files
|
|
- Environment files
|
|
|
|
No code changes - purely organizational.
|
|
System continues running without interruption.
|
|
|
|
Recovery: git revert HEAD to restore previous structure
|
|
```
|
|
|
|
---
|
|
|
|
## ⚡ EXECUTION LOG
|
|
|
|
Will document each step as executed:
|
|
1. [ ] Created directory structure
|
|
2. [ ] Moved documentation files
|
|
3. [ ] Moved workflow files
|
|
4. [ ] Moved script files
|
|
5. [ ] Moved test files
|
|
6. [ ] Moved archive files
|
|
7. [ ] Updated README.md
|
|
8. [ ] Deleted empty directories
|
|
9. [ ] Validated system still working
|
|
10. [ ] Git commit and push
|
|
|
|
---
|
|
|
|
## 🎯 FINAL SAFETY NET
|
|
|
|
**Before starting:**
|
|
```bash
|
|
# Create a manual backup tag
|
|
git tag -a cleanup-before -m "State before workspace cleanup - recovery point"
|
|
git push origin cleanup-before
|
|
```
|
|
|
|
**To recover using tag:**
|
|
```bash
|
|
git reset --hard cleanup-before
|
|
```
|
|
|
|
---
|
|
|
|
## ✅ READY TO PROCEED
|
|
|
|
This recovery plan provides:
|
|
- 3 different recovery methods
|
|
- Complete file location documentation
|
|
- Validation checklist
|
|
- Step-by-step rollback procedure
|
|
- Git tag as safety net
|
|
|
|
**Shall I:**
|
|
1. Create the git tag (safety net)
|
|
2. Execute the cleanup
|
|
3. Validate everything works
|
|
4. Commit with detailed message
|
|
5. Push to remote
|
|
|
|
Type "proceed" to start, or any concerns to address first.
|