import os
import datetime

class Config:
    # Server settings
    PORT = 9527
    HOST = "0.0.0.0"
    DEBUG = False

    # Trading settings
    TRADE_TIMEOUT = 5  # 交易超时时间（秒）
    SIMULATION_MODE = False

    # Trading hours
    MARKET_OPEN_TIME = "09:10"
    MARKET_CLOSE_TIME = "15:10"

    # Logging
    LOG_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "logs")
    LOG_LEVEL = "INFO"
    LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
    LOG_MAX_BYTES = 10 * 1024 * 1024  # 10MB
    LOG_BACKUP_COUNT = 10

    # strategy data
    DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "data")

    # API Rate limiting
    RATE_LIMIT_REQUESTS = 100
    RATE_LIMIT_PERIOD = 60  # seconds

    # XtQuant 相关配置
    XT_ACCOUNT = "80391818"
    XT_PATH = r'C:\\江海证券QMT实盘_交易\\userdata_mini'
    XT_LAUNCHER = r'C:\\江海证券QMT实盘_交易\\bin.x64\\XtItClient.exe'
    XT_PROCESS1 = r'miniquote.exe'
    XT_PROCESS2 = r'XtMiniQmt.exe'
    XT_RESTART_TIME = "09:00"
    
    # 重连相关配置
    XT_RECONNECT_INTERVAL = 3600  # 重连尝试间隔（秒）
    XT_MAX_SESSION_ID = 999999  # 最大会话ID
    XT_MIN_SESSION_ID = 100000  # 最小会话ID
    XT_SESSION_ID_RANGE = 20  # 一次尝试的会话ID数量
    
    # 邮件通知配置
    MAIL_ENABLED = True
    MAIL_SERVER = "mail.yushaoyou.com"
    MAIL_PORT = 465
    MAIL_USERNAME = "jq@yushaoyou.com"
    MAIL_PASSWORD = "zhiyong214"
    MAIL_FROM = "自动交易服务器"
    MAIL_TO = ["jq@yushaoyou.com"]  # 可以是多个邮箱
    
    # RealTraderManager配置
    RTM_ORDER_TIMEOUT = 10  # 订单超时时间（秒）
    RTM_USE_MARKET_ORDER = True  # 是否使用市价单进行补单

    # 撤销订单超时时间（秒）
    RTM_CANCEL_TIMEOUT = 10 

    # 计划任务运行时间
    CLEAN_ORDERS_TIME = "15:05"  # 每天清理超时委托的时间
    STRATEGY_SAVE_TIME = "15:08"  # 每天保存策略数据的时间
