1. 创建 QApplication
调用 create_qapp() 创建图形界面应用。
以下为 vnpy 官方 README 提供的首次运行脚本(2026-08 核验)。
from vnpy.event import EventEngine
from vnpy.trader.engine import MainEngine
from vnpy.trader.ui import MainWindow, create_qapp
from vnpy_ctp import CtpGateway
from vnpy_ctastrategy import CtaStrategyApp
from vnpy_ctabacktester import CtaBacktesterApp
def main():
# Start VeighNa Trader
qapp = create_qapp()
event_engine = EventEngine()
main_engine = MainEngine(event_engine)
main_engine.add_gateway(CtpGateway)
main_engine.add_app(CtaStrategyApp)
main_engine.add_app(CtaBacktesterApp)
main_window = MainWindow(main_engine, event_engine)
main_window.showMaximized()
qapp.exec()
if __name__ == "__main__":
main()python run.py 启动 VeighNa Trader。按官方示例拆解,便于理解每一步的作用。
调用 create_qapp() 创建图形界面应用。
创建 EventEngine 事件引擎与 MainEngine 主引擎。
add_gateway 接入交易接口(如 CtpGateway),add_app 添加策略应用(如 CtaStrategyApp、CtaBacktesterApp)。
创建 MainWindow 并最大化显示,运行 python run.py 进入 VeighNa Trader。