diff --git a/examples/CtaTrading/CTA_setting.json b/examples/CtaTrading/CTA_setting.json new file mode 100644 index 00000000..19884be3 --- /dev/null +++ b/examples/CtaTrading/CTA_setting.json @@ -0,0 +1,19 @@ +[ + { + "name": "double ema", + "className": "EmaDemoStrategy", + "vtSymbol": "IF1706" + }, + + { + "name": "atr rsi", + "className": "AtrRsiStrategy", + "vtSymbol": "IC1706" + }, + + { + "name": "king keltner", + "className": "KkStrategy", + "vtSymbol": "IH1706" + } +] \ No newline at end of file diff --git a/examples/CtaTrading/CTP_connect.json b/examples/CtaTrading/CTP_connect.json new file mode 100644 index 00000000..e4bfa6b8 --- /dev/null +++ b/examples/CtaTrading/CTP_connect.json @@ -0,0 +1,7 @@ +{ + "brokerID": "9999", + "mdAddress": "tcp://180.168.146.187:10011", + "tdAddress": "tcp://180.168.146.187:10001", + "userID": "simnow申请", + "password": "simnow申请" +} \ No newline at end of file diff --git a/examples/DataRecording/CTP_connect.json b/examples/DataRecording/CTP_connect.json new file mode 100644 index 00000000..e4bfa6b8 --- /dev/null +++ b/examples/DataRecording/CTP_connect.json @@ -0,0 +1,7 @@ +{ + "brokerID": "9999", + "mdAddress": "tcp://180.168.146.187:10011", + "tdAddress": "tcp://180.168.146.187:10001", + "userID": "simnow申请", + "password": "simnow申请" +} \ No newline at end of file diff --git a/examples/DataRecording/DR_setting.json b/examples/DataRecording/DR_setting.json new file mode 100644 index 00000000..07030299 --- /dev/null +++ b/examples/DataRecording/DR_setting.json @@ -0,0 +1,18 @@ +{ + "working": true, + + "tick": + [ + ], + + "bar": + [ + ["BTC_CNY_SPOT", "OKCOIN"], + ["LTC_CNY_SPOT", "OKCOIN"], + ["ETH_CNY_SPOT", "OKCOIN"] + ], + + "active": + { + } +} \ No newline at end of file diff --git a/examples/VnTrader/CTA_setting.json b/examples/VnTrader/CTA_setting.json new file mode 100644 index 00000000..19884be3 --- /dev/null +++ b/examples/VnTrader/CTA_setting.json @@ -0,0 +1,19 @@ +[ + { + "name": "double ema", + "className": "EmaDemoStrategy", + "vtSymbol": "IF1706" + }, + + { + "name": "atr rsi", + "className": "AtrRsiStrategy", + "vtSymbol": "IC1706" + }, + + { + "name": "king keltner", + "className": "KkStrategy", + "vtSymbol": "IH1706" + } +] \ No newline at end of file diff --git a/examples/VnTrader/CTP_connect.json b/examples/VnTrader/CTP_connect.json new file mode 100644 index 00000000..1b4d5a42 --- /dev/null +++ b/examples/VnTrader/CTP_connect.json @@ -0,0 +1,7 @@ +{ + "brokerID": "9999", + "mdAddress": "tcp://180.168.146.187:10011", + "tdAddress": "tcp://180.168.146.187:10001", + "userID": "000300", + "password": "19890624" +} \ No newline at end of file diff --git a/examples/VnTrader/DR_setting.json b/examples/VnTrader/DR_setting.json new file mode 100644 index 00000000..07030299 --- /dev/null +++ b/examples/VnTrader/DR_setting.json @@ -0,0 +1,18 @@ +{ + "working": true, + + "tick": + [ + ], + + "bar": + [ + ["BTC_CNY_SPOT", "OKCOIN"], + ["LTC_CNY_SPOT", "OKCOIN"], + ["ETH_CNY_SPOT", "OKCOIN"] + ], + + "active": + { + } +} \ No newline at end of file diff --git a/examples/VnTrader/FEMAS_connect.json b/examples/VnTrader/FEMAS_connect.json new file mode 100644 index 00000000..e2bb938e --- /dev/null +++ b/examples/VnTrader/FEMAS_connect.json @@ -0,0 +1,7 @@ +{ + "brokerID": "0110", + "tdAddress": "tcp://118.126.16.229:17111", + "password": "飞马账户请自行联系期货公司申请", + "mdAddress": "tcp://118.126.16.229:17101", + "userID": "飞马账户请自行联系期货公司申请" +} \ No newline at end of file diff --git a/examples/VnTrader/HUOBI_connect.json b/examples/VnTrader/HUOBI_connect.json new file mode 100644 index 00000000..3c427281 --- /dev/null +++ b/examples/VnTrader/HUOBI_connect.json @@ -0,0 +1,7 @@ +{ + "accessKey": "火币网站申请", + "secretKey": "火币网站申请", + "interval": 0.5, + "market": "cny", + "debug": false +} \ No newline at end of file diff --git a/examples/VnTrader/IB_connect.json b/examples/VnTrader/IB_connect.json new file mode 100644 index 00000000..1e62cab3 --- /dev/null +++ b/examples/VnTrader/IB_connect.json @@ -0,0 +1,6 @@ +{ + "host": "localhost", + "port": 7497, + "clientId": 888, + "accountCode": "DU545254" +} \ No newline at end of file diff --git a/examples/VnTrader/OANDA_connect.json b/examples/VnTrader/OANDA_connect.json new file mode 100644 index 00000000..21dd2cd9 --- /dev/null +++ b/examples/VnTrader/OANDA_connect.json @@ -0,0 +1,5 @@ +{ + "token": "请在OANDA网站申请", + "accountId": "请在OANDA网站申请", + "settingName": "practice" +} \ No newline at end of file diff --git a/examples/VnTrader/OKCOIN_connect.json b/examples/VnTrader/OKCOIN_connect.json new file mode 100644 index 00000000..8240e55e --- /dev/null +++ b/examples/VnTrader/OKCOIN_connect.json @@ -0,0 +1,7 @@ +{ + "host": "CNY", + "apiKey": "OKCOIN网站申请", + "secretKey": "OKCOIN网站申请", + "trace": false, + "leverage": 20 +} \ No newline at end of file diff --git a/examples/VnTrader/RM_setting.json b/examples/VnTrader/RM_setting.json new file mode 100644 index 00000000..25c98921 --- /dev/null +++ b/examples/VnTrader/RM_setting.json @@ -0,0 +1,9 @@ +{ + "orderFlowClear": 1, + "orderCancelLimit": 10, + "workingOrderLimit": 20, + "tradeLimit": 1000, + "orderSizeLimit": 100, + "active": true, + "orderFlowLimit": 50 +} \ No newline at end of file diff --git a/examples/VnTrader/SGIT_connect.json b/examples/VnTrader/SGIT_connect.json new file mode 100644 index 00000000..a6925448 --- /dev/null +++ b/examples/VnTrader/SGIT_connect.json @@ -0,0 +1,7 @@ +{ + "brokerID": "9999", + "tdAddress": "tcp://140.206.81.6:37776", + "password": "888888", + "mdAddress": "tcp://140.206.81.6:37777", + "userID": "0600035" +} \ No newline at end of file diff --git a/examples/VnTrader/SHZD_connect.json b/examples/VnTrader/SHZD_connect.json new file mode 100644 index 00000000..0bf3746e --- /dev/null +++ b/examples/VnTrader/SHZD_connect.json @@ -0,0 +1,8 @@ +{ + "frontAddress": "222.73.119.230", + "frontPort": 7003, + "marketAddress": "222.73.119.230", + "marketPort": 9003, + "userId": "demo000604", + "userPwd": "888888" +} \ No newline at end of file diff --git a/examples/VnTrader/ST_setting.json b/examples/VnTrader/ST_setting.json new file mode 100644 index 00000000..ba2c1da2 --- /dev/null +++ b/examples/VnTrader/ST_setting.json @@ -0,0 +1,85 @@ +[ + { + "name": "m.09-01", + + "activeLeg": + { + "vtSymbol": "m1709", + "ratio": 1, + "multiplier": 1.0, + "payup": 2 + }, + + "passiveLegs": [ + { + "vtSymbol": "m1801", + "ratio": -1, + "multiplier": -1.0, + "payup": 2 + } + ] + }, + + { + "name": "IF.07-09", + + "activeLeg": + { + "vtSymbol": "IF1707", + "ratio": 1, + "multiplier": 1.0, + "payup": 2 + }, + + "passiveLegs": [ + { + "vtSymbol": "IF1709", + "ratio": -1, + "multiplier": -1.0, + "payup": 2 + } + ] + }, + + { + "name": "IH.07-09", + + "activeLeg": + { + "vtSymbol": "IH1707", + "ratio": 1, + "multiplier": 1.0, + "payup": 2 + }, + + "passiveLegs": [ + { + "vtSymbol": "IH1709", + "ratio": -1, + "multiplier": -1.0, + "payup": 2 + } + ] + }, + + { + "name": "IC.07-09", + + "activeLeg": + { + "vtSymbol": "IC1707", + "ratio": 1, + "multiplier": 1.0, + "payup": 2 + }, + + "passiveLegs": [ + { + "vtSymbol": "IC1709", + "ratio": -1, + "multiplier": -1.0, + "payup": 2 + } + ] + } +] \ No newline at end of file diff --git a/examples/VnTrader/XSPEED_connect.json b/examples/VnTrader/XSPEED_connect.json new file mode 100644 index 00000000..71f0b84a --- /dev/null +++ b/examples/VnTrader/XSPEED_connect.json @@ -0,0 +1,6 @@ +{ + "tdAddress": "tcp://203.187.171.250:10910", + "password": "请联系飞创申请", + "mdAddress": "tcp://203.187.171.250:10915", + "accountID": "请联系飞创申请" +} \ No newline at end of file diff --git a/examples/VnTrader/run.py b/examples/VnTrader/run.py index 2140d8ae..0af7dabe 100644 --- a/examples/VnTrader/run.py +++ b/examples/VnTrader/run.py @@ -12,11 +12,9 @@ from vnpy.trader.uiQt import qApp from vnpy.trader.uiMainWindow import MainWindow # 加载底层接口 -# from vnpy.trader.gateway import (ctpGateway, femasGateway, xspeedGateway, -# sgitGateway, oandaGateway, ibGateway, -# shzdGateway, huobiGateway, okcoinGateway) - -from vnpy.trader.gateway import ( huobiGateway, okcoinGateway) +from vnpy.trader.gateway import (ctpGateway, femasGateway, xspeedGateway, + sgitGateway, oandaGateway, ibGateway, + shzdGateway, huobiGateway, okcoinGateway) # 加载上层应用 from vnpy.trader.app import (riskManager, ctaStrategy, spreadTrading) @@ -32,13 +30,13 @@ def main(): me = MainEngine(ee) # 添加交易接口 - # me.addGateway(ctpGateway) - # me.addGateway(femasGateway) - # me.addGateway(xspeedGateway) - # me.addGateway(sgitGateway) - # me.addGateway(oandaGateway) - # me.addGateway(ibGateway) - # me.addGateway(shzdGateway) + me.addGateway(ctpGateway) + me.addGateway(femasGateway) + me.addGateway(xspeedGateway) + me.addGateway(sgitGateway) + me.addGateway(oandaGateway) + me.addGateway(ibGateway) + me.addGateway(shzdGateway) me.addGateway(huobiGateway) me.addGateway(okcoinGateway) diff --git a/vnpy/trader/app/ctaStrategy/ctaEngine.py b/vnpy/trader/app/ctaStrategy/ctaEngine.py index 77464b18..cca62f6e 100644 --- a/vnpy/trader/app/ctaStrategy/ctaEngine.py +++ b/vnpy/trader/app/ctaStrategy/ctaEngine.py @@ -29,10 +29,10 @@ from vnpy.trader.vtEvent import * from vnpy.trader.vtConstant import * from vnpy.trader.vtObject import VtTickData, VtBarData from vnpy.trader.vtGateway import VtSubscribeReq, VtOrderReq, VtCancelOrderReq, VtLogData -from vnpy.trader.vtFunction import todayDate +from vnpy.trader.vtFunction import todayDate, getJsonPath -from vnpy.trader.app.ctaStrategy.ctaBase import * -from vnpy.trader.app.ctaStrategy.strategy import STRATEGY_CLASS +from .ctaBase import * +from .strategy import STRATEGY_CLASS @@ -41,8 +41,7 @@ from vnpy.trader.app.ctaStrategy.strategy import STRATEGY_CLASS class CtaEngine(object): """CTA策略引擎""" settingFileName = 'CTA_setting.json' - path = os.path.abspath(os.path.dirname(__file__)) - settingFileName = os.path.join(path, settingFileName) + settingfilePath = getJsonPath(settingFileName, __file__) #---------------------------------------------------------------------- def __init__(self, mainEngine, eventEngine): @@ -486,7 +485,7 @@ class CtaEngine(object): #---------------------------------------------------------------------- def saveSetting(self): """保存策略配置""" - with open(self.settingFileName, 'w') as f: + with open(self.settingfilePath, 'w') as f: l = [] for strategy in self.strategyDict.values(): @@ -501,7 +500,7 @@ class CtaEngine(object): #---------------------------------------------------------------------- def loadSetting(self): """读取策略配置""" - with open(self.settingFileName) as f: + with open(self.settingfilePath) as f: l = json.load(f) for setting in l: diff --git a/vnpy/trader/app/dataRecorder/drEngine.py b/vnpy/trader/app/dataRecorder/drEngine.py index c9af1522..ec4641c2 100644 --- a/vnpy/trader/app/dataRecorder/drEngine.py +++ b/vnpy/trader/app/dataRecorder/drEngine.py @@ -17,7 +17,7 @@ from threading import Thread from vnpy.event import Event from vnpy.trader.vtEvent import * -from vnpy.trader.vtFunction import todayDate +from vnpy.trader.vtFunction import todayDate, getJsonPath from vnpy.trader.vtObject import VtSubscribeReq, VtLogData, VtBarData, VtTickData from vnpy.trader.app.dataRecorder.drBase import * @@ -28,9 +28,8 @@ from vnpy.trader.app.dataRecorder.language import text class DrEngine(object): """数据记录引擎""" - settingFileName = 'DR_setting.csv' - path = os.path.abspath(os.path.dirname(__file__)) - settingFileName = os.path.join(path, settingFileName) + settingFileName = 'DR_setting.json' + settingFilePath = getJsonPath(settingFileName, __file__) #---------------------------------------------------------------------- def __init__(self, mainEngine, eventEngine): @@ -66,49 +65,122 @@ class DrEngine(object): # 注册事件监听 self.registerEvent() - + #---------------------------------------------------------------------- def loadSetting(self): """加载配置""" with open(self.settingFileName) as f: - drSetting = csv.DictReader(f) - - for d in drSetting: - # 读取配置 - gatewayName = d['gateway'] - symbol = d['symbol'] - exchange = d['exchange'] - currency = d['currency'] - productClass = d['product'] - recordTick = d['tick'] - recordBar = d['bar'] - activeSymbol = d['active'] - - if exchange: - vtSymbol = '.'.join([symbol, exchange]) - else: + drSetting = json.load(f) + + # 如果working设为False则不启动行情记录功能 + working = drSetting['working'] + if not working: + return + + if 'tick' in drSetting: + l = drSetting['tick'] + + for setting in l: + symbol = setting[0] vtSymbol = symbol - - # 订阅行情 - req = VtSubscribeReq() - req.symbol = symbol - req.exchange = exchange - req.currency = currency - req.productClass = productClass - self.mainEngine.subscribe(req, gatewayName) - - # 设置需要记录的数据 - if recordTick: - tick = VtTickData() - self.tickDict[vtSymbol] = VtTickData() - - if recordBar: - self.barDict[vtSymbol] = VtBarData() - - if activeSymbol: + + req = VtSubscribeReq() + req.symbol = setting[0] + + # 针对LTS和IB接口,订阅行情需要交易所代码 + if len(setting)>=3: + req.exchange = setting[2] + vtSymbol = '.'.join([symbol, req.exchange]) + + # 针对IB接口,订阅行情需要货币和产品类型 + if len(setting)>=5: + req.currency = setting[3] + req.productClass = setting[4] + + self.mainEngine.subscribe(req, setting[1]) + + tick = VtTickData() # 该tick实例可以用于缓存部分数据(目前未使用) + self.tickDict[vtSymbol] = tick + + if 'bar' in drSetting: + l = drSetting['bar'] + + for setting in l: + symbol = setting[0] + vtSymbol = symbol + + req = VtSubscribeReq() + req.symbol = symbol + + if len(setting)>=3: + req.exchange = setting[2] + vtSymbol = '.'.join([symbol, req.exchange]) + + if len(setting)>=5: + req.currency = setting[3] + req.productClass = setting[4] + + self.mainEngine.subscribe(req, setting[1]) + + bar = VtBarData() + self.barDict[vtSymbol] = bar + + if 'active' in drSetting: + d = drSetting['active'] + + # 注意这里的vtSymbol对于IB和LTS接口,应该后缀.交易所 + for activeSymbol, vtSymbol in d.items(): self.activeSymbolDict[vtSymbol] = activeSymbol + + # 启动数据插入线程 + self.start() + + # 注册事件监听 + self.registerEvent() + + + ##---------------------------------------------------------------------- + #def loadCsvSetting(self): + #"""加载CSV配置""" + #with open(self.settingFileName) as f: + #drSetting = csv.DictReader(f) + + #for d in drSetting: + ## 读取配置 + #gatewayName = d['gateway'] + #symbol = d['symbol'] + #exchange = d['exchange'] + #currency = d['currency'] + #productClass = d['product'] + #recordTick = d['tick'] + #recordBar = d['bar'] + #activeSymbol = d['active'] + + #if exchange: + #vtSymbol = '.'.join([symbol, exchange]) + #else: + #vtSymbol = symbol + + ## 订阅行情 + #req = VtSubscribeReq() + #req.symbol = symbol + #req.exchange = exchange + #req.currency = currency + #req.productClass = productClass + #self.mainEngine.subscribe(req, gatewayName) + + ## 设置需要记录的数据 + #if recordTick: + #tick = VtTickData() + #self.tickDict[vtSymbol] = VtTickData() - # 保存配置到缓存中 + #if recordBar: + #self.barDict[vtSymbol] = VtBarData() + + #if activeSymbol: + #self.activeSymbolDict[vtSymbol] = activeSymbol + + ## 保存配置到缓存中 self.settingDict[vtSymbol] = d #---------------------------------------------------------------------- diff --git a/vnpy/trader/app/riskManager/rmEngine.py b/vnpy/trader/app/riskManager/rmEngine.py index 54ef606e..8816f2b0 100644 --- a/vnpy/trader/app/riskManager/rmEngine.py +++ b/vnpy/trader/app/riskManager/rmEngine.py @@ -15,14 +15,14 @@ from vnpy.event import Event from vnpy.trader.vtEvent import * from vnpy.trader.vtConstant import * from vnpy.trader.vtGateway import VtLogData +from vnpy.trader.vtFunction import getJsonPath ######################################################################## class RmEngine(object): """风控引擎""" settingFileName = 'RM_setting.json' - path = os.path.abspath(os.path.dirname(__file__)) - settingFileName = os.path.join(path, settingFileName) + settingFilePath = getJsonPath(settingFileName, __file__) name = u'风控模块' @@ -64,7 +64,7 @@ class RmEngine(object): #---------------------------------------------------------------------- def loadSetting(self): """读取配置""" - with open(self.settingFileName) as f: + with open(self.settingFilePath) as f: d = json.load(f) # 设置风控参数 @@ -84,7 +84,7 @@ class RmEngine(object): #---------------------------------------------------------------------- def saveSetting(self): """保存风控参数""" - with open(self.settingFileName, 'w') as f: + with open(self.settingFilePath, 'w') as f: # 保存风控参数 d = {} diff --git a/vnpy/trader/gateway/cshshlpGateway/cshshlpGateway.py b/vnpy/trader/gateway/cshshlpGateway/cshshlpGateway.py index 49a7968e..63fdf361 100644 --- a/vnpy/trader/gateway/cshshlpGateway/cshshlpGateway.py +++ b/vnpy/trader/gateway/cshshlpGateway/cshshlpGateway.py @@ -8,7 +8,7 @@ from time import sleep from vnpy.api.cshshlp import CsHsHlp from vnpy.api.ctp import MdApi from vnpy.trader.vtGateway import * -from vnpy.trader.vtFunction import getTempPath +from vnpy.trader.vtFunction import getTempPath, getJsonPath # 接口常量 @@ -97,11 +97,10 @@ class CshshlpGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName diff --git a/vnpy/trader/gateway/ctpGateway/ctpGateway.py b/vnpy/trader/gateway/ctpGateway/ctpGateway.py index 4354080b..129bcd30 100644 --- a/vnpy/trader/gateway/ctpGateway/ctpGateway.py +++ b/vnpy/trader/gateway/ctpGateway/ctpGateway.py @@ -15,9 +15,9 @@ from datetime import datetime from vnpy.api.ctp import MdApi, TdApi, defineDict from vnpy.trader.vtGateway import * -from vnpy.trader.vtFunction import getTempPath -from vnpy.trader.gateway.ctpGateway.language import text +from vnpy.trader.vtFunction import getJsonPath, getTempPath from vnpy.trader.vtConstant import GATEWAYTYPE_FUTURES +from .language import text # 以下为一些VT类型和CTP类型的映射字典 @@ -97,11 +97,10 @@ class CtpGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName diff --git a/vnpy/trader/gateway/femasGateway/femasGateway.py b/vnpy/trader/gateway/femasGateway/femasGateway.py index 35051d3f..497f146b 100644 --- a/vnpy/trader/gateway/femasGateway/femasGateway.py +++ b/vnpy/trader/gateway/femasGateway/femasGateway.py @@ -11,7 +11,7 @@ import os import json from vnpy.api.femas import MdApi, TdApi, defineDict -from vnpy.trader.vtFunction import getTempPath +from vnpy.trader.vtFunction import getTempPath, getJsonPath from vnpy.trader.vtGateway import * # 以下为一些VT类型和CTP类型的映射字典 @@ -77,11 +77,10 @@ class FemasGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName diff --git a/vnpy/trader/gateway/huobiGateway/huobiGateway.py b/vnpy/trader/gateway/huobiGateway/huobiGateway.py index d84fee10..dd7b6224 100644 --- a/vnpy/trader/gateway/huobiGateway/huobiGateway.py +++ b/vnpy/trader/gateway/huobiGateway/huobiGateway.py @@ -15,7 +15,7 @@ from threading import Thread from vnpy.api.huobi import vnhuobi from vnpy.trader.vtGateway import * - +from vnpy.trader.vtFunction import getJsonPath SYMBOL_BTCCNY = 'BTCCNY' SYMBOL_LTCCNY = 'LTCCNY' @@ -65,11 +65,10 @@ class HuobiGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName diff --git a/vnpy/trader/gateway/ibGateway/ibGateway.py b/vnpy/trader/gateway/ibGateway/ibGateway.py index 880768b0..51c12e5e 100644 --- a/vnpy/trader/gateway/ibGateway/ibGateway.py +++ b/vnpy/trader/gateway/ibGateway/ibGateway.py @@ -19,7 +19,9 @@ from copy import copy from vnpy.api.ib import * from vnpy.trader.vtGateway import * -from vnpy.trader.gateway.ibGateway.language import text +from vnpy.trader.vtFunction import getJsonPath +from .language import text + # 以下为一些VT类型和CTP类型的映射字典 @@ -142,11 +144,10 @@ class IbGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName diff --git a/vnpy/trader/gateway/ksgoldGateway/ksgoldGateway.py b/vnpy/trader/gateway/ksgoldGateway/ksgoldGateway.py index 80f22f91..a23fa1cf 100644 --- a/vnpy/trader/gateway/ksgoldGateway/ksgoldGateway.py +++ b/vnpy/trader/gateway/ksgoldGateway/ksgoldGateway.py @@ -13,6 +13,7 @@ import time from vnpy.api.ksgold import TdApi, defineDict from vnpy.trader.vtGateway import * +from vnpy.trader.vtFunction import getJsonPath # 以下类型映射参考的是原生API里的Constant.h @@ -50,11 +51,10 @@ class KsgoldGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName diff --git a/vnpy/trader/gateway/ksotpGateway/ksotpGateway.py b/vnpy/trader/gateway/ksotpGateway/ksotpGateway.py index f6dd286b..fdfead52 100644 --- a/vnpy/trader/gateway/ksotpGateway/ksotpGateway.py +++ b/vnpy/trader/gateway/ksotpGateway/ksotpGateway.py @@ -9,7 +9,7 @@ import os import json from vnpy.api.ksotp import MdApi, TdApi, defineDict -from vnpy.trader.vtFunction import getTempPath +from vnpy.trader.vtFunction import getTempPath, getJsonPath from vnpy.trader.vtGateway import * # 以下为一些VT类型和CTP类型的映射字典 @@ -73,11 +73,10 @@ class KsotpGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName diff --git a/vnpy/trader/gateway/lhangGateway/lhangGateway.py b/vnpy/trader/gateway/lhangGateway/lhangGateway.py index d8d250b8..3948482a 100644 --- a/vnpy/trader/gateway/lhangGateway/lhangGateway.py +++ b/vnpy/trader/gateway/lhangGateway/lhangGateway.py @@ -12,6 +12,7 @@ from time import sleep from vnpy.api.lhang import LhangApi from vnpy.trader.vtGateway import * +from vnpy.trader.vtFunction import getJsonPath SYMBOL_BTCCNY = 'BTCCNY' @@ -51,11 +52,10 @@ class LhangGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName diff --git a/vnpy/trader/gateway/ltsGateway/ltsGateway.py b/vnpy/trader/gateway/ltsGateway/ltsGateway.py index 5616c5c5..693e9542 100644 --- a/vnpy/trader/gateway/ltsGateway/ltsGateway.py +++ b/vnpy/trader/gateway/ltsGateway/ltsGateway.py @@ -8,7 +8,7 @@ import os import json from vnpy.api.lts import MdApi, QryApi, TdApi, defineDict -from vnpy.trader.vtFunction import getTempPath +from vnpy.trader.vtFunction import getTempPath, getJsonPath from vnpy.trader.vtGateway import * @@ -74,11 +74,10 @@ class LtsGateway(VtGateway): """连接""" # 载入json 文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName diff --git a/vnpy/trader/gateway/oandaGateway/oandaGateway.py b/vnpy/trader/gateway/oandaGateway/oandaGateway.py index f4e52bac..e6cb9aff 100644 --- a/vnpy/trader/gateway/oandaGateway/oandaGateway.py +++ b/vnpy/trader/gateway/oandaGateway/oandaGateway.py @@ -26,6 +26,7 @@ import datetime from vnpy.api.oanda import OandaApi from vnpy.trader.vtGateway import * +from vnpy.trader.vtFunction import getJsonPath # 价格类型映射 priceTypeMap = {} @@ -58,11 +59,10 @@ class OandaGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName diff --git a/vnpy/trader/gateway/okcoinGateway/okcoinGateway.py b/vnpy/trader/gateway/okcoinGateway/okcoinGateway.py index f41265f9..1b73dc3c 100644 --- a/vnpy/trader/gateway/okcoinGateway/okcoinGateway.py +++ b/vnpy/trader/gateway/okcoinGateway/okcoinGateway.py @@ -20,6 +20,7 @@ from time import sleep from vnpy.api.okcoin import vnokcoin from vnpy.trader.vtGateway import * +from vnpy.trader.vtFunction import getJsonPath # 价格类型映射 priceTypeMap = {} @@ -122,11 +123,10 @@ class OkcoinGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName diff --git a/vnpy/trader/gateway/qdpGateway/qdpGateway.py b/vnpy/trader/gateway/qdpGateway/qdpGateway.py index fe00f708..d9443c75 100644 --- a/vnpy/trader/gateway/qdpGateway/qdpGateway.py +++ b/vnpy/trader/gateway/qdpGateway/qdpGateway.py @@ -15,6 +15,7 @@ from copy import copy from vnpy.api.qdp import MdApi, TdApi, defineDict from vnpy.trader.vtGateway import * +from vnpy.trader.vtFunction import getJsonPath # 以下为一些VT类型和QDP类型的映射字典 @@ -82,11 +83,10 @@ class QdpGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName diff --git a/vnpy/trader/gateway/sgitGateway/sgitGateway.py b/vnpy/trader/gateway/sgitGateway/sgitGateway.py index 4e009e10..ecee3026 100644 --- a/vnpy/trader/gateway/sgitGateway/sgitGateway.py +++ b/vnpy/trader/gateway/sgitGateway/sgitGateway.py @@ -14,7 +14,7 @@ from copy import copy from datetime import datetime from vnpy.api.sgit import MdApi, TdApi, defineDict -from vnpy.trader.vtFunction import getTempPath +from vnpy.trader.vtFunction import getTempPath, getJsonPath from vnpy.trader.vtGateway import * @@ -94,11 +94,10 @@ class SgitGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName diff --git a/vnpy/trader/gateway/shzdGateway/shzdGateway.py b/vnpy/trader/gateway/shzdGateway/shzdGateway.py index a56d2d42..ae192271 100644 --- a/vnpy/trader/gateway/shzdGateway/shzdGateway.py +++ b/vnpy/trader/gateway/shzdGateway/shzdGateway.py @@ -17,6 +17,7 @@ from datetime import datetime from vnpy.api.shzd import ShzdApi from vnpy.trader.vtGateway import * +from vnpy.trader.vtFunction import getJsonPath # 以下为一些VT类型和SHZD类型的映射字典 @@ -34,10 +35,6 @@ directionMapReverse = {v: k for k, v in directionMap.items()} # 交易所类型映射 exchangeMap = {} -#exchangeMap[EXCHANGE_CFFEX] = 'CFFEX' -#exchangeMap[EXCHANGE_SHFE] = 'SHFE' -#exchangeMap[EXCHANGE_CZCE] = 'CZCE' -#exchangeMap[EXCHANGE_DCE] = 'DCE' exchangeMap[EXCHANGE_HKEX] = 'HKEX' exchangeMap[EXCHANGE_CME] = 'CME' exchangeMap[EXCHANGE_ICE] = 'ICE' @@ -77,11 +74,10 @@ class ShzdGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName diff --git a/vnpy/trader/gateway/xspeedGateway/xspeedGateway.py b/vnpy/trader/gateway/xspeedGateway/xspeedGateway.py index ae913eab..091d4693 100644 --- a/vnpy/trader/gateway/xspeedGateway/xspeedGateway.py +++ b/vnpy/trader/gateway/xspeedGateway/xspeedGateway.py @@ -11,6 +11,8 @@ from copy import copy from vnpy.api.xspeed import MdApi, TdApi, defineDict from vnpy.trader.vtGateway import * +from vnpy.trader.vtFunction import getJsonPath + # 以下为一些VT类型和XSPEED类型的映射字典 # 价格类型映射 @@ -81,11 +83,10 @@ class XspeedGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - path = os.path.abspath(os.path.dirname(__file__)) - fileName = os.path.join(path, fileName) + filePath = getJsonPath(fileName, __file__) try: - f = file(fileName) + f = file(filePath) except IOError: log = VtLogData() log.gatewayName = self.gatewayName