Administrator
2023-10-11 826084fc7c11c5e2776b73342e6c1ed2f1a99b02
bug修改/添加代码身位之前的代码日志
4个文件已修改
56 ■■■■■ 已修改文件
l2/cancel_buy_strategy.py 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/huaxin/huaxin_delegate_postion_manager.py 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/code_plate_key_manager.py 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/kpl_block_util.py 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py
@@ -408,7 +408,8 @@
    # 保存成交位置到执行位置的揽括范围数据
    def __save_watch_index_set(self, code, indexes):
        trade_record_log_util.add_cancel_watch_indexes_log(code,
                                                           CancelWatchIndexesInfo(CancelWatchIndexesInfo.CANCEL_TYPE_H,
                                                           trade_record_log_util.CancelWatchIndexesInfo(
                                                               trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_H,
                                                                                  list(indexes)))
        CodeDataCacheUtil.set_cache(self.__cancel_watch_indexs_cache, code, indexes)
        key = f"h_cancel_watch_indexs-{code}"
@@ -752,9 +753,7 @@
    def __add_watch_indexes(self, code, indexes):
        if not indexes:
            return
        trade_record_log_util.add_cancel_watch_indexes_log(code,
                                                           trade_record_log_util.CancelWatchIndexesInfo(trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_DOWN,
                                                                                  list(indexes)))
        if code not in self.__cancel_watch_index_cache:
            self.__cancel_watch_index_cache[code] = set()
        for index in indexes:
@@ -775,6 +774,11 @@
        RedisUtils.delete_async(self.__db, f"l_cancel_watch_index-{code}")
        for index in indexes:
            RedisUtils.srem_async(self.__db, f"l_cancel_watch_index-{code}", index)
        if indexes:
            trade_record_log_util.add_cancel_watch_indexes_log(code,
                                                               trade_record_log_util.CancelWatchIndexesInfo(
                                                                   trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_DOWN,
                                                                   list(indexes)))
    def __get_watch_indexes(self, code):
        return RedisUtils.smembers(self.__get_redis(), f"l_cancel_watch_index-{code}")
@@ -1036,7 +1040,8 @@
        # 下单位临近撤
        can_cancel, cancel_data = False, None
        try:
            can_cancel, cancel_data = self.__compute_need_cancel(code, buy_exec_index, start_index, end_index, total_data,
            can_cancel, cancel_data = self.__compute_need_cancel(code, buy_exec_index, start_index, end_index,
                                                                 total_data,
                                                                 is_first_code)
        except Exception as e:
            logger_l2_l_cancel.exception(e)
l2/huaxin/huaxin_delegate_postion_manager.py
@@ -48,6 +48,11 @@
            continue
        if abs(float(price) - float(d["val"]["price"])) >= 0.01:
            continue
        # 必须是买入
        if not L2DataUtil.is_limit_up_price_buy(d["val"]):
            continue
        # 不可能比下单执行位置还早
        if d["index"] <= exec_data["index"]:
            continue
third_data/code_plate_key_manager.py
@@ -451,12 +451,16 @@
        # msg_list.append(f"历史top20(涨停数量:{len(top_8_record)})")
        # 获取主板实时身位,剔除高位板
        current_shsz_rank = kpl_block_util.get_code_current_rank(code, block, current_limit_up_datas,
        current_shsz_rank, front_current_shsz_rank_codes = kpl_block_util.get_code_current_rank(code, block,
                                                                                                current_limit_up_datas,
                                                                 code_limit_up_reason_dict,
                                                                 yesterday_current_limit_up_codes, shsz=True)
        record_shsz_rank = kpl_block_util.get_code_record_rank(code, block, limit_up_record_datas,
                                                                                                yesterday_current_limit_up_codes,
                                                                                                shsz=True)
        record_shsz_rank, record_shsz_rank_codes = kpl_block_util.get_code_record_rank(code, block,
                                                                                       limit_up_record_datas,
                                                               code_limit_up_reason_dict,
                                                               yesterday_current_limit_up_codes, shsz=True)
                                                                                       yesterday_current_limit_up_codes,
                                                                                       shsz=True)
        # 获取主板历史身位
        open_limit_up_codes = kpl_block_util.get_shsz_open_limit_up_codes(code, block, limit_up_record_datas,
@@ -469,7 +473,7 @@
            else:
                if record_shsz_rank >= len(open_limit_up_codes) + 1:
                    cls.__remove_from_l2(code, f"{code}根据身位禁止买入:【{block}】历史身位{record_shsz_rank}")
                return False, f"板块-{block}: top4涨停板块,主板开1({open_limit_up_codes}),不为主板前龙{len(open_limit_up_codes) + 1}(实时身位-{current_shsz_rank},历史身位-{record_shsz_rank})"
                return False, f"板块-{block}: top4涨停板块,主板开1({open_limit_up_codes}),不为主板前龙{len(open_limit_up_codes) + 1}(实时身位-{current_shsz_rank}:{front_current_shsz_rank_codes},历史身位-{record_shsz_rank})"
        else:
            if current_shsz_rank == 0 and record_shsz_rank < 2:
                return True, f"{tool.get_now_time_str()} {block}:top4涨停板块,非主板开1,属于龙1,实时涨停列表数量({len(current_limit_up_datas)})"
@@ -477,7 +481,7 @@
                if record_shsz_rank >= 2:
                    cls.__remove_from_l2(code, f"{code}根据身位禁止买入:【{block}】历史身位{record_shsz_rank}")
                return False, f"板块-{block}: top4涨停板块,非主板开1,不为主板龙1(实时身位-{current_shsz_rank},历史身位-{record_shsz_rank})"
                return False, f"板块-{block}: top4涨停板块,非主板开1,不为主板龙1(实时身位-{current_shsz_rank}:{front_current_shsz_rank_codes},历史身位-{record_shsz_rank})"
    # 获取可以买的板块
    # current_limit_up_datas: 今日实时涨停
third_data/kpl_block_util.py
@@ -124,7 +124,8 @@
# 获取当日历史身位
# shsz:是否主板
def get_code_record_rank(code, block, limit_up_record_datas, code_limit_up_reason_dict, yesterday_current_limit_up_codes, shsz=True):
def get_code_record_rank(code, block, limit_up_record_datas, code_limit_up_reason_dict,
                         yesterday_current_limit_up_codes, shsz=True):
    block_codes_infos = []
    limit_up_time = time.time()
    for k in limit_up_record_datas:
@@ -140,15 +141,19 @@
                limit_up_time = int(k[5])
    block_codes_infos.append((code, limit_up_time))
    block_codes_infos.sort(key=lambda x: x[1])
    front_codes = []
    for i in range(0, len(block_codes_infos)):
        if block_codes_infos[i][0] == code:
            return i
    return 0
            return i, front_codes
        else:
            front_codes.append(block_codes_infos[i][0])
    return 0,[]
# 获取当日实时身位
# before_blocks_dict格式位{"代码":set("板块")}
def get_code_current_rank(code, block, current_limit_up_datas, code_limit_up_reason_dict, yesterday_current_limit_up_codes, shsz=False):
def get_code_current_rank(code, block, current_limit_up_datas, code_limit_up_reason_dict,
                          yesterday_current_limit_up_codes, shsz=False):
    block_codes_infos = []
    limit_up_time = time.time()
    for k in current_limit_up_datas:
@@ -165,10 +170,13 @@
                limit_up_time = int(k[2])
    block_codes_infos.append((code, limit_up_time))
    block_codes_infos.sort(key=lambda x: x[1])
    front_codes = []
    for i in range(0, len(block_codes_infos)):
        if block_codes_infos[i][0] == code:
            return i
    return 0
            return i, front_codes
        else:
            front_codes.append(block_codes_infos[i][0])
    return 0,[]
if __name__ == "__main__":