[bug fix] 币安合约重复委托返回的bug。
This commit is contained in:
parent
564b0b8c0a
commit
b6a277ac4d
@ -385,7 +385,7 @@ class BackTestingEngine(object):
|
|||||||
def get_exchange(self, symbol: str):
|
def get_exchange(self, symbol: str):
|
||||||
return self.symbol_exchange_dict.get(symbol, Exchange.LOCAL)
|
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:
|
if not gateway_name:
|
||||||
gateway_name = self.gateway_name
|
gateway_name = self.gateway_name
|
||||||
|
@ -20,6 +20,7 @@ from .base import StopOrder
|
|||||||
from vnpy.component.cta_grid_trade import CtaGrid, CtaGridTrade
|
from vnpy.component.cta_grid_trade import CtaGrid, CtaGridTrade
|
||||||
from vnpy.component.cta_position import CtaPosition
|
from vnpy.component.cta_position import CtaPosition
|
||||||
|
|
||||||
|
|
||||||
class CtaTemplate(ABC):
|
class CtaTemplate(ABC):
|
||||||
"""CTA策略模板"""
|
"""CTA策略模板"""
|
||||||
|
|
||||||
@ -853,6 +854,10 @@ class CtaFutureTemplate(CtaTemplate):
|
|||||||
grid = old_order.get('grid', None)
|
grid = old_order.get('grid', None)
|
||||||
|
|
||||||
pre_status = old_order.get('status', Status.NOTTRADED)
|
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})
|
old_order.update({'status': Status.CANCELLED})
|
||||||
self.write_log(u'委托单状态:{}=>{}'.format(pre_status, old_order.get('status')))
|
self.write_log(u'委托单状态:{}=>{}'.format(pre_status, old_order.get('status')))
|
||||||
if grid:
|
if grid:
|
||||||
@ -891,6 +896,10 @@ class CtaFutureTemplate(CtaTemplate):
|
|||||||
|
|
||||||
grid = old_order.get('grid', None)
|
grid = old_order.get('grid', None)
|
||||||
pre_status = old_order.get('status', Status.NOTTRADED)
|
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})
|
old_order.update({'status': Status.CANCELLED})
|
||||||
self.write_log(u'委托单状态:{}=>{}'.format(pre_status, old_order.get('status')))
|
self.write_log(u'委托单状态:{}=>{}'.format(pre_status, old_order.get('status')))
|
||||||
if grid:
|
if grid:
|
||||||
@ -1297,7 +1306,8 @@ class CtaFutureTemplate(CtaTemplate):
|
|||||||
return
|
return
|
||||||
self.account_pos = self.cta_engine.get_position(vt_symbol=self.vt_symbol, direction=Direction.NET)
|
self.account_pos = self.cta_engine.get_position(vt_symbol=self.vt_symbol, direction=Direction.NET)
|
||||||
if self.account_pos:
|
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 = ""
|
up_grids_info = ""
|
||||||
for grid in list(self.gt.up_grids):
|
for grid in list(self.gt.up_grids):
|
||||||
|
@ -1263,7 +1263,7 @@ class BackTestingEngine(object):
|
|||||||
if v.long_td > 0:
|
if v.long_td > 0:
|
||||||
self.write_log(u'调整多单持仓:今仓{}=> 0 昨仓{} => 昨仓:{}'.format(v.long_td, v.long_yd, v.long_pos))
|
self.write_log(u'调整多单持仓:今仓{}=> 0 昨仓{} => 昨仓:{}'.format(v.long_td, v.long_yd, v.long_pos))
|
||||||
v.long_td = 0
|
v.long_td = 0
|
||||||
v.longYd = v.long_pos
|
v.long_yd = v.long_pos
|
||||||
|
|
||||||
if v.short_td > 0:
|
if v.short_td > 0:
|
||||||
self.write_log(u'调整空单持仓:今仓{}=> 0 昨仓{} => 昨仓:{}'.format(v.short_td, v.short_yd, v.short_pos))
|
self.write_log(u'调整空单持仓:今仓{}=> 0 昨仓{} => 昨仓:{}'.format(v.short_td, v.short_yd, v.short_pos))
|
||||||
|
@ -635,7 +635,7 @@ class CtaLineBar(object):
|
|||||||
# 波段买卖指标
|
# 波段买卖指标
|
||||||
self.line_bd_fast = [] # 波段快线
|
self.line_bd_fast = [] # 波段快线
|
||||||
self.line_bd_slow = [] # 波段慢线
|
self.line_bd_slow = [] # 波段慢线
|
||||||
self.cur_bd_cross = 0 # 当前波段快线慢线金叉死叉, +金叉计算, - 死叉技术
|
self.cur_bd_count = 0 # 当前波段快线慢线金叉死叉, +金叉计算, - 死叉技术
|
||||||
|
|
||||||
def set_params(self, setting: dict = {}):
|
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 len(self.line_bd_fast) > 2 and len(self.line_bd_slow) > 2:
|
||||||
if self.line_bd_fast[-1] > self.line_bd_slow[-1]:
|
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]:
|
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):
|
def write_log(self, content):
|
||||||
"""记录CTA日志"""
|
"""记录CTA日志"""
|
||||||
|
Loading…
Reference in New Issue
Block a user