L后修改/下过单的不再看身位/同一板块不限制挂单数量与买入数量/调整接口输出
5个文件已修改
107 ■■■■ 已修改文件
l2/cancel_buy_strategy.py 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/code_plate_key_manager.py 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/kpl_data_manager.py 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_server.py 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py
@@ -437,7 +437,7 @@
                    total_count, total_num = L2DataComputeUtil.compute_left_buy_order(code, trade_index,
                                                                                      real_order_index_info[0],
                                                                                      limit_up_price)
                    if total_num==0:
                    if total_num == 0:
                        total_num = 1
                    threshold_rate = constant.S_FAST_BIG_RATE
@@ -481,7 +481,7 @@
                        dealing_info[0]):
                        # 减去当前正在成交的数据中已经成交了的数据
                        total_num -= dealing_info[1] // 100
                        total_fast_num-=dealing_info[1] // 100
                        total_fast_num -= dealing_info[1] // 100
                    left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
                        code,
                        i,
@@ -491,7 +491,9 @@
                    if left_count > 0:
                        total_num += val["num"]
                        total_fast_num += val['num']
                if total_num * float(limit_up_price) < 800 * 100 and tool.trade_time_sub(sell_time_str, total_datas[real_order_index]['val']['time']) < 15 * 60:
                if total_num * float(limit_up_price) < 800 * 100 and tool.trade_time_sub(sell_time_str,
                                                                                         total_datas[real_order_index][
                                                                                             'val']['time']) < 15 * 60:
                    # 15分钟内真实成交位距离真实下单位,金额≤800万 ,大单阈值变为200w
                    threash_money_w = threash_money_danger_w
        except Exception as e:
@@ -1102,6 +1104,8 @@
    __last_trade_progress_dict = {}
    __real_place_order_index_dict = {}
    __cancel_watch_index_info_cache = {}
    # L后真实成交位之后的位置索引
    __cancel_l_down_after_place_order_index_cache = {}
    # 成交位附近临近大单索引
    __near_by_trade_progress_index_cache = {}
@@ -1152,6 +1156,17 @@
                    CodeDataCacheUtil.set_cache(cls.__near_by_trade_progress_index_cache, code, val)
                except:
                    pass
            keys = RedisUtils.keys(__redis, "l_cancel_down_after_place_order_index-*")
            for k in keys:
                code = k.split("-")[-1]
                val = RedisUtils.get(__redis, k)
                try:
                    val = json.loads(val)
                    CodeDataCacheUtil.set_cache(cls.__cancel_l_down_after_place_order_index_cache, code, val)
                except:
                    pass
        finally:
            RedisUtils.realse(__redis)
@@ -1200,6 +1215,16 @@
            return cache_result[1]
        return None
    def __set_cancel_l_down_after_place_order_index(self, code, watch_index, index):
        if code not in self.__cancel_l_down_after_place_order_index_cache:
            self.__cancel_l_down_after_place_order_index_cache[code] = {}
        self.__cancel_l_down_after_place_order_index_cache[code][str(watch_index)] = index
        RedisUtils.setex_async(self.__db, f"l_cancel_down_after_place_order_index-{code}", tool.get_expire(),
                               json.dumps(self.__cancel_l_down_after_place_order_index_cache[code]))
    def __get_cancel_l_down_after_place_order_index_dict(self, code):
        return self.__cancel_l_down_after_place_order_index_cache.get(code)
    def del_watch_index(self, code):
        CodeDataCacheUtil.clear_cache(self.__cancel_watch_index_info_cache, code)
        RedisUtils.delete_async(self.__db, f"l_cancel_watch_index_info-{code}")
@@ -1210,6 +1235,9 @@
            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}")
            if code in self.__cancel_l_down_after_place_order_index_cache:
                self.__cancel_l_down_after_place_order_index_cache.pop(code)
                RedisUtils.delete_async(self.__db, f"l_cancel_down_after_place_order_index-{code}")
        else:
            keys = RedisUtils.keys(self.__get_redis(), f"l_cancel_watch_index_info-*")
            for k in keys:
