From 6431cfbb3a65b92a677c38d18a2e05aabedd7a5f Mon Sep 17 00:00:00 2001 From: msincenselee Date: Fri, 5 Jun 2020 13:38:49 +0800 Subject: [PATCH] [bug fix] --- vnpy/app/cta_stock/template.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vnpy/app/cta_stock/template.py b/vnpy/app/cta_stock/template.py index 8bbaf26e..8db1d2ad 100644 --- a/vnpy/app/cta_stock/template.py +++ b/vnpy/app/cta_stock/template.py @@ -587,17 +587,19 @@ class CtaStockTemplate(CtaTemplate): self.write_log(f'清除委托单:{lg.order_ids}') [self.cta_engine.cancel_order(self, vt_orderid) for vt_orderid in lg.order_ids] lg.order_ids = [] - if lg.open_status and not lg.close_status and not lg.open_status: + if lg.open_status and not lg.close_status and not lg.order_status: pos = self.get_position(lg.vt_symbol) pos.volume += lg.volume lg.traded_volume = 0 self.write_log(u'持仓状态,加载持仓多单[{},价格:{},数量:{}手, 开仓时间:{}' .format(lg.vt_symbol, lg.open_price, lg.volume, lg.open_time)) + self.positions.update({lg.vt_symbol: pos}) elif lg.order_status and not lg.open_status and not lg.close_status and lg.traded_volume > 0: pos = self.get_position(lg.vt_symbol) pos.volume += lg.traded_volume self.write_log(u'开仓状态,加载部分持仓多单[{},价格:{},数量:{}手, 开仓时间:{}' .format(lg.vt_symbol, lg.open_price, lg.traded_volume, lg.open_time)) + self.positions.update({lg.vt_symbol: pos}) elif lg.order_status and lg.open_status and lg.close_status: if lg.traded_volume > 0: old_volume = lg.volume @@ -609,6 +611,9 @@ class CtaStockTemplate(CtaTemplate): pos.volume += lg.volume self.write_log(u'卖出状态,加载持仓多单[{},价格:{},数量:{}手, 开仓时间:{}' .format(lg.vt_symbol, lg.open_price, lg.volume, lg.open_time)) + + self.positions.update({lg.vt_symbol: pos}) + self.gt.save() self.display_grids()