| | |
| | | # 保存成交位置到执行位置的揽括范围数据 |
| | | def __save_watch_index_set(self, code, indexes): |
| | | trade_record_log_util.add_cancel_watch_indexes_log(code, |
| | | CancelWatchIndexesInfo(CancelWatchIndexesInfo.CANCEL_TYPE_H, |
| | | list(indexes))) |
| | | 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}" |
| | | RedisUtils.setex_async(self.__db, key, tool.get_expire(), |
| | |
| | | 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: |
| | |
| | | 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}") |
| | |
| | | # 下单位临近撤 |
| | | 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) |
| | |
| | | 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 |
| | |
| | | # 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, |
| | | 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, |
| | | code_limit_up_reason_dict, |
| | | yesterday_current_limit_up_codes, shsz=True) |
| | | 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, 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) |
| | | # 获取主板历史身位 |
| | | |
| | | open_limit_up_codes = kpl_block_util.get_shsz_open_limit_up_codes(code, block, limit_up_record_datas, |
| | |
| | | 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)})" |
| | |
| | | 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: 今日实时涨停 |
| | |
| | | |
| | | # 获取当日历史身位 |
| | | # 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: |
| | |
| | | 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: |
| | |
| | | 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__": |