| | |
| | | """ |
| | | 开盘啦涨停数据管理 |
| | | """ |
| | | import copy |
| | | |
| | | from third_data import kpl_util, kpl_data_manager |
| | | from third_data.history_k_data_manager import HistoryKDataManager |
| | | from third_data.history_k_data_util import HistoryKDatasUtils |
| | |
| | | @return: |
| | | """ |
| | | return kpl_data_manager.KPLLimitUpDataRecordManager.total_datas |
| | | |
| | | |
| | | |
| | | |
| | | class CodeLimitUpSequenceManager: |
| | |
| | | """ |
| | | 最近涨停的板块管理 |
| | | """ |
| | | # 看最近7天 |
| | | __LATEST_DAY_COUNT = 7 |
| | | # 看最近2天,不包含今天 |
| | | __LATEST_DAY_COUNT = 2 |
| | | |
| | | __days = [] |
| | | # 目前涨停 |
| | |
| | | |
| | | @classmethod |
| | | def __load_datas(cls): |
| | | # 加载最近7天的数据 |
| | | __days = HistoryKDatasUtils.get_latest_trading_date_cache(cls.__LATEST_DAY_COUNT - 1) |
| | | now_day = tool.get_now_date_str() |
| | | if __days[0] != now_day: |
| | | __days.insert(0, now_day) |
| | | # 加载最近几天的数据 |
| | | __days = HistoryKDatasUtils.get_latest_trading_date_cache(cls.__LATEST_DAY_COUNT) |
| | | __days = copy.deepcopy(__days) |
| | | # 不能包含今天 |
| | | if __days[0] == tool.get_now_date_str(): |
| | | __days.pop(0) |
| | | cls.__days = __days |
| | | # 加载之前6天的涨停,曾涨停,曾涨停代码的最近6天的K线 |
| | | for day in __days: |
| | | if day == now_day: |
| | | continue |
| | | limit_up_records = get_history_limit_up_datas(day) |
| | | cls.__history_limit_up_day_datas[day] = limit_up_records |
| | | current_limit_up_datas = get_current_limit_up_datas(day) |
| | |
| | | cls.__get_bars(code) |
| | | # 统计前6天的板块信息 |
| | | for day in __days: |
| | | if day == now_day: |
| | | continue |
| | | cls.__block_day_datas[day] = cls.__statistics_limit_up_block_infos_by_day(day) |
| | | |
| | | def set_current_limit_up_data(self, day, datas): |
| | |
| | | def __statistics_limit_up_block_infos_by_day(cls, day): |
| | | """ |
| | | 统计涨停代码信息 |
| | | @return: |
| | | @return:{"板块":(涨停数, 炸板数, {包含的代码})} |
| | | """ |
| | | # 统计板块的 |
| | | current_code_dict = {d[0]: d for d in cls.__current_limit_up_day_datas[day]} |
| | | # history_code_dict = {d[3]: d for d in self.__history_limit_up_day_datas[day]} |
| | | block_codes_dict = {} |
| | | for h in cls.__history_limit_up_day_datas[day]: |
| | | cls.__code_name_dict[h[3]] = h[4] |
| | | if h[2] not in block_codes_dict: |
| | | block_codes_dict[h[2]] = set() |
| | | block_codes_dict[h[2]].add(h[3]) |
| | | # 将板块所包含的代码归类 |
| | | code = h[3] |
| | | cls.__code_name_dict[code] = h[4] |
| | | blocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code) |
| | | if blocks: |
| | | for b in blocks: |
| | | if b not in block_codes_dict: |
| | | block_codes_dict[b] = set() |
| | | block_codes_dict[b].add(code) |
| | | fdata = {} |
| | | for b in block_codes_dict: |
| | | limit_up_count = 0 |
| | |
| | | 统计涨停板块数据 |
| | | @return: |
| | | """ |
| | | # 只统计今天的数据 |
| | | now_day = tool.get_now_date_str() |
| | | try: |
| | | block_dict = self.__statistics_limit_up_block_infos_by_day(now_day) |
| | | self.__block_day_datas[now_day] = block_dict |
| | | except: |
| | | pass |
| | | # 板块出现的天数 |
| | | block_count_dict = {} |
| | | # 板块出现的代码 |
| | | block_codes_dict = {} |
| | | for day in self.__block_day_datas: |
| | | for b in self.__block_day_datas[day]: |
| | | finally_limit_up_count = self.__block_day_datas[day][b][0] |
| | | if finally_limit_up_count < 3: |
| | | continue |
| | | # 板块涨停个数 |
| | | if b not in block_count_dict: |
| | | block_count_dict[b] = set() |
| | | if b not in block_codes_dict: |
| | | block_codes_dict[b] = set() |
| | | block_count_dict[b].add(day) |
| | | block_codes_dict[b] |= self.__block_day_datas[day][b][2] |
| | | |
| | | # [(板块,涨停日期集合)] |
| | | block_count_list = [(k, block_count_dict[k]) for k in block_count_dict] |
| | | block_count_list.sort(key=lambda x: x[1], reverse=True) |
| | | block_count_list.sort(key=lambda x: len(x[1]), reverse=True) |
| | | block_count_list = block_count_list[:50] |
| | | # [(涨停原因,累计涨停次数,连续次数)] |
| | | fdatas = [] |
| | | today_records_code_dict = {d[3]: d for d in self.__history_limit_up_day_datas.get(now_day)} |
| | | for d in block_count_list: |
| | | b = d[0] |
| | | fdata = [d[0], len(d[1])] |
| | | fdata = [b, len(d[1])] |
| | | temp = [] |
| | | max_continue_count = 0 |
| | | for day in self.__days: |
| | | if d[0] in self.__block_day_datas[day]: |
| | | if day not in self.__block_day_datas: |
| | | continue |
| | | if b in self.__block_day_datas[day]: |
| | | finally_limit_up_count = self.__block_day_datas[day][b][0] |
| | | else: |
| | | finally_limit_up_count = 0 |
| | | if b in self.__block_day_datas[day] and finally_limit_up_count >= 3: |
| | | # 板块代码数量>=3个 |
| | | temp.append(day) |
| | | else: |
| | | c = len(temp) |
| | |
| | | |
| | | # 统计今天这个板块中大于二板的代码数量 |
| | | limit_up_counts = 0 |
| | | for code in block_codes_dict[d[0]]: |
| | | if code in today_records_code_dict and today_records_code_dict[code][12] != '首板': |
| | | limit_up_counts += 1 |
| | | fdata.append(limit_up_counts) |
| | | # 获取每天的数量 |
| | | days_datas = [] |
| | | for day in self.__days: |
| | | if day not in self.__block_day_datas: |
| | | continue |
| | | binfo = self.__block_day_datas[day].get(b) |
| | | if not binfo: |
| | | days_datas.append((0, 0)) |
| | |
| | | if cls.__days: |
| | | volumes_data = HistoryKDataManager().get_history_bars(code, cls.__days[1]) |
| | | if volumes_data: |
| | | volumes_data = volumes_data[:cls.__LATEST_DAY_COUNT - 1] |
| | | volumes_data = volumes_data[:cls.__LATEST_DAY_COUNT] |
| | | cls.__k_datas[code] = volumes_data |
| | | if not volumes_data: |
| | | volumes_data = init_data_util.get_volumns_by_code(code, cls.__LATEST_DAY_COUNT - 1) |
| | | volumes_data = init_data_util.get_volumns_by_code(code, cls.__LATEST_DAY_COUNT) |
| | | if volumes_data: |
| | | cls.__k_datas[code] = volumes_data |
| | | # 获取最大涨幅 |
| | |
| | | cls.__k_max_rate[code] = rate |
| | | return cls.__k_datas.get(code) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | # datas = LatestLimitUpBlockManager().statistics_limit_up_block_infos() |
| | | # print(datas) |
| | | code = "600126" |
| | | blocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code) |
| | | print(blocks) |