|
@@ -370,32 +370,6 @@ class Strategy:
|
|
|
signals['Limits_close'].append([amount, 'pk', price,utils.get_cid(self.broker_id)])
|
|
signals['Limits_close'].append([amount, 'pk', price,utils.get_cid(self.broker_id)])
|
|
|
return signals
|
|
return signals
|
|
|
|
|
|
|
|
- # def _cancel_close(self):
|
|
|
|
|
- # '''
|
|
|
|
|
- # 取消平仓订单
|
|
|
|
|
- # '''
|
|
|
|
|
- # # 准备命令
|
|
|
|
|
- # signals = dict()
|
|
|
|
|
- # # 撤掉危险挂单
|
|
|
|
|
- # cond1 = self.close_dist[0]
|
|
|
|
|
- # cond2 = self.close_dist[1]
|
|
|
|
|
- # cond3 = self.close_dist[2]
|
|
|
|
|
- # cond4 = self.close_dist[3]
|
|
|
|
|
- # # # 获取当前挂单
|
|
|
|
|
- # for cid in self.local_orders:
|
|
|
|
|
- # i = self.local_orders[cid]
|
|
|
|
|
- # if i['side'] == 'pk':
|
|
|
|
|
- # if (i['price'] >= cond1 or i['price'] <= cond2):
|
|
|
|
|
- # cid = i['client_id']
|
|
|
|
|
- # oid = i['order_id']
|
|
|
|
|
- # signals[f'Cancel{cid}'] = [cid, oid]
|
|
|
|
|
- # if i['side'] == 'pd':
|
|
|
|
|
- # if (i['price'] <= cond3 or i['price'] >= cond4):
|
|
|
|
|
- # cid = i['client_id']
|
|
|
|
|
- # oid = i['order_id']
|
|
|
|
|
- # signals[f'Cancel{cid}'] = [cid, oid]
|
|
|
|
|
- # return signals
|
|
|
|
|
-
|
|
|
|
|
def _post_close(self):
|
|
def _post_close(self):
|
|
|
'''
|
|
'''
|
|
|
处理平仓
|
|
处理平仓
|
|
@@ -595,81 +569,6 @@ class Strategy:
|
|
|
amount_value = float(amount) * self.mp
|
|
amount_value = float(amount) * self.mp
|
|
|
if amount_value >= self._min_amount_value and amount_value <= short_free_value:
|
|
if amount_value >= self._min_amount_value and amount_value <= short_free_value:
|
|
|
signals['Limits_open'].append([amount, 'kk', targit_sell_price, utils.get_cid(self.broker_id)])
|
|
signals['Limits_open'].append([amount, 'kk', targit_sell_price, utils.get_cid(self.broker_id)])
|
|
|
- ############## 多层挂单 #################
|
|
|
|
|
- # step = (cond1-cond2) / self.grid
|
|
|
|
|
- # ########### 挂多单 ###########
|
|
|
|
|
- # if self.post_side >= 0:
|
|
|
|
|
- # if len(buyP) == 0:
|
|
|
|
|
- # # 1
|
|
|
|
|
- # targit_buy_price = cond1 * 0.1 + cond2 * 0.9
|
|
|
|
|
- # targit_buy_price = utils.clip(targit_buy_price, self.bp*0.97, self.ap*1.0005)
|
|
|
|
|
- # targit_buy_price = self.fix_price(targit_buy_price)
|
|
|
|
|
- # value = min(one_hand_long_value, long_free_value)
|
|
|
|
|
- # amount = self.fix_amount(value/self.mp)
|
|
|
|
|
- # amount_value = float(amount) * self.mp
|
|
|
|
|
- # if targit_buy_price < cond1*(1-self.long_hold_rate) + cond2*self.long_hold_rate:
|
|
|
|
|
- # if amount_value >= self._min_amount_value and amount_value <= long_free_value:
|
|
|
|
|
- # signals['Limits_open'].append([amount, 'kd', targit_buy_price, utils.get_cid(self.broker_id)])
|
|
|
|
|
- # else:
|
|
|
|
|
- # # 2
|
|
|
|
|
- # targit_buy_price = max(buyP) + step
|
|
|
|
|
- # targit_buy_price = utils.clip(targit_buy_price, self.bp*0.97, self.ap*1.0005)
|
|
|
|
|
- # targit_buy_price = self.fix_price(targit_buy_price)
|
|
|
|
|
- # value = min(one_hand_long_value, long_free_value)
|
|
|
|
|
- # amount = self.fix_amount(value/self.mp)
|
|
|
|
|
- # amount_value = float(amount) * self.mp
|
|
|
|
|
- # if targit_buy_price < cond1*(1-self.long_hold_rate) + cond2*self.long_hold_rate:
|
|
|
|
|
- # if targit_buy_price < cond1 - 0.1*step and targit_buy_price > cond2 + 0.1*step:
|
|
|
|
|
- # if amount_value >= self._min_amount_value and amount_value <= long_free_value:
|
|
|
|
|
- # signals['Limits_open'].append([amount, 'kd', targit_buy_price, utils.get_cid(self.broker_id)])
|
|
|
|
|
- # # 3
|
|
|
|
|
- # targit_buy_price = min(buyP) - step
|
|
|
|
|
- # targit_buy_price = utils.clip(targit_buy_price, self.bp*0.97, self.ap*1.0005)
|
|
|
|
|
- # targit_buy_price = self.fix_price(targit_buy_price)
|
|
|
|
|
- # value = min(one_hand_long_value, long_free_value)
|
|
|
|
|
- # amount = self.fix_amount(value/self.mp)
|
|
|
|
|
- # amount_value = float(amount) * self.mp
|
|
|
|
|
- # if targit_buy_price < cond1*(1-self.long_hold_rate) + cond2*self.long_hold_rate:
|
|
|
|
|
- # if targit_buy_price < cond1 - 0.1*step and targit_buy_price > cond2 + 0.1*step:
|
|
|
|
|
- # if amount_value >= self._min_amount_value and amount_value <= long_free_value:
|
|
|
|
|
- # signals['Limits_open'].append([amount, 'kd', targit_buy_price, utils.get_cid(self.broker_id)])
|
|
|
|
|
- # ########### 挂空单 ###########
|
|
|
|
|
- # if self.post_side <= 0:
|
|
|
|
|
- # if len(sellP) == 0:
|
|
|
|
|
- # # 1
|
|
|
|
|
- # targit_sell_price = cond3 * 0.1 + cond4 * 0.9
|
|
|
|
|
- # targit_sell_price = utils.clip(targit_sell_price, self.bp*0.9995, self.ap*1.03)
|
|
|
|
|
- # targit_sell_price = self.fix_price(targit_sell_price)
|
|
|
|
|
- # value = min(one_hand_short_value, short_free_value)
|
|
|
|
|
- # amount = self.fix_amount(value/self.mp)
|
|
|
|
|
- # amount_value = float(amount) * self.mp
|
|
|
|
|
- # if targit_sell_price > cond3*(1-self.short_hold_rate) + cond4*self.short_hold_rate:
|
|
|
|
|
- # if amount_value >= self._min_amount_value and amount_value <= short_free_value:
|
|
|
|
|
- # signals['Limits_open'].append([amount, 'kk', targit_sell_price, utils.get_cid(self.broker_id)])
|
|
|
|
|
- # else:
|
|
|
|
|
- # # 2
|
|
|
|
|
- # targit_sell_price = min(sellP) - step
|
|
|
|
|
- # targit_sell_price = utils.clip(targit_sell_price, self.bp*0.9995, self.ap*1.03)
|
|
|
|
|
- # targit_sell_price = self.fix_price(targit_sell_price)
|
|
|
|
|
- # value = min(one_hand_short_value, short_free_value)
|
|
|
|
|
- # amount = self.fix_amount(value/self.mp)
|
|
|
|
|
- # amount_value = float(amount) * self.mp
|
|
|
|
|
- # if targit_sell_price > cond3*(1-self.short_hold_rate) + cond4*self.short_hold_rate:
|
|
|
|
|
- # if targit_sell_price > cond3 + 0.1*step and targit_sell_price < cond4 - 0.1*step:
|
|
|
|
|
- # if amount_value >= self._min_amount_value and amount_value <= short_free_value:
|
|
|
|
|
- # signals['Limits_open'].append([amount, 'kk', targit_sell_price, utils.get_cid(self.broker_id)])
|
|
|
|
|
- # # 3
|
|
|
|
|
- # targit_sell_price = max(sellP) + step
|
|
|
|
|
- # targit_sell_price = utils.clip(targit_sell_price, self.bp*0.9995, self.ap*1.03)
|
|
|
|
|
- # targit_sell_price = self.fix_price(targit_sell_price)
|
|
|
|
|
- # value = min(one_hand_short_value, short_free_value)
|
|
|
|
|
- # amount = self.fix_amount(value/self.mp)
|
|
|
|
|
- # amount_value = float(amount) * self.mp
|
|
|
|
|
- # if targit_sell_price > cond3*(1-self.short_hold_rate) + cond4*self.short_hold_rate:
|
|
|
|
|
- # if targit_sell_price > cond3 + 0.1*step and targit_sell_price < cond4 - 0.1*step:
|
|
|
|
|
- # if amount_value >= self._min_amount_value and amount_value <= short_free_value:
|
|
|
|
|
- # signals['Limits_open'].append([amount, 'kk', targit_sell_price, utils.get_cid(self.broker_id)])
|
|
|
|
|
- ############################################
|
|
|
|
|
return signals
|
|
return signals
|
|
|
|
|
|
|
|
# @utils.timeit
|
|
# @utils.timeit
|
|
@@ -915,97 +814,6 @@ class Strategy:
|
|
|
except:
|
|
except:
|
|
|
traceback.print_exc()
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
- # @timeit
|
|
|
|
|
- # def onOrder(self, data):
|
|
|
|
|
- # '''
|
|
|
|
|
- # call on order update event
|
|
|
|
|
- # '''
|
|
|
|
|
- # try:
|
|
|
|
|
- # # 更新状态
|
|
|
|
|
- # if self._update_data(data):
|
|
|
|
|
- # # 检查是否准备充分
|
|
|
|
|
- # if self.check_ready():
|
|
|
|
|
- # return dict()
|
|
|
|
|
- # ###### 关键操作 ######
|
|
|
|
|
- # # 更新挂单距离
|
|
|
|
|
- # self._pos_rate()
|
|
|
|
|
- # open_dist, close_dist = self.gen_dist(
|
|
|
|
|
- # open=self.trade_open_dist,
|
|
|
|
|
- # close=self.trade_close_dist,
|
|
|
|
|
- # pos_rate=[self.long_hold_rate, self.short_hold_rate],
|
|
|
|
|
- # ref_bp=self.ref_bp,
|
|
|
|
|
- # ref_ap=self.ref_ap,
|
|
|
|
|
- # predict=self.predict,
|
|
|
|
|
- # grid=self.grid,
|
|
|
|
|
- # mode=self.maker_mode,
|
|
|
|
|
- # )
|
|
|
|
|
- # self.open_dist = \
|
|
|
|
|
- # [
|
|
|
|
|
- # self.fix_price(open_dist[0]),
|
|
|
|
|
- # self.fix_price(open_dist[1]),
|
|
|
|
|
- # self.fix_price(open_dist[2]),
|
|
|
|
|
- # self.fix_price(open_dist[3]),
|
|
|
|
|
- # ]
|
|
|
|
|
- # self.close_dist = \
|
|
|
|
|
- # [
|
|
|
|
|
- # self.fix_price(close_dist[0]),
|
|
|
|
|
- # self.fix_price(close_dist[1]),
|
|
|
|
|
- # self.fix_price(close_dist[2]),
|
|
|
|
|
- # self.fix_price(close_dist[3]),
|
|
|
|
|
- # ]
|
|
|
|
|
- # # 获取开平仓指令
|
|
|
|
|
- # signals = dict()
|
|
|
|
|
- # # 获取平仓信号
|
|
|
|
|
- # signals.update(self._post_close())
|
|
|
|
|
- # # 更新撤单队列
|
|
|
|
|
- # signals = self._update_in_cancel(signals)
|
|
|
|
|
- # # 限制频率
|
|
|
|
|
- # signals = self._check_request_limit(signals)
|
|
|
|
|
- # # 统计请求频率
|
|
|
|
|
- # self._update_request_num(signals)
|
|
|
|
|
- # ##########################
|
|
|
|
|
- # return signals
|
|
|
|
|
- # except:
|
|
|
|
|
- # traceback.print_exc()
|
|
|
|
|
- # if self._is_print:self.logger.error(traceback.format_exc())
|
|
|
|
|
-
|
|
|
|
|
- # @timeit
|
|
|
|
|
- # def onTick(self, data):
|
|
|
|
|
- # '''
|
|
|
|
|
- # call on ticker update event
|
|
|
|
|
- # '''
|
|
|
|
|
- # try:
|
|
|
|
|
- # # 更新状态
|
|
|
|
|
- # if self._update_data(data):
|
|
|
|
|
- # # 检查是否准备充分
|
|
|
|
|
- # if self.check_ready():
|
|
|
|
|
- # return dict()
|
|
|
|
|
- # ###### 关键操作 ######
|
|
|
|
|
- # # 更新挂单距离
|
|
|
|
|
- # self.open_dist, self.close_dist = utils.gen_dist(
|
|
|
|
|
- # self.trade_open_dist,
|
|
|
|
|
- # self.trade_close_dist,
|
|
|
|
|
- # self._pos_rate(),
|
|
|
|
|
- # self.ref_bp,
|
|
|
|
|
- # self.ref_ap,
|
|
|
|
|
- # self.predict
|
|
|
|
|
- # )
|
|
|
|
|
- # # 获取开平仓指令
|
|
|
|
|
- # signals = dict()
|
|
|
|
|
- # # 获取平仓信号
|
|
|
|
|
- # signals.update(self._cancel_open())
|
|
|
|
|
- # # 更新撤单队列
|
|
|
|
|
- # signals = self._update_in_cancel(signals)
|
|
|
|
|
- # # 限制频率
|
|
|
|
|
- # signals = self._check_request_limit(signals)
|
|
|
|
|
- # # 统计请求频率
|
|
|
|
|
- # self._update_request_num(signals)
|
|
|
|
|
- # ##########################
|
|
|
|
|
- # return signals
|
|
|
|
|
- # except:
|
|
|
|
|
- # traceback.print_exc()
|
|
|
|
|
- # if self._is_print:self.logger.error(traceback.format_exc())
|
|
|
|
|
-
|
|
|
|
|
# @utils.timeit
|
|
# @utils.timeit
|
|
|
def onTime(self, data):
|
|
def onTime(self, data):
|
|
|
'''
|
|
'''
|