| | |
| | | |
| | | if code_nature_analyse.is_up_too_high_in_10d_with_limit_up(volumes_data): |
| | | # 判断是否太高 |
| | | l2_trade_util.forbidden_trade(code, "股价长得太高(5天内有3个涨停)") |
| | | # l2_trade_util.forbidden_trade(code, "股价长得太高(5天内有3个涨停)") |
| | | HighIncreaseCodeManager().add_code(code) |
| | | |
| | | if code_nature_analyse.is_up_too_high_in_120d(volumes_data): |
| | |
| | | return False, True, f"均价涨幅({average_rate})小于1%" |
| | | |
| | | # -------量的约束-------- |
| | | if float(limit_up_price) < 3.0 and cls.volume_rate_info[code][0] < 0.6: |
| | | return False, True, f"涨停价小于3块,当日量比({cls.volume_rate_info[code][0]})小于0.6" |
| | | |
| | | if HighIncreaseCodeManager().is_in(code) and cls.volume_rate_info[code][0] < 0.6: |
| | | return False, True, f"股价涨得过高,当日量比({cls.volume_rate_info[code][0]})小于0.6" |
| | | |
| | | if cls.volume_rate_info[code][0] < 0.2: |
| | | return False, True, f"当日量比({cls.volume_rate_info[code][0]})小于0.2" |
| | | k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) |
| | |
| | | if code_nature_analyse.LatestMaxVolumeManager().is_latest_max_volume(code): |
| | | # 最近几天有最大量,判断量比是否大于60% |
| | | if cls.volume_rate_info[code][0] < 0.6: |
| | | HighIncreaseCodeManager().add_code(code) |
| | | # HighIncreaseCodeManager().add_code(code) |
| | | return False, True, f"近日出现最大量,当日量比({cls.volume_rate_info[code][0]})小于0.6" |
| | | |
| | | # ------自由流通市值约束------ |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | if zyltgb: |
| | | if zyltgb < 10 * 100000000: |
| | | return False, True, f"自由流通小于10亿({zyltgb})" |
| | | |
| | | total_data = local_today_datas.get(code) |
| | | if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_HUAXIN: |
| | |
| | | return False, True, "尚未获取到板块信息" |
| | | |
| | | if can_buy_result[1]: |
| | | # ------自由流通市值约束------ |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | if zyltgb: |
| | | if zyltgb < 10 * 100000000: |
| | | return False, True, f"独苗,自由流通小于10亿({zyltgb})" |
| | | if code in cls.volume_rate_info and cls.volume_rate_info[code][0] < 0.6: |
| | | return False, True, f"独苗:量比({cls.volume_rate_info[code][0]})未达到60%" |
| | | |
| | |
| | | |
| | | # @unittest.skip("跳过此单元测试") |
| | | def test_block(self): |
| | | code = "002962" |
| | | KPLCodeJXBlockManager().load_jx_blocks(code, 14.99, 14.99) |
| | | KPLCodeJXBlockManager().load_jx_blocks(code, 14.99, 14.99) |
| | | code = "002036" |
| | | KPLCodeJXBlockManager().load_jx_blocks(code, 11.83, 11.83, kpl_data_manager.KPLLimitUpDataRecordManager.get_current_reasons()) |
| | | |
| | | block_info.init_code(code) |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.load_total_datas() |
| | | yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.save_record(tool.get_now_date_str(), |
| | | kpl_data_manager.KPLDataManager.get_data( |
| | | kpl_util.KPLDataType.LIMIT_UP)) |
| | | KPLCodeJXBlockManager().load_jx_blocks(code, 11.83, 11.83, |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.get_current_reasons()) |
| | | |
| | | CodePlateKeyBuyManager.update_can_buy_blocks(code, |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.latest_origin_datas, |
| | |
| | | def __get_redis(self): |
| | | return self.__redisManager.getRedis() |
| | | |
| | | def save_jx_blocks(self, code, blocks: list, by=False): |
| | | def save_jx_blocks(self, code, blocks: list, current_limit_up_blocks: set, by=False): |
| | | if not blocks: |
| | | return |
| | | final_blocks = copy.deepcopy(blocks) |
| | |
| | | blocks.sort(key=lambda x: x[2]) |
| | | blocks.reverse() |
| | | for b in blocks: |
| | | if b[2] > 0 and b[1] not in constant.KPL_INVALID_BLOCKS: |
| | | if (b[2] > -1 or b[1] in current_limit_up_blocks) and b[1] not in constant.KPL_INVALID_BLOCKS: |
| | | final_blocks.append(b) |
| | | if len(final_blocks) < 2: |
| | | final_blocks = blocks |
| | | |
| | | # 保存前2条数据 |
| | | if by: |
| | | RedisUtils.setex_async(self.__db, f"kpl_jx_blocks_by-{code}", tool.get_expire(), json.dumps(final_blocks)) |
| | |
| | | else: |
| | | return self.__code_blocks.get(code) |
| | | |
| | | # 从网络上加载精选板块 |
| | | def load_jx_blocks(self, code, buy_1_price, limit_up_price): |
| | | # 从网络上加载精选板块, 当前涨停的板块 |
| | | def load_jx_blocks(self, code, buy_1_price, limit_up_price, current_limit_up_blocks): |
| | | try: |
| | | # logger_kpl_block_can_buy.info(f"准备更新精选板块:{code}-{buy_1_price}-{limit_up_price}") |
| | | if limit_up_price and buy_1_price: |
| | |
| | | jx_blocks_info = self.get_jx_blocks_cache(code) |
| | | if not jx_blocks_info: |
| | | blocks = kpl_api.getCodeJingXuanBlocks(code) |
| | | self.save_jx_blocks(code, blocks) |
| | | self.save_jx_blocks(code, blocks, current_limit_up_blocks) |
| | | async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块-{blocks}") |
| | | else: |
| | | # 还没涨停的需要更新精选板块 更新精选板块 |
| | |
| | | if time.time() - jx_blocks_info[1] > UPDATE_TIME_SPACE: |
| | | # 距离上次更新时间过去了5分钟 |
| | | blocks = kpl_api.getCodeJingXuanBlocks(code) |
| | | self.save_jx_blocks(code, blocks) |
| | | self.save_jx_blocks(code, blocks, current_limit_up_blocks) |
| | | async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块(更新)-{blocks}") |
| | | |
| | | elif price_rate > 0.03: |
| | | # 添加备用板块 |
| | | if not self.get_jx_blocks_cache(code, by=True): |
| | | blocks = kpl_api.getCodeJingXuanBlocks(code) |
| | | self.save_jx_blocks(code, blocks, by=True) |
| | | self.save_jx_blocks(code, blocks,current_limit_up_blocks, by=True) |
| | | async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块(备用)-{blocks}") |
| | | except Exception as e: |
| | | logger_kpl_block_can_buy.error(f"{code} 获取板块出错") |
| | |
| | | def get_current_reason_codes_dict(cls): |
| | | return copy.deepcopy(cls.__current_reason_codes_dict) |
| | | |
| | | @classmethod |
| | | def get_current_reasons(cls): |
| | | if cls.__current_reason_codes_dict: |
| | | return cls.__current_reason_codes_dict.keys() |
| | | return set() |
| | | |
| | | |
| | | class KPLDataManager: |
| | | __latest_datas = {} |
| | |
| | | from third_data import block_info, kpl_api |
| | | from third_data.code_plate_key_manager import KPLCodeJXBlockManager |
| | | from third_data.history_k_data_util import HistoryKDatasUtils, JueJinApi |
| | | from third_data.kpl_data_manager import KPLDataManager |
| | | from third_data.kpl_data_manager import KPLDataManager, KPLLimitUpDataRecordManager |
| | | from third_data.kpl_util import KPLDataType |
| | | from trade import trade_manager, trade_huaxin, l2_trade_util |
| | | |
| | |
| | | # 如果在9:24-9:30 需要加载板块 |
| | | if int("092400") < int(tool.get_now_time_str().replace(":", "")) < int("093000"): |
| | | for d in datas: |
| | | KPLCodeJXBlockManager().load_jx_blocks(d[0], gpcode_manager.get_price(d[0]), float(d[2])) |
| | | KPLCodeJXBlockManager().load_jx_blocks(d[0], gpcode_manager.get_price(d[0]), float(d[2]), KPLLimitUpDataRecordManager.get_current_reasons()) |
| | | time.sleep(1) |
| | | logger_l2_codes_subscript.info("({})发送到华鑫L2代码处理队列:数量-{}", request_id, len(datas)) |
| | | except Exception as e: |
| | |
| | | logger_debug.exception(e) |
| | | |
| | | # ----------------------------------板块相关------------------------------ |
| | | cls.__KPLCodeJXBlockManager.load_jx_blocks(code, buy_1_price, limit_up_price) |
| | | cls.__KPLCodeJXBlockManager.load_jx_blocks(code, buy_1_price, limit_up_price, kpl_data_manager.KPLLimitUpDataRecordManager.get_current_reasons()) |
| | | # 更新板块信息 |
| | | yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() |
| | | CodePlateKeyBuyManager.update_can_buy_blocks(code, |