增加主引擎内的英文翻译,修复ctpGateway中onRspQryInvestorPosition的zerodivision问题

This commit is contained in:
chenxy123 2017-04-10 21:40:18 +08:00
parent f0179c410d
commit d9401ba055
12 changed files with 55 additions and 38 deletions

View File

@ -7,5 +7,5 @@
"mongoLogging": true, "mongoLogging": true,
"darkStyle": true, "darkStyle": true,
"language": "English" "language": "english"
} }

View File

@ -5,7 +5,7 @@ import os
import traceback 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__), '..', '..'))
@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
try: try:
f = file(SETTING_FILENAME) f = file(SETTING_FILENAME)
setting = json.load(f) setting = json.load(f)
if setting['language'] == 'English': if setting['language'] == 'english':
from English import text from english import text
f.close() f.close()
except: except:
traceback.print_exc() traceback.print_exc()

View File

@ -5,7 +5,7 @@ import os
import traceback 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__), '..', '..'))
@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
try: try:
f = file(SETTING_FILENAME) f = file(SETTING_FILENAME)
setting = json.load(f) setting = json.load(f)
if setting['language'] == 'English': if setting['language'] == 'english':
from English import text from english import text
f.close() f.close()
except: except:
traceback.print_exc() traceback.print_exc()

View File

@ -1,7 +1,7 @@
{ {
"brokerID": "9999", "brokerID": "9999",
"tdAddress": "tcp://180.168.146.187:10000", "tdAddress": "tcp://180.168.146.187:10000",
"password": "simnow申请", "password": "19890624",
"mdAddress": "tcp://180.168.212.228:41213", "mdAddress": "tcp://180.168.146.187:10010",
"userID": "simnow申请" "userID": "000300"
} }

View File

@ -710,7 +710,8 @@ class CtpTdApi(TdApi):
pos.positionProfit += data['PositionProfit'] 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: if pos.direction is DIRECTION_LONG:

View File

@ -5,10 +5,10 @@ import os
import traceback 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 = 'VT_setting.json'
SETTING_FILENAME = os.path.join(path, SETTING_FILENAME) SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
try: try:
f = file(SETTING_FILENAME) f = file(SETTING_FILENAME)
setting = json.load(f) setting = json.load(f)
if setting['language'] == 'English': if setting['language'] == 'english':
from English import text from english import text
f.close() f.close()
except: except:
traceback.print_exc() traceback.print_exc()

View File

@ -5,10 +5,10 @@ import os
import traceback 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 = 'VT_setting.json'
SETTING_FILENAME = os.path.join(path, SETTING_FILENAME) SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
try: try:
f = file(SETTING_FILENAME) f = file(SETTING_FILENAME)
setting = json.load(f) setting = json.load(f)
if setting['language'] == 'English': if setting['language'] == 'english':
from English import text from english import text
f.close() f.close()
except: except:
traceback.print_exc() traceback.print_exc()

View File

@ -4,7 +4,7 @@ import json
import os import os
# 默认设置 # 默认设置
from Chinese import text, constant from chinese import text, constant
# 获取目录上级路径 # 获取目录上级路径
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
@ -15,8 +15,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
try: try:
f = file(SETTING_FILENAME) f = file(SETTING_FILENAME)
setting = json.load(f) setting = json.load(f)
if setting['language'] == 'English': if setting['language'] == 'english':
from English import text, constant from english import text, constant
f.close() f.close()
except: except:
pass pass

View File

@ -123,4 +123,11 @@ TEST = u'测试'
CONNECT = u'连接' CONNECT = u'连接'
CPU_MEMORY_INFO = u'CPU使用率{cpu}% 内存使用率:{memory}%' CPU_MEMORY_INFO = u'CPU使用率{cpu}% 内存使用率:{memory}%'
CONFIRM_EXIT = u'确认退出?' 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没有连接'

View File

@ -123,4 +123,11 @@ TEST = u'Test'
CONNECT = u'Connect ' CONNECT = u'Connect '
CPU_MEMORY_INFO = u'CPU Usage{cpu}% Memory Usage{memory}%' CPU_MEMORY_INFO = u'CPU Usage{cpu}% Memory Usage{memory}%'
CONFIRM_EXIT = u'Confirm Exit' 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 failedplease 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.'

View File

@ -5,7 +5,7 @@ import os
import traceback 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__), '..', '..'))
@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
try: try:
f = file(SETTING_FILENAME) f = file(SETTING_FILENAME)
setting = json.load(f) setting = json.load(f)
if setting['language'] == 'English': if setting['language'] == 'english':
from English import text from english import text
f.close() f.close()
except: except:
traceback.print_exc() traceback.print_exc()

View File

