diff --git a/vn.trader/VT_setting.json b/vn.trader/VT_setting.json index 5f15b65d..776c8d36 100644 --- a/vn.trader/VT_setting.json +++ b/vn.trader/VT_setting.json @@ -7,5 +7,5 @@ "mongoLogging": true, "darkStyle": true, - "language": "English" + "language": "english" } \ No newline at end of file diff --git a/vn.trader/ctaStrategy/language/__init__.py b/vn.trader/ctaStrategy/language/__init__.py index 9b79651c..e42bd064 100644 --- a/vn.trader/ctaStrategy/language/__init__.py +++ b/vn.trader/ctaStrategy/language/__init__.py @@ -5,7 +5,7 @@ import os import traceback # 默认设置 -from Chinese import text +from chinese import text # 获取目录上级路径 path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) @@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME) try: f = file(SETTING_FILENAME) setting = json.load(f) - if setting['language'] == 'English': - from English import text + if setting['language'] == 'english': + from english import text f.close() except: traceback.print_exc() diff --git a/vn.trader/dataRecorder/language/__init__.py b/vn.trader/dataRecorder/language/__init__.py index 9b79651c..e42bd064 100644 --- a/vn.trader/dataRecorder/language/__init__.py +++ b/vn.trader/dataRecorder/language/__init__.py @@ -5,7 +5,7 @@ import os import traceback # 默认设置 -from Chinese import text +from chinese import text # 获取目录上级路径 path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) @@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME) try: f = file(SETTING_FILENAME) setting = json.load(f) - if setting['language'] == 'English': - from English import text + if setting['language'] == 'english': + from english import text f.close() except: traceback.print_exc() diff --git a/vn.trader/gateway/ctpGateway/CTP_connect.json b/vn.trader/gateway/ctpGateway/CTP_connect.json index fe1ffded..0f3215d3 100644 --- a/vn.trader/gateway/ctpGateway/CTP_connect.json +++ b/vn.trader/gateway/ctpGateway/CTP_connect.json @@ -1,7 +1,7 @@ { "brokerID": "9999", "tdAddress": "tcp://180.168.146.187:10000", - "password": "simnow申请", - "mdAddress": "tcp://180.168.212.228:41213", - "userID": "simnow申请" + "password": "19890624", + "mdAddress": "tcp://180.168.146.187:10010", + "userID": "000300" } \ No newline at end of file diff --git a/vn.trader/gateway/ctpGateway/ctpGateway.py b/vn.trader/gateway/ctpGateway/ctpGateway.py index 0d38e711..24d620b6 100644 --- a/vn.trader/gateway/ctpGateway/ctpGateway.py +++ b/vn.trader/gateway/ctpGateway/ctpGateway.py @@ -710,7 +710,8 @@ class CtpTdApi(TdApi): pos.positionProfit += data['PositionProfit'] # 计算持仓均价 - pos.price = (cost + data['PositionCost']) / pos.position + if pos.position: + pos.price = (cost + data['PositionCost']) / pos.position # 读取冻结 if pos.direction is DIRECTION_LONG: diff --git a/vn.trader/gateway/ctpGateway/language/__init__.py b/vn.trader/gateway/ctpGateway/language/__init__.py index 9b79651c..8325ae0c 100644 --- a/vn.trader/gateway/ctpGateway/language/__init__.py +++ b/vn.trader/gateway/ctpGateway/language/__init__.py @@ -5,10 +5,10 @@ import os import traceback # 默认设置 -from Chinese import text +from chinese import text # 获取目录上级路径 -path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) +path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')) SETTING_FILENAME = 'VT_setting.json' SETTING_FILENAME = os.path.join(path, SETTING_FILENAME) @@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME) try: f = file(SETTING_FILENAME) setting = json.load(f) - if setting['language'] == 'English': - from English import text + if setting['language'] == 'english': + from english import text f.close() except: traceback.print_exc() diff --git a/vn.trader/gateway/ibGateway/language/__init__.py b/vn.trader/gateway/ibGateway/language/__init__.py index 9b79651c..8325ae0c 100644 --- a/vn.trader/gateway/ibGateway/language/__init__.py +++ b/vn.trader/gateway/ibGateway/language/__init__.py @@ -5,10 +5,10 @@ import os import traceback # 默认设置 -from Chinese import text +from chinese import text # 获取目录上级路径 -path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) +path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')) SETTING_FILENAME = 'VT_setting.json' SETTING_FILENAME = os.path.join(path, SETTING_FILENAME) @@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME) try: f = file(SETTING_FILENAME) setting = json.load(f) - if setting['language'] == 'English': - from English import text + if setting['language'] == 'english': + from english import text f.close() except: traceback.print_exc() diff --git a/vn.trader/language/__init__.py b/vn.trader/language/__init__.py index 7c23b182..696e9d4e 100644 --- a/vn.trader/language/__init__.py +++ b/vn.trader/language/__init__.py @@ -4,7 +4,7 @@ import json import os # 默认设置 -from Chinese import text, constant +from chinese import text, constant # 获取目录上级路径 path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) @@ -15,8 +15,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME) try: f = file(SETTING_FILENAME) setting = json.load(f) - if setting['language'] == 'English': - from English import text, constant + if setting['language'] == 'english': + from english import text, constant f.close() except: pass diff --git a/vn.trader/language/chinese/text.py b/vn.trader/language/chinese/text.py index 995b3c72..dfad30fb 100644 --- a/vn.trader/language/chinese/text.py +++ b/vn.trader/language/chinese/text.py @@ -123,4 +123,11 @@ TEST = u'测试' CONNECT = u'连接' CPU_MEMORY_INFO = u'CPU使用率:{cpu}% 内存使用率:{memory}%' -CONFIRM_EXIT = u'确认退出?' \ No newline at end of file +CONFIRM_EXIT = u'确认退出?' + +GATEWAY_NOT_EXIST = u'接口不存在:{gateway}' +DATABASE_CONNECTING_COMPLETED = u'MongoDB连接成功' +DATABASE_CONNECTING_FAILED = u'MongoDB连接失败' +DATA_INSERT_FAILED = u'数据插入失败,MongoDB没有连接' +DATA_QUERY_FAILED = u'数据查询失败,MongoDB没有连接' +DATA_UPDATE_FAILED = u'数据更新失败,MongoDB没有连接' diff --git a/vn.trader/language/english/text.py b/vn.trader/language/english/text.py index d68cc67d..daaf8ac9 100644 --- a/vn.trader/language/english/text.py +++ b/vn.trader/language/english/text.py @@ -123,4 +123,11 @@ TEST = u'Test' CONNECT = u'Connect ' CPU_MEMORY_INFO = u'CPU Usage:{cpu}% Memory Usage:{memory}%' -CONFIRM_EXIT = u'Confirm Exit?' \ No newline at end of file +CONFIRM_EXIT = u'Confirm Exit?' + +GATEWAY_NOT_EXIST = u"Can't find the gateway:{gateway}" +DATABASE_CONNECTING_COMPLETED = u'MongoDB is connected.' +DATABASE_CONNECTING_FAILED = u'Failed to connect to MongoDB.' +DATA_INSERT_FAILED = u'Data insert failed,please connect MongoDB first.' +DATA_QUERY_FAILED = u'Data query failed, please connect MongoDB first.' +DATA_UPDATE_FAILED = u'Data update failed, please connect MongoDB first.' \ No newline at end of file diff --git a/vn.trader/riskManager/language/__init__.py b/vn.trader/riskManager/language/__init__.py index 9b79651c..e42bd064 100644 --- a/vn.trader/riskManager/language/__init__.py +++ b/vn.trader/riskManager/language/__init__.py @@ -5,7 +5,7 @@ import os import traceback # 默认设置 -from Chinese import text +from chinese import text # 获取目录上级路径 path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) @@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME) try: f = file(SETTING_FILENAME) setting = json.load(f) - if setting['language'] == 'English': - from English import text + if setting['language'] == 'english': + from english import text f.close() except: traceback.print_exc() diff --git a/vn.trader/vtEngine.py b/vn.trader/vtEngine.py index c4c6864a..ec9c796a 100644 --- a/vn.trader/vtEngine.py +++ b/vn.trader/vtEngine.py @@ -10,6 +10,7 @@ from pymongo.errors import ConnectionFailure from eventEngine import * from vtGateway import * from vtFunction import loadMongoSetting +from language import text from gateway import GATEWAY_DICT from ctaStrategy.ctaEngine import CtaEngine @@ -75,7 +76,7 @@ class MainEngine(object): # 接口连接后自动执行数据库连接的任务 self.dbConnect() else: - self.writeLog(u'接口不存在:%s' %gatewayName) + self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName)) #---------------------------------------------------------------------- def subscribe(self, subscribeReq, gatewayName): @@ -84,7 +85,7 @@ class MainEngine(object): gateway = self.gatewayDict[gatewayName] gateway.subscribe(subscribeReq) else: - self.writeLog(u'接口不存在:%s' %gatewayName) + self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName)) #---------------------------------------------------------------------- def sendOrder(self, orderReq, gatewayName): @@ -97,7 +98,7 @@ class MainEngine(object): gateway = self.gatewayDict[gatewayName] return gateway.sendOrder(orderReq) else: - self.writeLog(u'接口不存在:%s' %gatewayName) + self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName)) #---------------------------------------------------------------------- def cancelOrder(self, cancelOrderReq, gatewayName): @@ -106,7 +107,8 @@ class MainEngine(object): gateway = self.gatewayDict[gatewayName] gateway.cancelOrder(cancelOrderReq) else: - self.writeLog(u'接口不存在:%s' %gatewayName) + self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName)) + #---------------------------------------------------------------------- def qryAccount(self, gatewayName): @@ -115,7 +117,7 @@ class MainEngine(object): gateway = self.gatewayDict[gatewayName] gateway.qryAccount() else: - self.writeLog(u'接口不存在:%s' %gatewayName) + self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName)) #---------------------------------------------------------------------- def qryPosition(self, gatewayName): @@ -124,7 +126,7 @@ class MainEngine(object): gateway = self.gatewayDict[gatewayName] gateway.qryPosition() else: - self.writeLog(u'接口不存在:%s' %gatewayName) + self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName)) #---------------------------------------------------------------------- def exit(self): @@ -165,14 +167,14 @@ class MainEngine(object): # 调用server_info查询服务器状态,防止服务器异常并未连接成功 self.dbClient.server_info() - self.writeLog(u'MongoDB连接成功') + self.writeLog(text.DATABASE_CONNECTING_COMPLETED) # 如果启动日志记录,则注册日志事件监听函数 if logging: self.eventEngine.register(EVENT_LOG, self.dbLogging) except ConnectionFailure: - self.writeLog(u'MongoDB连接失败') + self.writeLog(text.DATABASE_CONNECTING_FAILED) #---------------------------------------------------------------------- def dbInsert(self, dbName, collectionName, d): @@ -182,7 +184,7 @@ class MainEngine(object): collection = db[collectionName] collection.insert_one(d) else: - self.writeLog(u'数据插入失败,MongoDB没有连接') + self.writeLog(text.DATA_INSERT_FAILED) #---------------------------------------------------------------------- def dbQuery(self, dbName, collectionName, d): @@ -196,7 +198,7 @@ class MainEngine(object): else: return [] else: - self.writeLog(u'数据查询失败,MongoDB没有连接') + self.writeLog(text.DATA_QUERY_FAILED) return [] #---------------------------------------------------------------------- @@ -207,7 +209,7 @@ class MainEngine(object): collection = db[collectionName] collection.replace_one(flt, d, upsert) else: - self.writeLog(u'数据更新失败,MongoDB没有连接') + self.writeLog(text.DATA_UPDATE_FAILED) #---------------------------------------------------------------------- def dbLogging(self, event):