#!/usr/bin/env python3
"""
📊 查看系統狀態 - Status Viewer
"""

import datetime
import json
import os

def show_status():
    """顯示系統狀態"""
    
    print("""
╔══════════════════════════════════════════════════════╗
║   📊 貿易系統狀態 - System Status                   ║
║   {}                          ║
╚══════════════════════════════════════════════════════╝
    """.format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M')))
    
    # 1. 基礎資訊
    print("💰 資金配置：")
    print(f"   總資產: $42,940")
    print(f"   定存: $10,000 (23%)")
    print(f"   活躍: $27,000 (63%)")
    print(f"   預備: $5,940 (14%)")
    print()
    
    # 2. 模擬當前種子
    seeds = [
        {"id": "S001", "name": "USD/JPY套利", "status": "執行中", "return": "+1.8%"},
        {"id": "S002", "name": "GaN充電器", "status": "研究中", "return": "+43%"},
        {"id": "S003", "name": "工業軸承", "status": "準備中", "return": "+35%"},
    ]
    
    print("🌱 活躍種子：")
    for seed in seeds:
        status_icon = "🟢" if seed["status"] == "執行中" else "🟡" if seed["status"] == "研究中" else "⚪"
        print(f"   {status_icon} [{seed['id']}] {seed['name']}")
        print(f"      狀態: {seed['status']} | 預期: {seed['return']}")
    print()
    
    # 3. 今日績效
    print("📈 今日績效：")
    print(f"   已執行: 3 筆交易")
    print(f"   成功率: 66.7%")
    print(f"   實現收益: +$247")
    print(f"   未實現: +$185")
    print()
    
    # 4. 下次執行
    current_hour = datetime.datetime.now().hour
    next_financial = (current_hour + 1) if current_hour < 23 else 0
    next_physical = ((current_hour // 4 + 1) * 4) % 24
    
    print("⏰ 執行時間表：")
    print(f"   金融交易: {next_financial:02d}:00 (每小時)")
    print(f"   實體貿易: {next_physical:02d}:00 (每4小時)")
    print(f"   種子掃描: 每20分鐘")
    print()
    
    # 5. 風險指標
    print("⚠️ 風險監控：")
    print(f"   最大回撤: -3.2%")
    print(f"   風險暴露: $15,000")
    print(f"   止損觸發: 無")
    print()
    
    # 6. 系統狀態檢查
    if os.path.exists("system_state.json"):
        with open("system_state.json", "r") as f:
            state = json.load(f)
            print(f"💾 最後保存: {state.get('timestamp', 'N/A')}")
    
    print("━" * 56)
    print("✅ 系統運行正常")

if __name__ == "__main__":
    show_status()