| | |
| | | total_datas = local_today_datas.get(code) |
| | | if total_datas: |
| | | # 计算的上截至位距离下截至位纯买额要小于2.5倍m值 |
| | | thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code) |
| | | thresh_hold_money = int(thresh_hold_money * 2.5) |
| | | threshold_num = thresh_hold_money // (float(gpcode_manager.get_limit_up_price(code)) * 100) |
| | | # thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code) |
| | | # thresh_hold_money = int(thresh_hold_money * 2.5) |
| | | min_num = int(5000 / (float(gpcode_manager.get_limit_up_price(code)))) |
| | | # 统计净涨停买的数量 |
| | | total_num = 0 |
| | | not_cancel_indexes = [] |
| | | re_start_index = start_index |
| | | for j in range(end_index, start_index, -1): |
| | | for j in range(start_index, end_index): |
| | | data = total_datas[j] |
| | | val = data['val'] |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | |
| | | if val["num"] < min_num: |
| | | continue |
| | | |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, |
| | | j, |
| | | total_datas, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if left_count > 0: |
| | | total_num += val['num'] |
| | | if total_num >= threshold_num: |
| | | re_start_index = j - 1 |
| | | not_cancel_indexes.append(j) |
| | | if not_cancel_indexes: |
| | | temp_count = len(not_cancel_indexes) |
| | | # 取后1/3的数据 |
| | | temp_index = int(temp_count * 2 / 3) |
| | | re_start_index = not_cancel_indexes[temp_index] |
| | | |
| | | MIN_MONEYS = [300, 200, 100, 50] |
| | | watch_indexes = set() |
| | |
| | | # 设置真实下单位置 |
| | | def set_real_place_order_index(self, code, index, buy_single_index=None): |
| | | self.__real_place_order_index_dict[code] = index |
| | | if buy_single_index: |
| | | self.compute_watch_index(code, buy_single_index, index) |
| | | if self.__last_trade_progress_dict.get(code): |
| | | self.compute_watch_index(code, self.__last_trade_progress_dict.get(code), index) |
| | | self.__compute_trade_progress_near_by_indexes(code, self.__last_trade_progress_dict.get(code) + 1, index) |
| | | else: |
| | | if buy_single_index: |
| | | self.compute_watch_index(code, buy_single_index, index) |
| | | self.__compute_trade_progress_near_by_indexes(code, buy_single_index, index) |
| | | self.__compute_trade_progress_near_by_indexes(code, buy_single_index, index) |
| | | |
| | | # 计算范围内的成交位临近未撤大单 |
| | | def __compute_trade_progress_near_by_indexes(self, code, start_index, end_index): |
| | |
| | | # 重新计算成交位置临近大单撤单 |
| | | self.__compute_trade_progress_near_by_indexes(code, index + 1, self.__real_place_order_index_dict.get(code)) |
| | | |
| | | try: |
| | | # 已经有计算的无法触发计算 |
| | | old_watch_indexes = self.__get_watch_indexes_cache(code) |
| | | if old_watch_indexes and self.__last_trade_progress_dict.get(code): |
| | | return |
| | | finally: |
| | | self.__last_trade_progress_dict[code] = index |
| | | |
| | | if self.__real_place_order_index_dict.get(code): |
| | | # 触发计算 |
| | | self.compute_watch_index(code, self.__last_trade_progress_dict.get(code), |
| | | self.__real_place_order_index_dict.get(code)) |
| | | # 成交进度与L下撤无关 |
| | | # try: |
| | | # # 已经有计算的无法触发计算 |
| | | # old_watch_indexes = self.__get_watch_indexes_cache(code) |
| | | # if old_watch_indexes and self.__last_trade_progress_dict.get(code): |
| | | # return |
| | | # finally: |
| | | # self.__last_trade_progress_dict[code] = index |
| | | # |
| | | # if self.__real_place_order_index_dict.get(code): |
| | | # # 触发计算 |
| | | # self.compute_watch_index(code, self.__last_trade_progress_dict.get(code), |
| | | # self.__real_place_order_index_dict.get(code)) |
| | | |
| | | def __compute_need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, is_first_code): |
| | | watch_indexes = self.__get_watch_indexes_cache(code) |
| | |
| | | watch_indexes = self.__get_near_by_trade_progress_indexes_cache(code) |
| | | if not watch_indexes: |
| | | return False, None |
| | | |
| | | # 计算监听的总条数 |
| | | total_count = 0 |
| | | for wi in watch_indexes: |
| | | total_count += total_data[wi]["re"] |
| | | # 权重 |
| | | WATCH_INDEX_WEIGHTS = [3, 2, 1] |
| | | total_count_weight = 0 |
| | | for wi in range(0, len(watch_indexes)): |
| | | if wi < len(WATCH_INDEX_WEIGHTS): |
| | | total_count_weight += WATCH_INDEX_WEIGHTS[wi] |
| | | else: |
| | | total_count_weight += WATCH_INDEX_WEIGHTS[-1] |
| | | # 判断撤单中是否有监听中的索引 |
| | | need_compute = False |
| | | for i in range(start_index, end_index + 1): |
| | |
| | | need_compute = True |
| | | break |
| | | if need_compute: |
| | | watch_indexes_list = list(watch_indexes) |
| | | watch_indexes_list.sort() |
| | | # 计算撤单比例 |
| | | canceled_count = 0 |
| | | canceled_count_weight = 0 |
| | | canceled_indexes = [] |
| | | for wi in watch_indexes: |
| | | canceled_data = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_canceled_data_v2(code, |
| | |
| | | code)) |
| | | if canceled_data: |
| | | canceled_indexes.append(canceled_data["index"]) |
| | | canceled_count += total_data[wi]["re"] |
| | | rate = round(canceled_count / total_count, 3) |
| | | canceled_count_weight += total_data[wi]["re"] |
| | | pos_index = watch_indexes_list.index(wi) |
| | | if pos_index < len(WATCH_INDEX_WEIGHTS): |
| | | canceled_count_weight += WATCH_INDEX_WEIGHTS[pos_index] |
| | | else: |
| | | canceled_count_weight += WATCH_INDEX_WEIGHTS[-1] |
| | | rate = round(canceled_count_weight / total_count_weight, 3) |
| | | thresh_cancel_rate = LCancelRateManager.get_cancel_rate(code, is_up=True) |
| | | l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},成交位临近已撤单比例:{rate}/{thresh_cancel_rate}") |
| | | if rate >= thresh_cancel_rate: |
| | |
| | | if real_place_order_index and trade_progress_index: |
| | | total_num = 0 |
| | | thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code) |
| | | thresh_hold_money = thresh_hold_money * 2 |
| | | thresh_hold_money = thresh_hold_money * 3 |
| | | # 阈值为2倍m值 |
| | | thresh_hold_num = thresh_hold_money // (float(gpcode_manager.get_limit_up_price(code)) * 100) |
| | | for i in range(trade_progress_index + 1, real_place_order_index): |
| | |
| | | def need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, is_first_code): |
| | | if buy_exec_index is None: |
| | | return False, "尚未找到下单位置", "" |
| | | time_space = tool.trade_time_sub(total_data[start_index]["val"]["time"], |
| | | total_data[buy_exec_index]["val"]["time"]) |
| | | # 守护S撤以外的数据 |
| | | if int(tool.get_now_time_str().replace(":", "")) > int("145700"): |
| | | if int(tool.get_now_time_str().replace(":", "")) > int("145700") and not constant.TEST: |
| | | return False, None, "" |
| | | # 下单位临近撤 |
| | | can_cancel, cancel_data = False, None |