| | |
| | | |
| | | __l_down_after_by_big_order_dict = {} |
| | | |
| | | # 权重 |
| | | __l_down_after_by_big_order_weight_dict = {} |
| | | __instance = None |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | |
| | | self.del_watch_index(code) |
| | | if code in self.__l_down_after_by_big_order_dict: |
| | | self.__l_down_after_by_big_order_dict.pop(code) |
| | | if code in self.__l_down_after_by_big_order_weight_dict: |
| | | self.__l_down_after_by_big_order_weight_dict.pop(code) |
| | | if code in self.__real_place_order_index_dict: |
| | | self.__real_place_order_index_dict.pop(code) |
| | | RedisUtils.delete_async(self.__db, f"l_cancel_real_place_order_index-{code}") |
| | |
| | | for k in keys: |
| | | RedisUtils.delete(self.__get_redis(), k) |
| | | self.__l_down_after_by_big_order_dict.clear() |
| | | self.__l_down_after_by_big_order_weight_dict.clear() |
| | | |
| | | # 重新计算L上 |
| | | |
| | |
| | | limit_up_price = round(float(limit_up_price), 2) |
| | | bigger_num = l2_data_util.get_big_money_val(limit_up_price, tool.is_ge_code(code)) // (limit_up_price * 100) |
| | | min_num = 500000 // (limit_up_price * 100) |
| | | count = -1 |
| | | index = -1 |
| | | watch_indexes = set() |
| | | if code not in self.__l_down_after_by_big_order_weight_dict: |
| | | self.__l_down_after_by_big_order_weight_dict[code] = {} |
| | | for i in range(real_place_order_index + 1, total_datas[-1]["index"]): |
| | | data = total_datas[i] |
| | | val = data["val"] |
| | |
| | | code)) |
| | | if left_count > 0: |
| | | if val["num"] >= bigger_num: |
| | | if count < 0: |
| | | if index < 0: |
| | | # 开始计数 |
| | | count = 0 |
| | | index = 0 |
| | | # 加入大单监听 |
| | | self.__l_down_after_by_big_order_weight_dict[code][str(i)] = int(str(index)) |
| | | watch_indexes.add(i) |
| | | if count >= 0: |
| | | count += 1 |
| | | if count > 10: |
| | | if index >= 0: |
| | | index += 1 |
| | | if index > 10: |
| | | break |
| | | self.__l_down_after_by_big_order_dict[code] = watch_indexes |
| | | l2_log.l_cancel_debug(code, f"L后后半段大单备用囊括范围:{watch_indexes}") |
| | |
| | | watch_indexes_info = self.__get_watch_indexes_cache(code) |
| | | if not watch_indexes_info: |
| | | return False, None |
| | | |
| | | # 这是下单位置之后的索引: key为字符串 |
| | | after_place_order_index_dict = self.__get_cancel_l_down_after_place_order_index_dict(code) |
| | | if after_place_order_index_dict is None: |
| | | after_place_order_index_dict = {} |
| | | after_place_order_index_by_dict = self.__l_down_after_by_big_order_weight_dict.get(code) |
| | | if after_place_order_index_by_dict is None: |
| | | after_place_order_index_by_dict = {} |
| | | |
| | | |
| | | watch_indexes = set([int(i) for i in watch_indexes_info[2]]) |
| | | try: |
| | | # 将备用订单加进去 |
| | |
| | | if watch_indexes_by: |
| | | # 是否是下单30分钟内 |
| | | real_place_order_info = self.__real_place_order_index_dict.get(code) |
| | | if real_place_order_info and tool.trade_time_sub(total_data[-1]["val"]["time"] , total_data[real_place_order_info[0]]["val"]["time"]) < 30*60: |
| | | if real_place_order_info and tool.trade_time_sub(total_data[-1]["val"]["time"], |
| | | total_data[real_place_order_info[0]]["val"][ |
| | | "time"]) < 30 * 60: |
| | | # 下单30分钟内有效 |
| | | watch_indexes|=watch_indexes_by |
| | | watch_indexes |= watch_indexes_by |
| | | else: |
| | | # 清除备用大单 |
| | | watch_indexes_by.clear() |
| | | except Exception as e: |
| | | l2_log.l_cancel_debug(code,"将L2后后半段备用大单加入计算出错:{}", str(e)) |
| | | l2_log.l_cancel_debug(code, "将L2后后半段备用大单加入计算出错:{}", str(e)) |
| | | # 计算监听的总条数 |
| | | total_num = 0 |
| | | max_num = 0 |
| | | thresh_hold_rate, must_buy = LCancelRateManager.get_cancel_rate(code, |
| | | total_data[buy_exec_index]["val"]["time"]) |
| | | # 这是下单位置之后的索引: key为字符串 |
| | | after_place_order_index_dict = self.__get_cancel_l_down_after_place_order_index_dict(code) |
| | | if after_place_order_index_dict is None: |
| | | after_place_order_index_dict = {} |
| | | |
| | | for wi in watch_indexes: |
| | | if str(wi) in after_place_order_index_dict: |
| | | # 如果加红就需要计算分母 |
| | |
| | | total_num += total_data[wi]["val"]["num"] * ( |
| | | 10 - after_place_order_index_dict[str(wi)]) // 10 |
| | | continue |
| | | elif str(wi) in after_place_order_index_by_dict: |
| | | if must_buy: |
| | | total_num += total_data[wi]["val"]["num"] * ( |
| | | 10 - after_place_order_index_by_dict[str(wi)]) // 10 |
| | | continue |
| | | |
| | | |
| | | total_num += total_data[wi]["val"]["num"] * total_data[wi]["re"] |
| | | if total_data[wi]["val"]["num"] > max_num: |
| | | max_num = total_data[wi]["val"]["num"] |
| | |
| | | # 真实下单位置之后的按照权重比例来计算 |
| | | canceled_num += total_data[wi]["val"]["num"] * ( |
| | | 10 - after_place_order_index_dict[str(wi)]) // 10 |
| | | elif str(wi) in after_place_order_index_by_dict: |
| | | canceled_num += total_data[wi]["val"]["num"] * ( |
| | | 10 - after_place_order_index_by_dict[str(wi)]) // 10 |
| | | else: |
| | | canceled_num += total_data[wi]["val"]["num"] |
| | | |