🎯 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
This commit is contained in:
2025-12-19 20:30:48 +01:00
commit 5ca16ec33f
18 changed files with 4207 additions and 0 deletions

89
tools/backup_manager.py Normal file
View File

@ -0,0 +1,89 @@
#!/usr/bin/env python3
"""
Backup Manager for Git Agent
Handles backup branch creation and management
"""
import os
import logging
from datetime import datetime, timezone
from typing import Dict, Any
class BackupManager:
"""Manages backup branch operations"""
def __init__(self, config: Dict[str, Any], logger: logging.Logger):
self.config = config
self.logger = logger
self.backup_config = config.get('backup', {})
self.prefix = self.backup_config.get('branch_prefix', 'backup-')
def create_backup_branch(self) -> str:
"""Create a new backup branch with timestamp"""
timestamp = datetime.now(timezone.utc)
branch_name = f"{self.prefix}{timestamp.strftime('%Y-%m-%d-%H')}"
# Get current directory from git utils
current_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Create backup branch
import subprocess
try:
# Create and checkout new branch
result = subprocess.run(
['git', 'checkout', '-b', branch_name],
cwd=current_dir,
capture_output=True,
text=True,
check=False
)
if result.returncode == 0:
self.logger.info(f"✅ Created backup branch: {branch_name}")
return branch_name
else:
# Branch might already exist, just checkout
result = subprocess.run(
['git', 'checkout', branch_name],
cwd=current_dir,
capture_output=True,
text=True,
check=False
)
if result.returncode == 0:
self.logger.info(f"✅ Using existing backup branch: {branch_name}")
return branch_name
else:
self.logger.error(f"❌ Failed to create/checkout backup branch: {result.stderr}")
return None
except Exception as e:
self.logger.error(f"❌ Exception creating backup branch: {e}")
return None
def get_backup_count(self) -> int:
"""Get current number of backup branches"""
current_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
try:
result = subprocess.run(
['git', 'branch', '-a'],
cwd=current_dir,
capture_output=True,
text=True,
check=False
)
if result.returncode == 0:
branches = result.stdout.strip().split('\n')
backup_branches = [
b.strip().replace('* ', '').replace('remotes/origin/', '')
for b in branches
if b.strip() and self.prefix in b
]
return len(backup_branches)
except Exception as e:
self.logger.error(f"❌ Error counting backup branches: {e}")
return 0