#!/usr/bin/env python3
"""
Quick backup and check of candlestick bot
"""
import shutil
import os

def backup_file(src, dst):
    if os.path.exists(src):
        shutil.copy2(src, dst)
        print(f"✅ 备份完成: {src} → {dst}")
        return True
    else:
        print(f"❌ 文件不存在: {src}")
        return False

def check_bot_file():
    bot_path = '/root/quant_pipeline/candle_bot.py'
    
    print("=" * 60)
    print("检查 candlestick bot 文件")
    print("=" * 60)
    
    if os.path.exists(bot_path):
        print("✅ 文件存在: candle_bot.py")
        file_size = os.path.getsize(bot_path)
        print(f"   文件大小: {file_size} 字节")
        
        with open(bot_path, 'r', encoding='utf-8') as f:
            content = f.read()
            line_count = len(content.split('\n'))
            print(f"   文件行数: {line_count}")
            
        key_functions = ['check_sig', 'get_candles', 'get_trend', 'order', 'log']
        found_funcs = []
        for func in key_functions:
            if f"def {func}(" in content:
                found_funcs.append(func)
        
        print(f"   核心函数检查: {found_funcs}")
        
        if "烛龙 v1.2" in content:
            print("   ✅ 版本: v1.2 (正确)")
        elif "烛龙 v1.1" in content:
            print("   ⚠️  版本: v1.1 (需要更新)")
        else:
            print("   ❓ 版本: 未知")
        
        if "只加不减" in content:
            print("   ✅ 策略: 只加不减")
        else:
            print("   ❓ 策略: 未找到")
        
    else:
        print(f"❌ 文件不存在: {bot_path}")
        return False
    
    print("=" * 60)
    print("检查完成")
    print("=" * 60)
    print("\n📝 下一步操作：")
    print("1. 运行测试: python /root/quant_pipeline/candle_bot.py --dry-run")
    print("2. 确认策略和逻辑无误后，正式上线 real")
    print("3. 开始自动交易...")
    
    return True

def main():
    backup_file('/root/quant_pipeline/candle_bot.py', '/root/quant_pipeline/candle_bot_v1.1_backup.py')
    check_bot_file()

if __name__ == "__main__":
    main()