diff --git a/vnpy/app/cta_strategy_pro/back_testing.py b/vnpy/app/cta_strategy_pro/back_testing.py index da4c334a..29091488 100644 --- a/vnpy/app/cta_strategy_pro/back_testing.py +++ b/vnpy/app/cta_strategy_pro/back_testing.py @@ -407,7 +407,10 @@ class BackTestingEngine(object): def get_commission_rate(self, vt_symbol: str): """ 获取保证金比例,缺省万分之一""" - return self.commission_rate.get(vt_symbol, float(0.00001)) + if vt_symbol not in self.commission_rate: + symbol, exchange = extract_vt_symbol(vt_symbol) + return self.commission_rate.get(symbol, float(0.0001)) + return self.commission_rate.get(vt_symbol, float(0.0001)) def get_fix_commission(self, vt_symbol: str): return self.fix_commission.get(vt_symbol, 0) @@ -623,11 +626,12 @@ class BackTestingEngine(object): self.set_margin_rate(symbol, margin_rate) self.set_commission_rate(symbol, symbol_data.get('commission_rate', float(0.0001))) - + exchange = symbol_data.get('exchange', 'LOCAL') + self.set_commission_rate(f'{symbol}.{exchange}', symbol_data.get('commission_rate', float(0.0001))) self.set_contract( symbol=symbol, name=symbol, - exchange=Exchange(symbol_data.get('exchange', 'LOCAL')), + exchange=Exchange(exchange), product=Product(symbol_data.get('product', "期货")), size=symbol_data.get('symbol_size', 10), price_tick=symbol_data.get('price_tick', 1), @@ -1874,6 +1878,7 @@ class BackTestingEngine(object): # 不计算套利合约的持仓占用保证金 if t.vt_symbol.endswith('SPD') or t.vt_symbol.endswith('SPD99'): continue + cur_occupy_money = 0 # 当前空单保证金 if self.use_margin: try: diff --git a/vnpy/app/cta_strategy_pro/engine.py b/vnpy/app/cta_strategy_pro/engine.py index e0579399..74640df6 100644 --- a/vnpy/app/cta_strategy_pro/engine.py +++ b/vnpy/app/cta_strategy_pro/engine.py @@ -1065,8 +1065,9 @@ class CtaEngine(BaseEngine): except Exception: strategy.trading = False strategy.inited = False + accountid = self.engine_config.get('accountid', 'XXX') - msg = f"触发异常已停止\n{traceback.format_exc()}" + msg = f"{accountid}/{strategy.strategy_name}触发异常已停止\n{traceback.format_exc()}" self.write_log(msg=msg, strategy_name=strategy.strategy_name, level=logging.CRITICAL) diff --git a/vnpy/app/cta_strategy_pro/template.py b/vnpy/app/cta_strategy_pro/template.py index ba01867e..fd9defaa 100644 --- a/vnpy/app/cta_strategy_pro/template.py +++ b/vnpy/app/cta_strategy_pro/template.py @@ -899,6 +899,7 @@ class CtaProTemplate(CtaTemplate): none_mi_grid = None none_mi_symbol = None + self.write_log(f'持仓换月=>启动.') # 找出非主力合约的持仓网格 for g in self.gt.get_opened_grids(direction=Direction.LONG): @@ -1648,11 +1649,20 @@ class CtaProFutureTemplate(CtaProTemplate): self.gt.save() + # 普通限价单委托方式 else: pre_status = old_order.get('status', Status.NOTTRADED) old_order.update({'status': Status.CANCELLED}) + self.write_log(u'委托单状态:{}=>{}'.format(pre_status, old_order.get('status'))) if grid: + # 判断是否有部分交易 + if order.traded > 0: + old_traded_volume = grid.traded_volume + grid.traded_volume += order.traded + self.write_log(f'{grid.direction.value}单部分{order.offset}仓,' + + f'网格volume:{grid.volume}, traded_volume:{old_traded_volume}=>{grid.traded_volume}') + if order.vt_orderid in grid.order_ids: grid.order_ids.remove(order.vt_orderid) if len(grid.order_ids) == 0: @@ -1709,14 +1719,16 @@ class CtaProFutureTemplate(CtaProTemplate): self.active_orders.update({vt_orderid: order_info}) ret = self.cancel_order(str(vt_orderid)) if not ret: - self.write_log(u'撤单逻辑 => 撤单失败,更新状态为撤单成功') - order_info.update({'status': Status.CANCELLED}) - self.active_orders.update({vt_orderid: order_info}) - if order_grid: - if vt_orderid in order_grid.order_ids: - order_grid.order_ids.remove(vt_orderid) - if len(order_grid.order_ids) == 0: - order_grid.order_status = False + self.write_error(f'{self.strategy_name}撤单逻辑 => {order_vt_symbol}撤单失败') + + #self.write_log(u'撤单逻辑 => 撤单失败,更新状态为撤单成功') + # order_info.update({'status': Status.CANCELLED}) + # self.active_orders.update({vt_orderid: order_info}) + # if order_grid: + # if vt_orderid in order_grid.order_ids: + # order_grid.order_ids.remove(vt_orderid) + # if len(order_grid.order_ids) == 0: + # order_grid.order_status = False continue # 处理状态为‘撤销’的委托单