Enhancement #4: Failed Revenge Tracking - Added 3 database fields: revengeOutcome, revengePnL, revengeFailedReason - Added updateRevengeOutcome() method in stop-hunt-tracker.ts - Position Manager hooks revenge trade closes, records outcome - Enables data-driven analysis of revenge success rate Enhancement #10: Metadata Persistence - Added 4 database fields: firstCrossTime, lowestInZone, highestInZone, zoneResetCount - Migrated 90-second zone tracking from in-memory to database - Rewrote shouldExecuteRevenge() with database persistence - Container restarts now preserve exact zone tracking state Technical Details: - Prisma schema updated with 7 new StopHunt fields - Added signalSource field to ActiveTrade interface - All zone metadata persisted in real-time to database - Build verified successful (no TypeScript errors) Files Changed: - prisma/schema.prisma (StopHunt model + index) - lib/trading/stop-hunt-tracker.ts (DB persistence + outcome tracking) - lib/trading/position-manager.ts (revenge hook + interface) - docs/REVENGE_ENHANCEMENTS_EXPLAINED.md (comprehensive guide) Pending User Decision: - Enhancement #1: ADX confirmation (3 options explained in docs) - Enhancement #6: SL distance validation (2× ATR recommended) Status: Ready for deployment after Prisma migration Date: Nov 27, 2025
94 lines
3.2 KiB
Bash
Executable File
94 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Trading Bot v4 - Automated Docker Cleanup Script
|
|
# Runs after builds to keep only last 2 images and prune dangling resources
|
|
# Usage: ./cleanup_trading_bot.sh (or add to cron: 0 2 * * * /home/icke/traderv4/cleanup_trading_bot.sh)
|
|
|
|
set -e
|
|
|
|
echo "🧹 Trading Bot v4 - Docker Cleanup"
|
|
echo "======================================"
|
|
echo ""
|
|
|
|
# Function to format bytes to human-readable
|
|
format_size() {
|
|
numfmt --to=iec-i --suffix=B "$1" 2>/dev/null || echo "$1 bytes"
|
|
}
|
|
|
|
# Check disk space before cleanup
|
|
echo "📊 Disk space BEFORE cleanup:"
|
|
df -h / | tail -1
|
|
echo ""
|
|
|
|
# Get current space usage
|
|
BEFORE_IMAGES=$(docker system df --format "{{.Size}}" | head -1 | sed 's/[^0-9.]//g' | awk '{print $1}')
|
|
BEFORE_BUILD_CACHE=$(docker system df --format "{{.Size}}" | sed -n 3p | sed 's/[^0-9.]//g' | awk '{print $1}')
|
|
|
|
echo "💾 Docker resources BEFORE cleanup:"
|
|
docker system df
|
|
echo ""
|
|
|
|
# Keep only last 2 trading-bot images (for rollback safety)
|
|
echo "🗑️ Step 1: Keeping last 2 trading-bot images, removing older ones..."
|
|
IMAGES_TO_REMOVE=$(docker images traderv4-trading-bot --format "{{.ID}}" | tail -n +3)
|
|
if [ -n "$IMAGES_TO_REMOVE" ]; then
|
|
echo "$IMAGES_TO_REMOVE" | xargs docker rmi -f 2>/dev/null || true
|
|
echo "✅ Removed $(echo "$IMAGES_TO_REMOVE" | wc -l) old trading-bot image(s)"
|
|
else
|
|
echo "✅ No old trading-bot images to remove (keeping last 2)"
|
|
fi
|
|
echo ""
|
|
|
|
# Remove dangling images (untagged layers from builds)
|
|
echo "🗑️ Step 2: Removing dangling images..."
|
|
DANGLING=$(docker images -f "dangling=true" -q)
|
|
if [ -n "$DANGLING" ]; then
|
|
docker image prune -f
|
|
echo "✅ Removed dangling images"
|
|
else
|
|
echo "✅ No dangling images found"
|
|
fi
|
|
echo ""
|
|
|
|
# Prune build cache (biggest space saver - 40GB typical)
|
|
echo "🗑️ Step 3: Pruning build cache..."
|
|
docker builder prune -f
|
|
echo "✅ Build cache pruned"
|
|
echo ""
|
|
|
|
# Optional: Remove dangling volumes (be careful - only if no important data)
|
|
echo "🗑️ Step 4: Checking for dangling volumes..."
|
|
DANGLING_VOLUMES=$(docker volume ls -f "dangling=true" -q | grep -v "trading-bot-postgres" || true)
|
|
if [ -n "$DANGLING_VOLUMES" ]; then
|
|
echo "⚠️ Found dangling volumes (excluding postgres):"
|
|
echo "$DANGLING_VOLUMES"
|
|
echo "⚠️ Skipping volume cleanup for safety (run 'docker volume prune -f' manually if needed)"
|
|
else
|
|
echo "✅ No dangling volumes found"
|
|
fi
|
|
echo ""
|
|
|
|
# Show space saved
|
|
echo "📊 Disk space AFTER cleanup:"
|
|
df -h / | tail -1
|
|
echo ""
|
|
|
|
echo "💾 Docker resources AFTER cleanup:"
|
|
docker system df
|
|
echo ""
|
|
|
|
# Calculate space freed (approximate)
|
|
AFTER_IMAGES=$(docker system df --format "{{.Size}}" | head -1 | sed 's/[^0-9.]//g' | awk '{print $1}')
|
|
AFTER_BUILD_CACHE=$(docker system df --format "{{.Size}}" | sed -n 3p | sed 's/[^0-9.]//g' | awk '{print $1}')
|
|
|
|
echo "✅ Cleanup complete!"
|
|
echo ""
|
|
echo "💡 Tips:"
|
|
echo " - Run after each build: docker compose build && ./cleanup_trading_bot.sh"
|
|
echo " - Add to cron: 0 2 * * * /home/icke/traderv4/cleanup_trading_bot.sh"
|
|
echo " - BuildKit auto-cleanup kicks in at 20GB threshold (daemon.json)"
|
|
echo ""
|
|
echo "🔒 Safety measures:"
|
|
echo " - Keeps last 2 trading-bot images for rollback"
|
|
echo " - Never touches named volumes (postgres data safe)"
|
|
echo " - Never removes running containers"
|