vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 2
声望: 0

请问如何在Linux下命令行使用vnpy进行实盘交易呢?

Administrator
avatar
加入于:
帖子: 3810
声望: 199

https://github.com/vnpy/vnpy/blob/master/examples/no_ui/run.py

参考这个无界面模式下的vn.py例子

Member
avatar
加入于:
帖子: 1
声望: 0

请问能否写个no_ui 运行script engine的例子?包括连接交易所和执行代码两部分。

示例代码 http://www.vnpy.com/docs/cn/script_trader.html
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)
© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3