Files
uniswap_auto_clp/florida/tools/README_GIT_AGENT.md

5.6 KiB

Git Agent for Uniswap Auto CLP

Overview

Automated backup and version control system for your Uniswap Auto CLP trading bot.

Quick Setup

1. Initialize Repository

# Navigate to project directory
cd K:\Projects\uniswap_auto_clp

# Create initial commit
python tools\git_agent.py --init

# Add and push initial setup
git add .
git commit -m "🎯 Initial commit: Uniswap Auto CLP system"
git remote add origin https://git.kapuscinski.pl/ditus/uniswap_auto_clp.git
git push -u origin main

2. Create First Backup

# Test backup creation
python tools\git_agent.py --backup

3. Check Status

# View current status
python tools\git_agent.py --status

Configuration

Edit tools/agent_config.json as needed:

{
  "backup": {
    "enabled": true,
    "frequency_hours": 1,
    "keep_max_count": 100,
    "push_to_remote": true
  }
}

Usage Commands

Manual Operations

# Create backup now
python tools\git_agent.py --backup

# Check status
python tools\git_agent.py --status

# Cleanup old backups
python tools\git_agent.py --cleanup

# Initialize repository (one-time)
python tools\git_agent.py --init

Automated Scheduling

Windows Task Scheduler

# Create hourly task
schtasks /create /tn "Git Backup" /tr "python tools\git_agent.py --backup" /sc hourly

Linux Cron (if needed)

# Add to crontab
0 * * * * cd /path/to/project && python tools/git_agent.py --backup

How It Works

Branch Strategy

  • main branch: Your manual development (you control pushes)
  • backup- branches*: Automatic hourly backups (agent managed)

Backup Process

  1. Hourly: Agent checks for file changes
  2. Creates backup branch: Named backup-YYYY-MM-DD-HH
  3. Commits changes: With detailed file and parameter tracking
  4. Pushes to remote: Automatic backup to Gitea
  5. Cleans up: Keeps only last 100 backups

Backup Naming

backup-2025-01-15-14  # 2 PM backup on Jan 15, 2025
backup-2025-01-15-15  # 3 PM backup
backup-2025-01-15-16  # 4 PM backup

Commit Messages

Agent creates detailed commit messages showing:

  • Files changed with status icons
  • Parameter changes with percentage differences
  • Security validation confirmation
  • Timestamp and backup number

Security

What's Excluded

Private keys and tokens (.env files)
Log files (*.log)
State files (hedge_status.json)
Temporary files

What's Included

All code changes
Configuration modifications
Documentation updates
Parameter tracking

Emergency Recovery

Quick Rollback

# List recent backups
python tools\git_agent.py --status

# Switch to backup
git checkout backup-2025-01-15-14

# Copy files to main
git checkout main -- .
git commit -m "🔄 Emergency restore from backup-2025-01-15-14"
git push origin main

File Recovery

# Restore specific file from backup
git checkout backup-2025-01-15-14 -- path/to/file.py

Monitoring

Backup Health

# Check backup count and status
python tools\git_agent.py --status

# Expected output:
# 📊 Git Agent Status:
#    Current Branch: main
#    Backup Count: 47
#    Has Changes: false
#    Remote Connected: true
#    Last Backup: backup-2025-01-15-16

Manual Cleanup

# Remove old backups (keeps last 100)
python tools\git_agent.py --cleanup

Troubleshooting

Common Issues

"Configuration file not found"

# Ensure agent_config.json exists in tools/ directory
ls tools/agent_config.json

"Git command failed"

# Check Git installation and repository status
git status
git --version

"Remote connection failed"

# Verify Gitea URL and credentials
git remote -v
ping git.kapuscinski.pl

Debug Mode

Edit agent_config.json:

{
  "logging": {
    "enabled": true,
    "log_level": "DEBUG"
  }
}

Then check git_agent.log in project root.

Integration with Trading Bot

Parameter Changes

Agent automatically tracks changes to:

  • TARGET_INVESTMENT_VALUE_USDC
  • RANGE_WIDTH_PCT
  • SLIPPAGE_TOLERANCE
  • LEVERAGE
  • CHECK_INTERVAL
  • PRICE_BUFFER_PCT

Backup Triggers

Consider manual backups when:

  • Changing trading strategy parameters
  • Updating risk management settings
  • Before major system changes
  • After successful backtesting
# Manual backup before important changes
python tools\git_agent.py --backup

Best Practices

Development Workflow

  1. Work on main branch for normal development
  2. Manual commits for your changes
  3. Agent handles backups automatically
  4. Manual push to main when ready

Backup Management

  • 100 backup limit = ~4 days of hourly coverage
  • Automatic cleanup maintains repository size
  • Remote storage provides offsite backup

Security Reminders

  • Never commit private keys (automatically excluded)
  • Check .gitignore if adding sensitive files
  • Review backup commits for accidental secrets

Support

Log Files

  • git_agent.log: Agent activity and errors
  • Check logs for troubleshooting issues

Repository Structure

tools/
├── git_agent.py          # Main automation script
├── agent_config.json     # Configuration settings
├── git_utils.py         # Git operations
├── backup_manager.py     # Backup branch logic
├── change_detector.py    # Change analysis
├── cleanup_manager.py    # Backup rotation
└── commit_formatter.py  # Message formatting

This automated backup system ensures your trading bot code is always versioned and recoverable, while keeping your main development workflow clean and manual.