28 lines
749 B
Python
28 lines
749 B
Python
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)
|