| | |
| | | |
| | | __SecondCancelBigNumComputer = SecondCancelBigNumComputer() |
| | | |
| | | # L后囊括范围未撤单/未成交的总手数 |
| | | __total_l_down_not_deal_num_dict = {} |
| | | # L后最近的成交数信息 |
| | | __l_down_latest_deal_info_dict = {} |
| | | |
| | | __last_l_up_compute_info = {} |
| | | |
| | | __instance = None |
| | |
| | | self.__set_near_by_trade_progress_indexes(code, buy_single_index, watch_indexes) |
| | | self.__last_l_up_compute_info[code] = (time.time(), watch_indexes) |
| | | |
| | | # 计算L后还没成交的手数 |
| | | def __compute_total_l_down_not_deal_num(self, code): |
| | | try: |
| | | if code in self.__total_l_down_not_deal_num_dict and time.time() - self.__total_l_down_not_deal_num_dict[code][ |
| | | 1] < 1: |
| | | # 需要间隔1s更新一次 |
| | | return |
| | | l_down_cancel_info = self.__cancel_watch_index_info_cache.get(code) |
| | | if not l_down_cancel_info: |
| | | return |
| | | |
| | | trade_progress = self.__last_trade_progress_dict.get(code) |
| | | if trade_progress is None: |
| | | return |
| | | |
| | | l_down_indexes = l_down_cancel_info[2] |
| | | # 统计还未成交的数据 |
| | | total_left_num = 0 |
| | | total_datas = local_today_datas.get(code) |
| | | for i in l_down_indexes: |
| | | # 已经成交了的不计算 |
| | | if i <= trade_progress: |
| | | continue |
| | | data = total_datas[i] |
| | | val = data['val'] |
| | | 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_left_num += val["num"] |
| | | limit_up_price = float(gpcode_manager.get_limit_up_price(code)) |
| | | total_money = limit_up_price * total_left_num |
| | | # 如果200<=金额<=1000w才会生效,否则就设为-1 |
| | | if 20000 <= total_money <= 100000: |
| | | pass |
| | | else: |
| | | total_left_num = -1 |
| | | self.__total_l_down_not_deal_num_dict[code] = (total_left_num, time.time()) |
| | | except Exception as e: |
| | | async_log_util.exception(logger_l2_l_cancel, e) |
| | | |
| | | # 设置成交位置,成交位置变化之后相应的监听数据也会发生变化 |
| | | def set_trade_progress(self, code, buy_single_index, index, total_datas): |
| | | if self.__last_trade_progress_dict.get(code) == index: |
| | | self.__compute_total_l_down_not_deal_num(code) |
| | | return |
| | | self.__last_trade_progress_dict[code] = index |
| | | self.__compute_total_l_down_not_deal_num(code) |
| | | |
| | | if not self.__is_l_down_can_cancel(code, buy_single_index): |
| | | # L后已经不能守护 |
| | |
| | | # self.compute_watch_index(code, self.__last_trade_progress_dict.get(code), |
| | | # self.__real_place_order_index_dict.get(code)) |
| | | |
| | | def add_transaction_data(self, transaction_data): |
| | | if not transaction_data: |
| | | return False, "成交数据为空" |
| | | code = transaction_data[0] |
| | | buyno_map = local_today_buyno_map.get(code) |
| | | if not buyno_map: |
| | | return False, "没找到买单字典" |
| | | buy_data = buyno_map.get(str(transaction_data[6])) |
| | | if not buy_data: |
| | | return False, f"没有找到对应买单({transaction_data[6]})" |
| | | total_datas = local_today_datas.get(code) |
| | | if not total_datas: |
| | | return False, "L2数据为空" |
| | | l_down_cancel_info = self.__cancel_watch_index_info_cache.get(code) |
| | | if not l_down_cancel_info: |
| | | return False, "L撤为空" |
| | | l_down_indexes = l_down_cancel_info[2] |
| | | if buy_data["index"] not in l_down_indexes: |
| | | return False, "非L撤监听数据成交" |
| | | # 统计数据 |
| | | orgin_deal_data = self.__l_down_latest_deal_info_dict.get(code) |
| | | if not orgin_deal_data: |
| | | orgin_deal_data = [0, None] |
| | | time_str = l2_huaxin_util.convert_time(transaction_data[3]) |
| | | if orgin_deal_data[1] != time_str: |
| | | orgin_deal_data[0] = transaction_data[2] |
| | | orgin_deal_data[1] = time_str |
| | | else: |
| | | orgin_deal_data[0] += transaction_data[2] |
| | | self.__l_down_latest_deal_info_dict[code] = orgin_deal_data |
| | | |
| | | # 计算成交比例 |
| | | total_l_down_not_deal_num = self.__total_l_down_not_deal_num_dict.get(code) |
| | | if total_l_down_not_deal_num is None: |
| | | return False, "L后撤数据为空" |
| | | threshold_rate = 0.5 |
| | | rate = orgin_deal_data[0] / (total_l_down_not_deal_num[0] * 100) |
| | | if rate > threshold_rate: |
| | | return True, f"达到撤单比例:{rate}/{threshold_rate}" |
| | | else: |
| | | return False, "尚未达到撤单比例" |
| | | |
| | | # 已经成交的索引 |
| | | def add_deal_index(self, code, index, buy_single_index): |
| | | watch_indexes_info = self.__get_watch_indexes_cache(code) |