diff --git a/vnpy/app/cta_crypto/back_testing.py b/vnpy/app/cta_crypto/back_testing.py index c136419c..8ecdf7bf 100644 --- a/vnpy/app/cta_crypto/back_testing.py +++ b/vnpy/app/cta_crypto/back_testing.py @@ -385,7 +385,7 @@ class BackTestingEngine(object): def get_exchange(self, symbol: str): return self.symbol_exchange_dict.get(symbol, Exchange.LOCAL) - def get_position(self, vt_symbol: str, direction: Direction, gateway_name: str = ''): + def get_position(self, vt_symbol: str, direction: Direction = Direction.NET, gateway_name: str = ''): """ 查询合约在账号的持仓""" if not gateway_name: gateway_name = self.gateway_name diff --git a/vnpy/app/cta_crypto/template.py b/vnpy/app/cta_crypto/template.py index 12fadc55..aaf5f90e 100644 --- a/vnpy/app/cta_crypto/template.py +++ b/vnpy/app/cta_crypto/template.py @@ -20,6 +20,7 @@ from .base import StopOrder from vnpy.component.cta_grid_trade import CtaGrid, CtaGridTrade from vnpy.component.cta_position import CtaPosition + class CtaTemplate(ABC): """CTA策略模板""" @@ -853,6 +854,10 @@ class CtaFutureTemplate(CtaTemplate): grid = old_order.get('grid', None) pre_status = old_order.get('status', Status.NOTTRADED) + if pre_status == Status.CANCELLED: + self.write_log(f'当前状态已经是{Status.CANCELLED},不做调整处理') + return + old_order.update({'status': Status.CANCELLED}) self.write_log(u'委托单状态:{}=>{}'.format(pre_status, old_order.get('status'))) if grid: @@ -862,7 +867,7 @@ class CtaFutureTemplate(CtaTemplate): pre_traded_volume = grid.traded_volume grid.traded_volume = round(grid.traded_volume + order.traded, 7) self.write_log(f'撤单中部分开仓:{order.traded} + 原已成交:{pre_traded_volume} => {grid.traded_volume}') - if len(grid.order_ids)==0: + if len(grid.order_ids) == 0: grid.order_status = False if grid.traded_volume > 0: pre_volume = grid.volume @@ -891,6 +896,10 @@ class CtaFutureTemplate(CtaTemplate): grid = old_order.get('grid', None) pre_status = old_order.get('status', Status.NOTTRADED) + if pre_status == Status.CANCELLED: + self.write_log(f'当前状态已经是{Status.CANCELLED},不做调整处理') + return + old_order.update({'status': Status.CANCELLED}) self.write_log(u'委托单状态:{}=>{}'.format(pre_status, old_order.get('status'))) if grid: @@ -1277,7 +1286,7 @@ class CtaFutureTemplate(CtaTemplate): and order_grid \ and len(order_grid.order_ids) == 0 \ and not order_grid.open_status \ - and not order_grid.order_status \ + and not order_grid.order_status \ and order_grid.traded_volume == 0: self.write_log(u'移除从未开仓成功的委托网格{}'.format(order_grid.__dict__)) order_info['grid'] = None @@ -1297,7 +1306,8 @@ class CtaFutureTemplate(CtaTemplate): return self.account_pos = self.cta_engine.get_position(vt_symbol=self.vt_symbol, direction=Direction.NET) if self.account_pos: - self.write_log(f'账号{self.vt_symbol}持仓:{self.account_pos.volume}, 冻结:{self.account_pos.frozen}, 盈亏:{self.account_pos.pnl}') + self.write_log( + f'账号{self.vt_symbol}持仓:{self.account_pos.volume}, 冻结:{self.account_pos.frozen}, 盈亏:{self.account_pos.pnl}') up_grids_info = "" for grid in list(self.gt.up_grids): diff --git a/vnpy/app/cta_strategy_pro/back_testing.py b/vnpy/app/cta_strategy_pro/back_testing.py index 6d910a5a..22d66cfd 100644 --- a/vnpy/app/cta_strategy_pro/back_testing.py +++ b/vnpy/app/cta_strategy_pro/back_testing.py @@ -1263,7 +1263,7 @@ class BackTestingEngine(object): if v.long_td > 0: self.write_log(u'调整多单持仓:今仓{}=> 0 昨仓{} => 昨仓:{}'.format(v.long_td, v.long_yd, v.long_pos)) v.long_td = 0 - v.longYd = v.long_pos + v.long_yd = v.long_pos if v.short_td > 0: self.write_log(u'调整空单持仓:今仓{}=> 0 昨仓{} => 昨仓:{}'.format(v.short_td, v.short_yd, v.short_pos)) diff --git a/vnpy/component/cta_line_bar.py b/vnpy/component/cta_line_bar.py index fc09765a..b32d1327 100644 --- a/vnpy/component/cta_line_bar.py +++ b/vnpy/component/cta_line_bar.py @@ -635,7 +635,7 @@ class CtaLineBar(object): # 波段买卖指标 self.line_bd_fast = [] # 波段快线 self.line_bd_slow = [] # 波段慢线 - self.cur_bd_cross = 0 # 当前波段快线慢线金叉死叉, +金叉计算, - 死叉技术 + self.cur_bd_count = 0 # 当前波段快线慢线金叉死叉, +金叉计算, - 死叉技术 def set_params(self, setting: dict = {}): """设置参数""" @@ -4029,9 +4029,9 @@ class CtaLineBar(object): # 判断金叉/死叉 if len(self.line_bd_fast) > 2 and len(self.line_bd_slow) > 2: if self.line_bd_fast[-1] > self.line_bd_slow[-1]: - self.cur_bd_cross = max(1, self.cur_bd_cross + 1) + self.cur_bd_count = max(1, self.cur_bd_count + 1) elif self.line_bd_fast[-1] < self.line_bd_slow[-1]: - self.cur_bd_cross = min(-1, self.cur_bd_cross -1) + self.cur_bd_count = min(-1, self.cur_bd_count - 1) def write_log(self, content): """记录CTA日志"""