diff --git a/vnpy/trader/vtFunction.py b/vnpy/trader/vtFunction.py index e5b4eb71..1fc55c9a 100644 --- a/vnpy/trader/vtFunction.py +++ b/vnpy/trader/vtFunction.py @@ -7,13 +7,10 @@ import os import decimal import json +import traceback from datetime import datetime from math import isnan -from vtGlobal import globalSetting - -MAX_NUMBER = 10000000000000 -MAX_DECIMAL = globalSetting.get('maxDecimal', 4) #---------------------------------------------------------------------- def safeUnicode(value): @@ -93,6 +90,29 @@ def getJsonPath(name, moduleFile): jsonPathDict[name] = moduleJsonPath return moduleJsonPath + +# 加载全局配置 +#---------------------------------------------------------------------- +def loadJsonSetting(settingFileName): + """加载JSON配置""" + settingFilePath = getJsonPath(settingFileName, __file__) + + setting = {} + + try: + with open(settingFilePath, 'rb') as f: + setting = f.read() + if type(setting) is not str: + setting = str(setting, encoding='utf8') + setting = json.loads(setting) + except: + traceback.print_exc() + + return setting - +# 函数常量 +MAX_NUMBER = 10000000000000 + +globalSetting = loadJsonSetting('VT_setting.json') +MAX_DECIMAL = globalSetting.get('maxDecimal', 4) diff --git a/vnpy/trader/vtGlobal.py b/vnpy/trader/vtGlobal.py index 420b9fa7..d9385534 100644 --- a/vnpy/trader/vtGlobal.py +++ b/vnpy/trader/vtGlobal.py @@ -7,20 +7,7 @@ import os import traceback import json -from .vtFunction import getJsonPath - +from .vtFunction import loadJsonSetting settingFileName = "VT_setting.json" -settingFilePath = getJsonPath(settingFileName, __file__) - -globalSetting = {} # 全局配置字典 - -try: - with open(settingFilePath, 'rb') as f: - setting = f.read() - if type(setting) is not str: - setting = str(setting, encoding='utf8') - globalSetting = json.loads(setting) -except: - traceback.print_exc() - +globalSetting = loadJsonSetting(settingFileName) \ No newline at end of file