@@ -1220,6 +1248,11 @@
                    self.__real_place_order_index_dict.pop(code)
                self.del_watch_index(code)
            keys = RedisUtils.keys(self.__get_redis(), f"l_cancel_real_place_order_index-*")
            for k in keys:
                RedisUtils.delete(self.__get_redis(), k)
            # 清除L后真实下单位置之后囊括的索引
            self.__cancel_l_down_after_place_order_index_cache.clear()
            keys = RedisUtils.keys(self.__get_redis(), f"l_cancel_down_after_place_order_index-*")
            for k in keys:
                RedisUtils.delete(self.__get_redis(), k)
@@ -1403,6 +1436,7 @@
                                    after_count += 1
                                    if l2_data_util.is_big_money(val):
                                        watch_indexes.add(i)
                                        self.__set_cancel_l_down_after_place_order_index(code, i, after_count - 1)
                    except Exception as e:
                        pass
                    self.__set_watch_indexes(code, buy_single_index, re_compute, watch_indexes)
@@ -1614,6 +1648,7 @@
                        left_count_after += 1
                        if l2_data_util.is_big_money(val) and j not in watch_indexes:
                            watch_indexes.add(j)
                            self.__set_cancel_l_down_after_place_order_index(code, j, left_count_after - 1)
                            break
            except:
                pass
@@ -1621,6 +1656,17 @@
        self.__set_watch_indexes(code, watch_indexes_info[0], watch_indexes_info[1], watch_indexes)
    def __compute_need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, is_first_code):
        """
        L后撤单;
        撤单计算规则:计算撤单比例时,将真实下单位置之后的数据按权重(离下单位最近的权重越大)加入分子,不加入分母(总囊括手数)计算
        @param code:
        @param buy_exec_index:
        @param start_index:
        @param end_index:
        @param total_data:
        @param is_first_code:
        @return:
        """
        watch_indexes_info = self.__get_watch_indexes_cache(code)
        if not watch_indexes_info:
            return False, None
@@ -1628,7 +1674,13 @@
        # 计算监听的总条数
        total_num = 0
        max_num = 0
        # 这是下单位置之后的索引: 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:
                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"]
@@ -1646,6 +1698,7 @@
                    need_compute = True
                    break
        if need_compute:
            # 计算撤单比例
            watch_indexes_list = list(watch_indexes)
            watch_indexes_list.sort()
@@ -1659,7 +1712,13 @@
                                                                                                      local_today_canceled_buyno_map.get(
                                                                                                          code))
                if cancel_data:
                    canceled_num += total_data[wi]["val"]["num"] * total_data[wi]["re"]
                    if str(wi) in after_place_order_index_dict:
                        # 真实下单位置之后的按照权重比例来计算
                        canceled_num += total_data[wi]["val"]["num"] * (
                                    10 - after_place_order_index_dict[str(wi)]) // 10
                    else:
                        canceled_num += total_data[wi]["val"]["num"]
                    canceled_indexes.append(cancel_data["index"])
                # if wi == watch_indexes_list[-1] and left_count == 0:
                #     # 离下单位置最近的一个撤单,必须触发撤单
@@ -1673,7 +1732,8 @@
            if not must_buy:
                temp_thresh_hold_rate = round((total_num - max_num) * 0.9 / total_num, 2)
                thresh_hold_rate = min(thresh_hold_rate, temp_thresh_hold_rate)
            l2_log.l_cancel_debug(code, f"L后计算范围:{start_index}-{end_index},已撤单比例:{rate}/{thresh_hold_rate}")
            l2_log.l_cancel_debug(code,
                                  f"L后计算范围:{start_index}-{end_index},已撤单比例:{rate}/{thresh_hold_rate}, 下单位之后的索引:{after_place_order_index_dict}")
            if rate >= thresh_hold_rate:
                canceled_indexes.sort()
                l2_log.l_cancel_debug(code, f"L后撤单,撤单位置:{canceled_indexes[-1]}")
