启动Station之后,执行run.py
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()
如果用“在该目录下打开CMD(按住Shift->点击鼠标右键->在此处打开命令窗口/PowerShell)后运行下列命令启动VeighNa Trader: python run.py”的方式启动,可以执行。
如果在vscode执行run.py,
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
就会报错No module named 'vnpy'
请问怎么设置才能直接在vscode里启动呢,在vscode里启动才能加断点调试
或者用cmd执行的话,怎么加断点?
用cmd执行后,附加断点Attach using Process Id,附加到" python.exe" run.py 并设置 "justMyCode": false
可以断点了。
有用vscode直接执行的嘛?
报错为:
2022-12-19 21:24:10.013930 策略交易脚本启动
2022-12-19 21:24:14.682423 触发异常已停止
Traceback (most recent call last):
File "C:\veighna_studio\lib\site-packages\vnpy_scripttrader\engine.py", line 79, in run_strategy
module.run(self)
File "C:\veighna_studio\code\test1.py", line 24, in run
api.wait_update()
File "C:\veighna_studio\lib\site-packages\tqsdk\api.py", line 1872, in wait_update
self._run_until_idle(async_run=False)
File "C:\veighna_studio\lib\site-packages\tqsdk\baseApi.py", line 65, in _run_until_idle
check_handle = self._loop.call_soon(self._check_event, self._event_rev + 1)
File "C:\veighna_studio\lib\site-packages\tqsdk\baseApi.py", line 50, in _call_soon
return org_call_soon(callback, *args, **kargs)
File "C:\veighna_studio\lib\asyncio\base_events.py", line 745, in call_soon
self._check_closed()
File "C:\veighna_studio\lib\asyncio\base_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
代码:
api = TqApi(auth=",")
# 设置twap任务参数、
target_twap = Twap(api,"SHFE.fu2305","BUY","OPEN",20,300,1,5)
# 启动循环
while True:
api.wait_update()
if target_twap.is_finished():
break
api.close()
是连simnow的7*24小时环境测试的,请问是因为啥。。。