| | |
| | | return False, "" |
| | | |
| | | def __need_cancel_for_slow_sell(self, code, total_datas): |
| | | """ |
| | | S慢撤的目的是判断较大金额卖占整个卖的比例不能太大 |
| | | @param code: |
| | | @param total_datas: |
| | | @return: |
| | | """ |
| | | if code not in self.__s_slow_sell_watch_indexes_dict: |
| | | return False, "S慢砸没有囊括" |
| | | # 下单3分钟内有效 |
| | |
| | | real_order_time_ms = total_datas[real_order_index]["val"]["time"] + ".{0:0>3}".format( |
| | | total_datas[real_order_index]["val"]["tms"]) |
| | | |
| | | max_money = 0 |
| | | for x in big_sell_order_info[1]: |
| | | deal_time = l2_huaxin_util.convert_time(x[4][0], with_ms=True) |
| | | if real_order_time_ms: |
| | | if tool.trade_time_sub_with_ms(deal_time, real_order_time_ms) >= 0: |
| | | m = x[1] * x[2] |
| | | if max_money < m: |
| | | max_money = m |
| | | total_deal_money += m |
| | | else: |
| | | m = x[1] * x[2] |
| | | if max_money < m: |
| | | max_money = m |
| | | total_deal_money += m |
| | | if max_money >= 4990000: |
| | | return True, f"有大于499w大卖单({max_money})" |
| | | if total_deal_money >= 4990000: |
| | | return True, f"1s内大于499w大卖单({total_deal_money})" |
| | | |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | | # 判断是否为激进下单 |
| | |
| | | total_fast_num = 0 |
| | | if order_begin_pos.mode == OrderBeginPosInfo.MODE_ACTIVE: |
| | | try: |
| | | # 真实成交位距离真实下单位,10笔以内且金额≤1000万 , 且在180s内 |
| | | # 15分钟内真实成交位距离真实下单位,金额≤800万 ,大单阈值变为200w |
| | | trade_index, is_default = TradeBuyQueue().get_traded_index(code) |
| | | if trade_index is None: |
| | | trade_index = 0 |
| | |
| | | fdeal = big_sell_order_info[1][0][3] |
| | | start_order_no = fdeal[1] |
| | | sell_time_str = l2_huaxin_util.convert_time(fdeal[0], with_ms=False) |
| | | is_s_slow_timw = tool.trade_time_sub(sell_time_str, |
| | | total_datas[real_order_index]["val"]["time"]) < 180 |
| | | total_slow_num = 0 |
| | | total_slow_count = 0 |
| | | # 获取正在成交的数据 |
| | | dealing_info = HuaXinBuyOrderManager.get_dealing_order_info(code) |
| | | for i in range(trade_index, real_order_index): |
| | | data = total_datas[i] |
| | | val = data['val'] |
| | | if int(val['orderNo']) < start_order_no: |
| | | continue |
| | | if i == trade_index and dealing_info and str( |
| | | total_datas[trade_index]["val"]["orderNo"]) == str( |
| | | dealing_info[0]): |
| | | # 减去当前正在成交的数据中已经成交了的数据 |
| | | if is_s_slow_timw: |
| | | total_slow_num -= dealing_info[1] // 100 |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2( |
| | | code, |
| | | i, |
| | | total_datas, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if left_count > 0: |
| | | if is_s_slow_timw: |
| | | total_slow_num += val["num"] |
| | | total_slow_count += 1 |
| | | total_fast_num += val['num'] |
| | | if total_slow_num * float(limit_up_price) < 800 * 100: |
| | | threash_money_w = 200 |
| | | if tool.trade_time_sub(sell_time_str, total_datas[real_order_index]['val']['time']) < 15 * 60: |
| | | total_num = 0 |
| | | # 获取正在成交的数据 |
| | | dealing_info = HuaXinBuyOrderManager.get_dealing_order_info(code) |
| | | for i in range(trade_index, real_order_index): |
| | | data = total_datas[i] |
| | | val = data['val'] |
| | | if int(val['orderNo']) < start_order_no: |
| | | continue |
| | | if i == trade_index and dealing_info and str( |
| | | total_datas[trade_index]["val"]["orderNo"]) == str( |
| | | dealing_info[0]): |
| | | # 减去当前正在成交的数据中已经成交了的数据 |
| | | total_num -= dealing_info[1] // 100 |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2( |
| | | code, |
| | | i, |
| | | total_datas, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if left_count > 0: |
| | | total_num += val["num"] |
| | | total_fast_num += val['num'] |
| | | if total_num * float(limit_up_price) < 800 * 100: |
| | | threash_money_w = 200 |
| | | except Exception as e: |
| | | l2_log.s_cancel_debug(code, f"S撤激进下单计算大单卖阈值出错:{str(e)}") |
| | | total_fast_money = int(total_fast_num * 100 * float(limit_up_price)) |
| | |
| | | if total_deal_money >= threash_money_w * 10000 and rate >= 0.25: |
| | | return True, f"近1s有大卖单({round(total_deal_money / 10000, 1)}万/{threash_money_w}万,成交占比:{total_deal_money}/{total_fast_money})" |
| | | else: |
| | | l2_log.s_cancel_debug(code, f"S快撤没达到撤单比例:成交金额({total_deal_money})/囊括金额({total_fast_money}),比例:{rate} 大单阈值:{threash_money_w}w") |
| | | l2_log.s_cancel_debug(code, |
| | | f"S快撤没达到撤单比例:成交金额({total_deal_money})/囊括金额({total_fast_money}),比例:{rate} 大单阈值:{threash_money_w}w") |
| | | return False, f"无{threash_money_w}大单" |
| | | |
| | | # big_sell_order_info格式:[总共的卖单金额, 大卖单详情列表] |
| | |
| | | finally: |
| | | # self.__latest_process_sell_order_no[code] = big_sell_order_info[1][-1][0] |
| | | pass |
| | | |
| | | def need_cancel_for_down(self, code, start_index, end_index): |
| | | watch_index_info = self.__s_down_watch_indexes_dict.get(code) |
| | | if not watch_index_info: |
| | | return False, "没获取到囊括范围" |
| | | total_datas = local_today_datas.get(code) |
| | | if tool.trade_time_sub(total_datas[-1]["val"]["time"], watch_index_info[0].split(".")[0]) > 9: |
| | | return False, "超过守护时间" |
| | | |
| | | watch_indexes = watch_index_info[1] |
| | | watch_order_nos = set([total_datas[d]['val']['orderNo'] for d in watch_indexes]) |
| | | # 计算是否有撤单 |
| | | need_compute = False |
| | | for i in range(start_index, end_index + 1): |
| | | data = total_datas[i] |
| | | val = data['val'] |
| | | if not L2DataUtil.is_limit_up_price_buy_cancel(val): |
| | | continue |
| | | if val['orderNo'] in watch_order_nos: |
| | | need_compute = True |
| | | break |
| | | if not need_compute: |
| | | return False, "没有监听范围内的单撤单" |
| | | # 计算撤单比例 |
| | | total_num = 0 |
| | | cancel_num = 0 |
| | | for index in watch_indexes: |
| | | total_num += total_datas[index]["val"]['num'] |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, index, |
| | | total_datas, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if left_count <= 0: |
| | | cancel_num += total_datas[index]["val"]['num'] |
| | | cancel_rate = round(cancel_num / total_num, 4) |
| | | if cancel_rate >= 0.25: |
| | | return True, f"达到撤单比例:{cancel_rate} 监听范围:{watch_index_info}" |
| | | |
| | | return False, "没达到撤单比例" |
| | | |
| | | # ----------------------------S慢砸范围计算------------------------------------ |
| | | def __compute_s_slow_sell(self, code): |
| | |
| | | def cancel_success(self, code): |
| | | self.clear(code) |
| | | |
| | | # 下单3分钟内距离下单位置不足3笔且不到300w就需要撤单 |
| | | # 下单3分钟内距离下单位置不足3笔(包含正在成交)且不到300w就需要撤单 |
| | | def need_cancel_for_deal_fast(self, code, trade_index=None): |
| | | if trade_index is None: |
| | | trade_info = TradeBuyQueue().get_traded_index(code) |
| | |
| | | real_trade_index = i |
| | | break |
| | | |
| | | # 是否是下单5分钟内 |
| | | # 是否是下单3分钟内 |
| | | if tool.trade_time_sub(total_datas[-1]['val']['time'], total_datas[real_order_index]['val']['time']) > 180: |
| | | return False, "下单超过180s" |
| | | |
| | |
| | | self.__expire_time_dict[code] = tool.trade_time_add_second(now_time, 15) |
| | | |
| | | # 大有单卖 |
| | | # 暂时不启用 |
| | | def set_big_sell_order_info(self, code, big_sell_order_info): |
| | | money = big_sell_order_info[0] |
| | | if money < 50 * 10000: |
| | |
| | | if len(temp_list) > 15: |
| | | break |
| | | temp_list.sort(key=lambda x: x[0], reverse=True) |
| | | # 次大单的笔数1-3笔 |
| | | THRESH_COUNT = len(temp_list) // 5 |
| | | if THRESH_COUNT < 1: |
| | | THRESH_COUNT = 1 |
| | | if temp_list: |
| | | l2_log.g_cancel_debug(code, f"小单备用监听位置:{temp_list[0][1]['index']}") |
| | | watch_indexes.add(temp_list[0][1]["index"]) |
| | | for i in range(THRESH_COUNT): |
| | | l2_log.g_cancel_debug(code, f"小单备用监听位置:{temp_list[i][1]['index']}") |
| | | watch_indexes.add(temp_list[i][1]["index"]) |
| | | self.__watch_indexes_by_dict[code] = origin_watch_index_by | watch_indexes |
| | | |
| | | def set_trade_progress(self, code, buy_single_index, index): |