[bug fix]

This commit is contained in:
msincenselee 2020-07-16 20:41:07 +08:00
parent 658faafd8b
commit 338db92c03
6 changed files with 957 additions and 77 deletions

View File

@ -31,3 +31,13 @@
}
}
}
# 创建mongodb 索引,提高性能
db.today_orders.createIndex({'account_id':1,'vt_symbol':1,'sys_orderid':1,'order_date':1,'holder_id':1},{'name':'accountid_vtsymbol_sysorderid_order_date_holder_id','unique':true})
db.history_orders.createIndex({'account_id':1,'vt_symbol':1,'sys_orderid':1,'order_date':1,'holder_id':1},{'name':'history_accountid_vtsymbol_sysorderid_order_date_holder_id'})
db.today_trades.createIndex({'account_id':1,'vt_symbol':1,'vt_tradeid':1,'trade_date':1,'holder_id':1},{'name':'accountid_vtSymbol_vt_tradeid_trade_date_holder_id','unique':true})
db.history_trades.createIndex({'account_id':1,'vt_symbol':1,'vt_tradeid':1,'trade_date':1,'holder_id':1},{'name':'accountid_vtSymbol_vt_tradeid_trade_date_holder_id'})
db.today_positions.createIndex({'account_id':1,'vt_symbol':1,'direction':1,'trade_date':1,'holder_id':1},{'name':'accountid_vtsymbol_direction_trade_date_holder_id'})
db.today_strategy_pos.createIndex({'account_id':1,'strategy_group':1,'strategy_name':1,'date':1},{'name':'accountid_strategy_group_strategy_name_date'})
db.strategy_snapshot.createIndex({'account_id':1,'strategy_group':1,'strategy':1,'guid':1},{'name':'accountid_strategy_name_guid'})

View File

@ -117,7 +117,11 @@ class AlgoTemplate:
offset: Offset = Offset.NONE
):
""""""
msg = f"委托买入{vt_symbol}{volume}@{price}"
if offset in [Offset.CLOSE]:
msg = f"委托买平{vt_symbol}{volume}@{price}"
else:
msg = f"委托买入{vt_symbol}{volume}@{price}"
self.write_log(msg)
return self.algo_engine.send_order(
@ -139,7 +143,11 @@ class AlgoTemplate:
offset: Offset = Offset.NONE
):
""""""
msg = f"委托卖出{vt_symbol}{volume}@{price}"
if offset in [Offset.NONE, Offset.CLOSE]:
msg = f"委托卖出{vt_symbol}{volume}@{price}"
else:
msg = f"委托开空{vt_symbol}{volume}@{price}"
self.write_log(msg)
return self.algo_engine.send_order(

View File

@ -234,7 +234,6 @@ class CtaEngine(BaseEngine):
# 比对仓位,使用上述获取得持仓信息,不用重复获取
self.compare_pos(strategy_pos_list=copy(all_strategy_pos))
# 推送到事件
self.put_all_strategy_pos_event(all_strategy_pos)

View File

@ -804,8 +804,10 @@ class CtaProTemplate(CtaTemplate):
self.display_grids()
if not self.backtesting:
pos_symbols.add(self.vt_symbol)
pos_symbols.add(self.idx_symbol)
if self.vt_symbol not in pos_symbols:
pos_symbols.add(self.vt_symbol)
if self.idx_symbol not in pos_symbols:
pos_symbols.add(self.idx_symbol)
# 如果持仓的合约不在self.vt_symbol中需要订阅
for symbol in list(pos_symbols):
self.write_log(f'新增订阅合约:{symbol}')
@ -1807,7 +1809,7 @@ class CtaProFutureTemplate(CtaProTemplate):
# 当前没有昨仓,采用锁仓处理
else:
self.write_log(u'昨仓多单:{}不满足条件,创建对锁仓'.format(grid_pos.longYd))
self.write_log(u'昨仓多单:{}不满足条件,创建对锁仓'.format(grid_pos.long_yd))
dist_record = dict()
dist_record['datetime'] = self.cur_datetime
dist_record['symbol'] = sell_symbol
@ -1907,7 +1909,7 @@ class CtaProFutureTemplate(CtaProTemplate):
# 当前没有昨仓,采用锁仓处理
else:
self.write_log(u'昨仓空单:{}不满足条件,建立对锁仓'.format(grid_pos.shortYd))
self.write_log(u'昨仓空单:{}不满足条件,建立对锁仓'.format(grid_pos.short_yd))
dist_record = dict()
dist_record['datetime'] = self.cur_datetime
dist_record['symbol'] = cover_symbol

View File

@ -1875,7 +1875,7 @@ class TickCombiner(object):
ratio_tick.date = tick.date
ratio_tick.time = tick.time
# 比率tick
# 比率tick = (腿1 * 腿1 手数 / 腿2价格 * 腿2手数) 百分比
ratio_tick.ask_price_1 = 100 * self.last_leg1_tick.ask_price_1 * self.leg1_ratio \
/ (self.last_leg2_tick.bid_price_1 * self.leg2_ratio) # noqa
ratio_tick.ask_price_1 = round_to(

File diff suppressed because it is too large Load Diff