From f8d48bd4b94c91e1a7349cc103ff197b0f2696e0 Mon Sep 17 00:00:00 2001 From: lamter Date: Wed, 26 Apr 2017 22:23:05 +0800 Subject: [PATCH] =?UTF-8?q?=20-=20change=20:=20=E5=91=BD=E4=BB=A4=E8=A1=8C?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=20vtServer.py=20=E5=8F=AF=E4=BB=A5=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E5=8F=82=E6=95=B0=E6=8C=87=E5=AE=9A=20VT=5Fsetting.js?= =?UTF-8?q?on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/vtServer.py | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/vn.trader/vtServer.py b/vn.trader/vtServer.py index 16698105..f6d3b1be 100644 --- a/vn.trader/vtServer.py +++ b/vn.trader/vtServer.py @@ -1,14 +1,12 @@ # encoding: utf-8 -import sys +import vtGlobal +import json import os +from argparse import ArgumentParser from datetime import datetime -from time import sleep -from threading import Thread -import vtPath -import eventType from vnrpc import RpcServer from vtEngine import MainEngine @@ -74,14 +72,14 @@ def runServer(): """运行服务器""" repAddress = 'tcp://*:2014' pubAddress = 'tcp://*:0602' - + # 创建并启动服务器 server = VtServer(repAddress, pubAddress) server.start() - + printLog('-'*50) printLog(u'vn.trader服务器已启动') - + # 进入主循环 while True: printLog(u'请输入exit来关闭服务器') @@ -91,8 +89,29 @@ def runServer(): printLog(u'确认关闭服务器?yes|no') if raw_input() == 'yes': break - + server.stopServer() - + if __name__ == '__main__': - runServer() \ No newline at end of file + opt = ArgumentParser( + prog="vnpy", + description="Args of vnpy.", + ) + + # VT_setting.json 文件路径 + opt.add_argument("--VT_setting", default=None, help="重新指定VT_setting.json的绝对路径") + + # 生成参数实例 + cmdArgs = opt.parse_args() + + if cmdArgs.VT_setting is None: + fileName = 'VT_setting.json' + path = os.path.abspath(os.path.dirname(__file__)) + fileName = os.path.join(path, fileName) + else: + fileName = cmdArgs.VT_setting + + with open(fileName) as f: + vtGlobal.VT_setting = json.load(f) + + runServer()