Files
uniswap_auto_clp/tools/README_GIT_AGENT.md
DiTus 5ca16ec33f 🎯 Initial commit: Uniswap Auto CLP trading system
Core Components:
- uniswap_manager.py: V3 concentrated liquidity position manager
- clp_hedger.py: Hyperliquid perpetuals hedging bot
- requirements.txt: Python dependencies
- .gitignore: Security exclusions for sensitive data
- doc/: Project documentation
- tools/: Utility scripts and Git agent

Features:
- Automated liquidity provision on Uniswap V3 (WETH/USDC)
- Delta-neutral hedging using Hyperliquid perpetuals
- Position lifecycle management (open/close/rebalance)
- Automated backup and version control system

Security:
- Private keys and tokens excluded from version control
- Environment variables properly handled
- Automated security validation for backups

Git Agent:
- Hourly automated backups to separate branches
- Keep last 100 backups (~4 days coverage)
- Detailed change tracking and parameter monitoring
- Push to Gitea server automatically
- Manual main branch control preserved
- No performance tracking for privacy
- No notifications for simplicity

Files Added:
- git_agent.py: Main automation script
- agent_config.json: Configuration with Gitea settings
- git_utils.py: Git operations wrapper
- backup_manager.py: Backup branch management
- change_detector.py: File change analysis
- cleanup_manager.py: 100-backup rotation
- commit_formatter.py: Detailed commit messages
- README_GIT_AGENT.md: Complete usage documentation
2025-12-19 20:30:48 +01:00

262 lines
5.6 KiB
Markdown

# 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
```bash
# 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
```bash
# Test backup creation
python tools\git_agent.py --backup
```
### 3. Check Status
```bash
# View current status
python tools\git_agent.py --status
```
## Configuration
Edit `tools/agent_config.json` as needed:
```json
{
"backup": {
"enabled": true,
"frequency_hours": 1,
"keep_max_count": 100,
"push_to_remote": true
}
}
```
## Usage Commands
### Manual Operations
```bash
# 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
```powershell
# Create hourly task
schtasks /create /tn "Git Backup" /tr "python tools\git_agent.py --backup" /sc hourly
```
#### Linux Cron (if needed)
```bash
# 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
```bash
# 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
```bash
# Restore specific file from backup
git checkout backup-2025-01-15-14 -- path/to/file.py
```
## Monitoring
### Backup Health
```bash
# 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
```bash
# Remove old backups (keeps last 100)
python tools\git_agent.py --cleanup
```
## Troubleshooting
### Common Issues
#### "Configuration file not found"
```bash
# Ensure agent_config.json exists in tools/ directory
ls tools/agent_config.json
```
#### "Git command failed"
```bash
# Check Git installation and repository status
git status
git --version
```
#### "Remote connection failed"
```bash
# Verify Gitea URL and credentials
git remote -v
ping git.kapuscinski.pl
```
### Debug Mode
Edit `agent_config.json`:
```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
```bash
# 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.