diff --git a/vnpy/api/okex/vnokex.py b/vnpy/api/okex/vnokex.py index 7d769b31..4e65c959 100644 --- a/vnpy/api/okex/vnokex.py +++ b/vnpy/api/okex/vnokex.py @@ -6,6 +6,7 @@ import ssl import hashlib import json import traceback +import zlib from threading import Thread from time import sleep @@ -145,7 +146,13 @@ class OkexApi(object): #---------------------------------------------------------------------- def readData(self, evt): """解码推送收到的数据""" - data = json.loads(evt) + # 先解压 + decompress = zlib.decompressobj(-zlib.MAX_WBITS) + inflated = decompress.decompress(evt) + inflated += decompress.flush() + + # 再转换为json + data = json.loads(inflated) return data #---------------------------------------------------------------------- diff --git a/vnpy/trader/app/ctaStrategy/ctaEngine.py b/vnpy/trader/app/ctaStrategy/ctaEngine.py index 8536d1df..a45e1db2 100644 --- a/vnpy/trader/app/ctaStrategy/ctaEngine.py +++ b/vnpy/trader/app/ctaStrategy/ctaEngine.py @@ -441,9 +441,9 @@ class CtaEngine(AppEngine): strategy = self.strategyDict[name] if not strategy.inited: - self.callStrategyFunc(strategy, strategy.onInit) strategy.inited = True - + self.callStrategyFunc(strategy, strategy.onInit) + self.loadSyncData(strategy) # 初始化完成后加载同步数据 self.subscribeMarketData(strategy) # 加载同步数据后再订阅行情 else: diff --git a/vnpy/trader/vtEngine.py b/vnpy/trader/vtEngine.py index 63499977..ee683840 100644 --- a/vnpy/trader/vtEngine.py +++ b/vnpy/trader/vtEngine.py @@ -700,7 +700,7 @@ class LogEngine(object): if not filename: filename = 'vt_' + datetime.now().strftime('%Y%m%d') + '.log' filepath = getTempPath(filename) - self.fileHandler = logging.FileHandler(filepath) + self.fileHandler = logging.FileHandler(filepath, mode='w', encoding='utf-8') self.fileHandler.setLevel(self.level) self.fileHandler.setFormatter(self.formatter) self.logger.addHandler(self.fileHandler)