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

from vnpy.app.script_trader import init_cli_trading
from vnpy.app.script_trader.cli import process_log_event
from vnpy.gateway.ctp import CtpGateway
from vnpy.trader.constant import OrderType

setting = {
"用户名": "XXXX",
"密码": "XXXX",
"经纪商代码": "9999",
"交易服务器":"tcp://218.202.237.33 :10102",
"行情服务器":"tcp://218.202.237.33 :10112",
"产品名称":"simnow_client_test",
"授权编码":"0000000000000000",
"产品信息": ""
}

engine = init_cli_trading([CtpGateway])
engine.connect_gateway(setting,"CTP")
from time import sleep
from vnpy.app.script_trader import ScriptEngine
sleep(10)
print("查询资金和持仓")
print(engine.get_all_accounts(use_df = True))

查询持仓

print(engine.get_all_positions(use_df = True))

from vnpy.app.cta_strategy import CtaStrategyApp
from vnpy.app.cta_strategy.base import EVENT_CTA_LOG
engine.event_engine.register(EVENT_CTA_LOG, process_log_event)
cta_engine = engine.main_engine.add_app(CtaStrategyApp) #加入app
cta_engine.init_engine()
cta_engine.add_strategy("DoubleMaStrategy","demo_test_dd", "rb2010.SHFE",{"fast_window":1, "slow_window": 5})
sleep(10)
cta_engine.init_strategy("demo_test_dd")
sleep(10)
cta_engine.start_strategy("demo_test_dd")

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

新手,不会用,多谢指点

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3