@ -10,6 +10,7 @@ from pymongo.errors import ConnectionFailure
from eventEngine import * from eventEngine import *
from vtGateway import * from vtGateway import *
from vtFunction import loadMongoSetting from vtFunction import loadMongoSetting
from language import text
from gateway import GATEWAY_DICT from gateway import GATEWAY_DICT
from ctaStrategy.ctaEngine import CtaEngine from ctaStrategy.ctaEngine import CtaEngine
@ -75,7 +76,7 @@ class MainEngine(object):
# 接口连接后自动执行数据库连接的任务 # 接口连接后自动执行数据库连接的任务
self.dbConnect() self.dbConnect()
else: else:
self.writeLog(u'接口不存在:%s' %gatewayName) self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def subscribe(self, subscribeReq, gatewayName): def subscribe(self, subscribeReq, gatewayName):
@ -84,7 +85,7 @@ class MainEngine(object):
gateway = self.gatewayDict[gatewayName] gateway = self.gatewayDict[gatewayName]
gateway.subscribe(subscribeReq) gateway.subscribe(subscribeReq)
else: else:
self.writeLog(u'接口不存在:%s' %gatewayName) self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def sendOrder(self, orderReq, gatewayName): def sendOrder(self, orderReq, gatewayName):
@ -97,7 +98,7 @@ class MainEngine(object):
gateway = self.gatewayDict[gatewayName] gateway = self.gatewayDict[gatewayName]
return gateway.sendOrder(orderReq) return gateway.sendOrder(orderReq)
else: else:
self.writeLog(u'接口不存在:%s' %gatewayName) self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def cancelOrder(self, cancelOrderReq, gatewayName): def cancelOrder(self, cancelOrderReq, gatewayName):
@ -106,7 +107,8 @@ class MainEngine(object):
gateway = self.gatewayDict[gatewayName] gateway = self.gatewayDict[gatewayName]
gateway.cancelOrder(cancelOrderReq) gateway.cancelOrder(cancelOrderReq)
else: else:
self.writeLog(u'接口不存在:%s' %gatewayName) self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def qryAccount(self, gatewayName): def qryAccount(self, gatewayName):
@ -115,7 +117,7 @@ class MainEngine(object):
gateway = self.gatewayDict[gatewayName] gateway = self.gatewayDict[gatewayName]
gateway.qryAccount() gateway.qryAccount()
else: else:
self.writeLog(u'接口不存在:%s' %gatewayName) self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def qryPosition(self, gatewayName): def qryPosition(self, gatewayName):
@ -124,7 +126,7 @@ class MainEngine(object):
gateway = self.gatewayDict[gatewayName] gateway = self.gatewayDict[gatewayName]
gateway.qryPosition() gateway.qryPosition()
else: else:
self.writeLog(u'接口不存在:%s' %gatewayName) self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def exit(self): def exit(self):
@ -165,14 +167,14 @@ class MainEngine(object):
# 调用server_info查询服务器状态防止服务器异常并未连接成功 # 调用server_info查询服务器状态防止服务器异常并未连接成功
self.dbClient.server_info() self.dbClient.server_info()
self.writeLog(u'MongoDB连接成功') self.writeLog(text.DATABASE_CONNECTING_COMPLETED)
# 如果启动日志记录,则注册日志事件监听函数 # 如果启动日志记录,则注册日志事件监听函数
if logging: if logging:
self.eventEngine.register(EVENT_LOG, self.dbLogging) self.eventEngine.register(EVENT_LOG, self.dbLogging)
except ConnectionFailure: except ConnectionFailure:
self.writeLog(u'MongoDB连接失败') self.writeLog(text.DATABASE_CONNECTING_FAILED)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def dbInsert(self, dbName, collectionName, d): def dbInsert(self, dbName, collectionName, d):
@ -182,7 +184,7 @@ class MainEngine(object):
collection = db[collectionName] collection = db[collectionName]
collection.insert_one(d) collection.insert_one(d)
else: else:
self.writeLog(u'数据插入失败MongoDB没有连接') self.writeLog(text.DATA_INSERT_FAILED)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def dbQuery(self, dbName, collectionName, d): def dbQuery(self, dbName, collectionName, d):
@ -196,7 +198,7 @@ class MainEngine(object):
else: else:
return [] return []
else: else:
self.writeLog(u'数据查询失败MongoDB没有连接') self.writeLog(text.DATA_QUERY_FAILED)
return [] return []
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@ -207,7 +209,7 @@ class MainEngine(object):
collection = db[collectionName] collection = db[collectionName]
collection.replace_one(flt, d, upsert) collection.replace_one(flt, d, upsert)
else: else:
self.writeLog(u'数据更新失败MongoDB没有连接') self.writeLog(text.DATA_UPDATE_FAILED)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def dbLogging(self, event): def dbLogging(self, event):