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

需求:在纯Python环境下,通过simnow账号,获取行情数据
问题描述:使用图形界面,可以看到行情更新,但是在脚本中,日志显示可以正确连接服务器,却获取不到行情,一直是None.
代码如下:

from vnpy.app.script_trader import ScriptEngine
from vnpy.app.script_trader import init_cli_trading
from vnpy.gateway.ctp import CtpGateway
from time import sleep

import sys
import importlib
import traceback
from typing import Sequence, Any
from pathlib import Path
from datetime import datetime
from threading import Thread

from pandas import DataFrame

from vnpy.event import Event, EventEngine
from vnpy.trader.engine import BaseEngine, MainEngine
from vnpy.trader.constant import Direction, Offset, OrderType, Interval
from vnpy.trader.object import (
    OrderRequest,
    HistoryRequest,
    SubscribeRequest,
    TickData,
    OrderData,
    TradeData,
    PositionData,
    AccountData,
    ContractData,
    LogData,
    BarData
)
from vnpy.trader.rqdata import rqdata_client

APP_NAME = "ScriptTrader"

EVENT_SCRIPT_LOG = "eScriptLog"

engine = init_cli_trading([CtpGateway])

setting = {
    "用户名": "xxx",
    "密码": "xxx",
    "经纪商代码": "9999",
    "交易服务器": "180.168.146.187:10101",
    "行情服务器": "168.146.187:10111",
    "产品名称": "simnow_client_test",
    "授权编码": "0000000000000000",
    "产品信息": ""
}
engine.connect_gateway(setting, "CTP")
sleep(5)
contract_list = engine.get_all_contracts()
print(contract_list[1])
vt_symbols = ['CF109.CZCE']
engine.subscribe(vt_symbols=vt_symbols)

while True:
    for vt_symbol in vt_symbols:
        tick = engine.get_tick(vt_symbol=vt_symbol, use_df=True)
        print(tick)
    sleep(5)

description

Member
avatar
加入于:
帖子: 794
声望: 40
  1. 第一套第二组行情服务器是“180.168.146.187:10111”不是 "168.146.187:10111"吧;
  2. 你while True:前面是不是少了一句engine.strategy_active = True;
  3. 现在关市了,可以用第二套环境再试试
© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3