@@ -1841,6 +1901,16 @@
    def cancel_success(self, code):
        self.clear(code)
    def test(self):
        code = "000333"
        self.__set_cancel_l_down_after_place_order_index(code, 121, 0)
        time.sleep(6)
        self.__set_cancel_l_down_after_place_order_index(code, 121, 0),
        time.sleep(6)
        self.__set_cancel_l_down_after_place_order_index(code, 122, 1)
        print(self.__get_cancel_l_down_after_place_order_index_dict(code))
# 新F撤,根据成交数据来撤
@@ -2091,7 +2161,7 @@
        if real_order_index_info[1]:
            return False, "真实下单位为默认"
        place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code)
        if place_order_count>1:
        if place_order_count > 1:
            return False, "不是初次下单"
        trade_index, is_default = TradeBuyQueue().get_traded_index(code)
l2/l2_data_manager_new.py
@@ -1320,7 +1320,11 @@
                return True, False, can_buy_result[2]
        else:
            if not can_buy_result[0]:
                return False, True, f"非强势30分钟,不满足身位:{can_buy_result[2]}"
                place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code)
                if place_order_count <=0:
                    return False, True, f"非强势30分钟,不满足身位:{can_buy_result[2]}"
                else:
                    return True, False, "之前下过单"
            return True, False, can_buy_result[2]
    @classmethod
third_data/code_plate_key_manager.py
@@ -891,12 +891,12 @@
                # 强势主线最多同时挂3只票,最多成交2只票
                MAX_DELEGATE_COUNT = 3 if r[4] else 2
                MAX_DEAL_COUNT = 2 if r[4] else 1
                if r[0] in trade_success_blocks_count and len(trade_success_blocks_count[r[0]]) >= MAX_DEAL_COUNT:
                    msg_list.append(f"【{r[0]}】有成交代码:{trade_success_blocks_count[r[0]]}")
                    continue
                if r[0] in trade_delegate_blocks_count and len(trade_delegate_blocks_count[r[0]]) >= MAX_DELEGATE_COUNT:
                    msg_list.append(f"【{r[0]}】已挂单:{trade_delegate_blocks_count[r[0]]}")
                    continue
                # if r[0] in trade_success_blocks_count and len(trade_success_blocks_count[r[0]]) >= MAX_DEAL_COUNT:
                #     msg_list.append(f"【{r[0]}】有成交代码:{trade_success_blocks_count[r[0]]}")
                #     continue
                # if r[0] in trade_delegate_blocks_count and len(trade_delegate_blocks_count[r[0]]) >= MAX_DELEGATE_COUNT:
                #     msg_list.append(f"【{r[0]}】已挂单:{trade_delegate_blocks_count[r[0]]}")
                #     continue
                if len(r)>6:
                    can_buy_blocks.append(f"{r[0]}-{r[6]}")
                else:
third_data/kpl_data_manager.py
@@ -54,6 +54,7 @@
    # 当前涨停原因的代码集合
    __current_limit_up_reason_codes_dict = {}
    __records_cache = {}
    record_code_dict = {}
    @classmethod
    def __load_hist_and_blocks(cls, code):
@@ -88,6 +89,7 @@
        # 统计代码所属板块
        code_block_dict = {}
        for data in records:
            cls.record_code_dict[data[0]] = data
            blocks = set(data[5].split("、"))
            code = data[0]
            for b in blocks:
trade/huaxin/huaxin_trade_server.py
@@ -1586,7 +1586,12 @@
                                    fdata['block'] = ",".join(can_buy_result[0])
                            except:
                                pass
                            # 获取涨停时间
                            limit_up_data = kpl_data_manager.KPLLimitUpDataRecordManager.record_code_dict.get(code)
                            if limit_up_data:
                                fdata['limit_up_time'] = limit_up_data[2]
                                # 获取委托队列
                            try:
                                real_place_order_index = SCancelBigNumComputer().get_real_place_order_index_cache(code)
                                if real_place_order_index is not None: