#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
用户: {{username}}
交易进程启动脚本 - 启动RPC服务端
"""

from vnpy.trader.event_engine import EventEngine
from vnpy.trader.main_engine import MainEngine
from vnpy.rpc import RpcServer
# 导入需要的gateway
# from vnpy_ctp import CtpGateway
# from vnpy_ib import IbGateway
# 导入需要的app
# from vnpy_ctastrategy import CtaStrategyApp

def main():
    # 创建核心引擎
    event_engine = EventEngine()
    main_engine = MainEngine(event_engine)
    
    # 添加gateway
    # main_engine.add_gateway(CtpGateway)
    # main_engine.add_gateway(IbGateway)
    
    # 添加应用模块
    # main_engine.add_app(CtaStrategyApp)
    # main_engine.add_app(PortfolioStrategyApp)
    
    # 启动RPC服务
    rpc_request_port = {{rpc_request_port}}
    rpc_subscribe_port = {{rpc_subscribe_port}}
    
    rpc_server = RpcServer(
        main_engine,
        ("0.0.0.0", rpc_request_port),
        ("0.0.0.0", rpc_subscribe_port)
    )
    rpc_server.start()
    
    print(f"[{username}] RPC服务已启动")
    print(f"- 请求地址: tcp://0.0.0.0:{rpc_request_port}")
    print(f"- 订阅地址: tcp://0.0.0.0:{rpc_subscribe_port}")
    print("按回车键退出...")
    input()

if __name__ == "__main__":
    main()
