From bca6196ee28a64d4297804141eb46dadb66e4399 Mon Sep 17 00:00:00 2001 From: msincenselee Date: Fri, 23 Feb 2018 16:07:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=85=88=E4=BD=BF=E7=94=A8=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E7=9B=AE=E5=BD=95=E4=B8=8B=E5=AD=98=E5=9C=A8=E7=9A=84?= =?UTF-8?q?data=E5=AD=90=E7=9B=AE=E5=BD=95=E4=BD=9C=E4=B8=BA=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/app/ctaStrategy/ctaGridTrade.py | 27 ++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/vnpy/trader/app/ctaStrategy/ctaGridTrade.py b/vnpy/trader/app/ctaStrategy/ctaGridTrade.py index 99bd7c48..6d318a77 100644 --- a/vnpy/trader/app/ctaStrategy/ctaGridTrade.py +++ b/vnpy/trader/app/ctaStrategy/ctaGridTrade.py @@ -794,11 +794,19 @@ class CtaGridTrade(object): # 更新开仓均价 self.recount_avg_open_price() - path = os.path.abspath(os.path.dirname(__file__)) + + # 工作目录 + currentFolder = os.path.abspath(os.path.join(os.getcwd(), u'data')) + if os.path.isdir(currentFolder): + # 如果工作目录下,存在data子目录,就使用data子目录 + path = currentFolder + else: + # 否则,使用缺省保存目录 vnpy/trader/app/ctaStrategy/data + path = os.path.abspath(os.path.join(os.path.dirname(__file__), u'data')) # 保存上网格列表 if direction == DIRECTION_SHORT: - jsonFileName = os.path.join(path, u'data', u'{0}_upGrids.json'.format(self.jsonName)) + jsonFileName = os.path.join(path, u'{0}_upGrids.json'.format(self.jsonName)) l = [] for grid in self.upGrids: @@ -812,7 +820,7 @@ class CtaGridTrade(object): # 保存上网格列表 if direction == DIRECTION_LONG: - jsonFileName = os.path.join(path, u'data', u'{0}_dnGrids.json'.format(self.jsonName)) + jsonFileName = os.path.join(path, u'{0}_dnGrids.json'.format(self.jsonName)) l = [] for grid in self.dnGrids: @@ -832,13 +840,20 @@ class CtaGridTrade(object): :return: """ - path = os.path.abspath(os.path.dirname(__file__)) + # 工作目录 + currentFolder = os.path.abspath(os.path.join(os.getcwd(), u'data')) + if os.path.isdir(currentFolder): + # 如果工作目录下,存在data子目录,就使用data子目录 + path = currentFolder + else: + # 否则,使用缺省保存目录 vnpy/trader/app/ctaStrategy/data + path = os.path.abspath(os.path.join(os.path.dirname(__file__), u'data')) if direction == DIRECTION_SHORT: - jsonFileName = os.path.join(path, u'data', u'{0}_upGrids.json'.format(self.jsonName)) + jsonFileName = os.path.join(path, '{0}_upGrids.json'.format(self.jsonName)) self.writeCtaLog(u'开始加载上网格文件{0}'.format(jsonFileName)) if direction == DIRECTION_LONG: - jsonFileName = os.path.join(path, u'data', u'{0}_dnGrids.json'.format(self.jsonName)) + jsonFileName = os.path.join(path, u'{0}_dnGrids.json'.format(self.jsonName)) self.writeCtaLog(u'开始加载上网格文件{0}'.format(jsonFileName)) if not os.path.isfile(jsonFileName):