[Add] demo_script.py for ScriptTrader
This commit is contained in:
parent
2125bc6a27
commit
afa7f1a227
27
examples/vn_trader/demo_script.py
Normal file
27
examples/vn_trader/demo_script.py
Normal file
@ -0,0 +1,27 @@
|
||||
from time import sleep
|
||||
from vnpy.app.script_trader import ScriptEngine
|
||||
|
||||
|
||||
def run(engine: ScriptEngine):
|
||||
""""""
|
||||
vt_symbols = ["IF1912.CFFEX", "rb2001.SHFE"]
|
||||
|
||||
# 订阅行情
|
||||
engine.subscribe(vt_symbols)
|
||||
|
||||
# 获取合约信息
|
||||
for vt_symbol in vt_symbols:
|
||||
contract = engine.get_contract(vt_symbol)
|
||||
msg = f"合约信息,{contract}"
|
||||
engine.write_log(msg)
|
||||
|
||||
# 持续运行,使用strategy_active来判断是否要退出程序
|
||||
while engine.strategy_active:
|
||||
# 轮询获取行情
|
||||
for vt_symbol in vt_symbols:
|
||||
tick = engine.get_tick(vt_symbol)
|
||||
msg = f"最新行情, {tick}"
|
||||
engine.write_log(msg)
|
||||
|
||||
# 等待3秒进入下一轮
|
||||
sleep(3)
|
Loading…
Reference in New Issue
Block a user