| | |
| | | """ |
| | | import datetime |
| | | |
| | | import juejin |
| | | import tool |
| | | from third_data import kpl_util, kpl_data_manager |
| | | import constant |
| | | from utils import tool |
| | | from third_data import kpl_util |
| | | from third_data.history_k_data_util import HistoryKDatasUtils |
| | | from third_data.kpl_data_manager import KPLLimitUpDataRecordManager, KPLDataManager |
| | | |
| | | from third_data import kpl_data_manager |
| | | |
| | | __before_block_dict = {} |
| | | |
| | |
| | | |
| | | def __load_before_block(code): |
| | | if code not in __before_block_dict: |
| | | blocks = KPLLimitUpDataRecordManager.get_latest_blocks(code) |
| | | blocks = KPLLimitUpDataRecordManager.get_latest_blocks_set(code) |
| | | if blocks: |
| | | blocks = blocks[0].split(',') |
| | | __before_block_dict[code] = blocks |
| | | |
| | | return __before_block_dict.get(code) |
| | | |
| | | |
| | | # 获取之前的板块 |
| | | def get_before_blocks(code): |
| | | return __before_block_dict.get(code) |
| | | |
| | | |
| | | # 获取之前的代码-板块字典 |
| | | def get_before_blocks_dict(): |
| | | return __before_block_dict |
| | | |
| | | |
| | | def __get_code_from_code_info(code_info): |
| | |
| | | # (代码, 名称, 首次涨停时间, 最近涨停时间, 几板, 涨停原因, 板块, 实际流通, 主力净额) |
| | | def __get_blocks(code, limit_up_datas, filter=True): |
| | | blocks = [] |
| | | for data in limit_up_datas: |
| | | if data[0] == code: |
| | | block = data[5] |
| | | if block in kpl_data_manager.INVALID_BLOCKS and filter: |
| | | continue |
| | | blocks.append(block) |
| | | if limit_up_datas: |
| | | for data in limit_up_datas: |
| | | if data[0] == code: |
| | | block = data[5] |
| | | if block in constant.KPL_INVALID_BLOCKS and filter: |
| | | continue |
| | | blocks.append(block) |
| | | return blocks |
| | | |
| | | |
| | |
| | | if now_day in __blocks_dict: |
| | | return __blocks_dict[now_day] |
| | | now_date = datetime.datetime.now() |
| | | end_date = juejin.JueJinManager.get_previous_trading_date(tool.get_now_date_str()) |
| | | end_date = HistoryKDatasUtils.get_previous_trading_date(tool.get_now_date_str()) |
| | | start_date = now_date - datetime.timedelta(days=(day_count * 2 + 10)) |
| | | start_date = start_date.strftime("%Y-%m-%d") |
| | | days = juejin.JueJinManager.get_trading_dates(start_date, end_date) |
| | | days = HistoryKDatasUtils.get_trading_dates(start_date, end_date) |
| | | days = days[0 - day_count:] |
| | | results = KPLLimitUpDataRecordManager.list_blocks_with_day(days) |
| | | __blocks_dict[now_day] = results |
| | |
| | | return blocks |
| | | |
| | | |
| | | def get_target_block(code, filter=False): |
| | | def get_target_block_info(code, filter=False): |
| | | latest_datas = __kplDataManager.get_data(kpl_util.KPLDataType.LIMIT_UP) |
| | | blocks = __get_blocks(code, latest_datas, filter) |
| | | if not blocks: |
| | |
| | | target_block = None |
| | | if blocks: |
| | | for block in blocks: |
| | | if block in kpl_data_manager.INVALID_BLOCKS and filter: |
| | | if block in constant.KPL_INVALID_BLOCKS and filter: |
| | | continue |
| | | target_block = block |
| | | break |
| | |
| | | target_block = None |
| | | if blocks: |
| | | for block in blocks: |
| | | if block in kpl_data_manager.INVALID_BLOCKS: |
| | | if block in constant.KPL_INVALID_BLOCKS: |
| | | continue |
| | | target_block = block |
| | | break |
| | |
| | | # 是否出现过高位板 |
| | | high_block_infos = [] |
| | | for block in blocks: |
| | | if block in kpl_data_manager.INVALID_BLOCKS: |
| | | if block in constant.KPL_INVALID_BLOCKS: |
| | | continue |
| | | if latest_datas: |
| | | has_high, high_code_info = __is_has_high_code(block, latest_datas) |
| | |
| | | code_ = d[3] |
| | | limit_up_codes_info_set.add((code_, d[5])) |
| | | block_codes_set.add(code_) |
| | | elif d[3]==code: |
| | | elif d[3] == code: |
| | | limit_up_codes_info_set.add((d[3], d[5])) |
| | | # 获取涨停的顺序 |
| | | limit_up_index = -1 |
| | |
| | | re_limit_codes = set() |
| | | # 炸板: |
| | | # (代码,名称,涨幅,板块,实际流通) |
| | | for data in open_limit_up_datas: |
| | | blocks = set(data[3].split("、")) |
| | | if target_block not in blocks: |
| | | continue |
| | | code_ = data[0] |
| | | break_codes.add(code_) |
| | | if open_limit_up_datas: |
| | | for data in open_limit_up_datas: |
| | | blocks = set(data[3].split("、")) |
| | | if target_block not in blocks: |
| | | continue |
| | | code_ = data[0] |
| | | break_codes.add(code_) |
| | | # 统计回封 |
| | | for data in latest_datas: |
| | | if data[5] != target_block: |
| | | continue |
| | | # 回封 |
| | | if data[2] != data[3]: |
| | | re_limit_codes.add(data[0]) |
| | | if latest_datas: |
| | | for data in latest_datas: |
| | | if data[5] != target_block: |
| | | continue |
| | | # 回封 |
| | | if data[2] != data[3]: |
| | | re_limit_codes.add(data[0]) |
| | | |
| | | # 排除自己 |
| | | break_codes.discard(code) |
| | |
| | | return fresult |
| | | |
| | | |
| | | # 初始化板块数据 |
| | | def init(): |
| | | # 加载数据到内存中 |
| | | kpl_data_manager.get_current_limit_up_data_records(10) |
| | | # 加载最近数据到内存中 |
| | | limit_up_datas = kpl_data_manager.KPLDataManager().get_data(kpl_util.KPLDataType.LIMIT_UP) |
| | | if limit_up_datas: |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.latest_origin_datas = limit_up_datas |
| | | |
| | | |
| | | def init_code(code): |
| | | # 加载历史涨停原因 |
| | | __load_before_block(code) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | get_info("603133") |