| | |
| | | from third_data import kpl_util, kpl_api |
| | | from third_data.code_plate_key_manager import LimitUpCodesPlateKeyManager, CodesHisReasonAndBlocksManager |
| | | |
| | | |
| | | # 代码对应的涨停原因保存 |
| | | from third_data.kpl_util import KPLPlatManager |
| | | from third_data.kpl_util import KPLPlatManager, KPLDataType |
| | | |
| | | |
| | | class KPLCodeLimitUpReasonManager: |
| | |
| | | return dict_ |
| | | |
| | | |
| | | |
| | | |
| | | class KPLLimitUpDataRecordManager: |
| | | total_datas = None |
| | | latest_datas = {} |
| | | latest_origin_datas=[] |
| | | __kplPlatManager = KPLPlatManager() |
| | | __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager() |
| | | __CodesPlateKeysManager = CodesHisReasonAndBlocksManager() |
| | | |
| | | @classmethod |
| | | def __load_hist_and_blocks(cls,code): |
| | | def __load_hist_and_blocks(cls, code): |
| | | # 有数据新增,加载历史原因与板块 |
| | | his_reasons = cls.get_latest_infos(code, 10, False) |
| | | his_reasons = set([r[0] for r in his_reasons]) |
| | |
| | | cls.__CodesPlateKeysManager.set_blocks(code, bs) |
| | | except Exception as e: |
| | | pass |
| | | |
| | | |
| | | @classmethod |
| | | def save_record(cls, day, records): |
| | |
| | | code_block_dict[code].add(b) |
| | | # 设置涨停数据 |
| | | if records: |
| | | cls.latest_origin_datas = records |
| | | cls.__LimitUpCodesPlateKeyManager.set_today_limit_up([(r[0], r[5]) for r in records]) |
| | | |
| | | # 涨停数据记录 |
| | |
| | | return json.loads(lines[0]) |
| | | return None |
| | | |
| | | # 获取最近几天的数据,根据日期倒序返回 |
| | | def get_latest_from_file(self, type, count): |
| | | files = os.listdir(constant.CACHE_PATH) |
| | | file_name_list = [] |
| | | for f in files: |
| | | if f[10:] == f"_{type.value}.log": |
| | | file_name_list.append((f.split("_")[0], f)) |
| | | |
| | | file_name_list.sort(key=lambda x: x[0], reverse=True) |
| | | file_name_list = file_name_list[:count] |
| | | fresults = [] |
| | | for file in file_name_list: |
| | | path = f"{constant.CACHE_PATH}/{file[1]}" |
| | | if not os.path.exists(path): |
| | | continue |
| | | with open(path, 'r') as f: |
| | | lines = f.readlines() |
| | | if lines: |
| | | fresults.append((file[0], json.loads(lines[0]))) |
| | | |
| | | return fresults |
| | | |
| | | def save_data(self, type, datas): |
| | | self.__latest_datas[type] = datas |
| | | self.__save_in_file(type, datas) |
| | |
| | | # print(day, list_) |
| | | |
| | | |
| | | # 历史涨停列表 |
| | | __limit_up_list_records_dict = {} |
| | | |
| | | |
| | | # 获取最近几天的实时涨停信息 |
| | | # 返回格式([日期,数据]) |
| | | def get_current_limit_up_data_records(count): |
| | | fresults = [] |
| | | day = tool.get_now_date_str() |
| | | datas = [] |
| | | if day in __limit_up_list_records_dict: |
| | | datas = __limit_up_list_records_dict[day] |
| | | else: |
| | | datas = KPLDataManager().get_latest_from_file(KPLDataType.LIMIT_UP, 10) |
| | | if datas: |
| | | # 保存数据 |
| | | __limit_up_list_records_dict[day] = datas |
| | | for i in range(len(datas)): |
| | | if datas[i][0] == day: |
| | | continue |
| | | fresults.append(datas[i]) |
| | | if len(fresults) >= count: |
| | | break |
| | | return fresults |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | ds = set(["1", "2", "3"]) |
| | | print(ds.pop()) |
| | | fresults = get_current_limit_up_data_records(2) |
| | | for d in fresults: |
| | | print(d) |
| | | get_current_limit_up_data_records(2) |