| | |
| | | from code_attribute.gpcode_manager import BlackListCodeManager |
| | | from l2.l2_transaction_data_manager import HuaXinBuyOrderManager |
| | | from log_module.log import logger_system, logger_debug, logger_kpl_limit_up, logger_request_api |
| | | from third_data.kpl_data_constant import LimitUpCodesBlockRecordManager |
| | | from third_data.kpl_data_constant import LimitUpCodesBlockRecordManager, LimitUpDataConstant |
| | | from third_data.kpl_limit_up_data_manager import LatestLimitUpBlockManager, CodeLimitUpSequenceManager |
| | | from third_data.third_blocks_manager import BlockMapManager |
| | | from trade.buy_strategy import OpenLimitUpGoodBlocksBuyStrategy |
| | |
| | | def log_message(self, format, *args): |
| | | pass |
| | | |
| | | def __get_limit_up_list(self): |
| | | def __get_limit_up_statistic_infos(self): |
| | | # 统计目前为止的代码涨停数量(分涨停原因) |
| | | total_datas = KPLLimitUpDataRecordManager.total_datas |
| | | if not total_datas: |
| | | KPLLimitUpDataRecordManager.load_total_datas() |
| | | total_datas = KPLLimitUpDataRecordManager.total_datas |
| | | # 通过涨停时间排序 |
| | | total_datas = list(total_datas) |
| | | current_reason_codes_dict = KPLLimitUpDataRecordManager.get_current_reason_codes_dict() |
| | | |
| | | # 统计涨停原因 |
| | | limit_up_reason_dict = {} |
| | | for d in total_datas: |
| | | if d[2] not in limit_up_reason_dict: |
| | | limit_up_reason_dict[d[2]] = [] |
| | | limit_up_reason_dict[d[2]].append(d) |
| | | for k in limit_up_reason_dict: |
| | | limit_up_reason_dict[k].sort(key=lambda x: int(x[5])) |
| | | # 统计想买单数量 |
| | | want_codes = gpcode_manager.WantBuyCodesManager().list_code_cache() |
| | | limit_up_reason_want_count_dict = {} |
| | | for d in total_datas: |
| | | if d[2] not in limit_up_reason_want_count_dict: |
| | | limit_up_reason_want_count_dict[d[2]] = 0 |
| | | if d[3] in want_codes: |
| | | limit_up_reason_want_count_dict[d[2]] += 1 |
| | | # (板块名称,涨停代码数量,想买单数量,涨停时间) |
| | | limit_up_reason_statistic_info = [ |
| | | (k, len(limit_up_reason_dict[k]), limit_up_reason_want_count_dict.get(k), limit_up_reason_dict[k][0][5]) for |
| | | k in |
| | | limit_up_reason_dict] |
| | | limit_up_reason_statistic_info.sort( |
| | | key=lambda x: len(current_reason_codes_dict[x[0]]) if x[0] in current_reason_codes_dict else 0) |
| | | currents = LimitUpDataConstant.current_limit_up_datas |
| | | records = LimitUpDataConstant.history_limit_up_datas |
| | | records_map = {x[3]: x for x in records} |
| | | current_codes = [d[0] for d in currents] |
| | | record_codes = [d[3] for d in records] |
| | | # 计算涨停时间排序 |
| | | record_reason_dict = {} |
| | | current_reason_dict = {} |
| | | for _code in record_codes: |
| | | blocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(_code) |
| | | if not blocks: |
| | | blocks = set() |
| | | for b in blocks: |
| | | if b not in record_reason_dict: |
| | | record_reason_dict[b] = [] |
| | | record_reason_dict[b].append(_code) |
| | | for _code in current_codes: |
| | | blocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(_code) |
| | | if not blocks: |
| | | blocks = set() |
| | | for b in blocks: |
| | | if b not in record_reason_dict: |
| | | current_reason_dict[b] = [] |
| | | current_reason_dict[b].append(_code) |
| | | # (板块名称,涨停代码数量,炸板数量,涨停时间) |
| | | limit_up_reason_statistic_info = [(k, len(record_reason_dict[k]), len(record_reason_dict[k]) - len( |
| | | current_reason_dict.get(k) if k in current_reason_dict else []), |
| | | int(records_map.get(k)[5])) for k in record_reason_dict] |
| | | limit_up_reason_statistic_info.sort(key=lambda x: x[1] - x[2]) |
| | | limit_up_reason_statistic_info.reverse() |
| | | |
| | | codes_set = set([d[3] for d in total_datas]) |
| | | # 判断是龙几,判断是否涨停,判断是否炸板,加载分数 |
| | | rank_dict = limit_up_data_filter.get_limit_up_time_rank_dict(total_datas) |
| | | limit_up_dict, limit_up_codes, open_limit_up_codes = limit_up_data_filter.get_limit_up_info(codes_set) |
| | | score_dict = {} |
| | | fresult = [] |
| | | ignore_codes = self.__IgnoreCodeManager.list_ignore_codes("1") |
| | | |
| | | total_datas.sort(key=lambda x: int(x[5])) |
| | | total_datas.reverse() |
| | | |
| | | # 获取涨停原因变化记录 |
| | | reason_changes = log_export.load_kpl_reason_changes() |
| | | reason_changes.reverse() |
| | | reason_changes_dict = {} |
| | | for r in reason_changes: |
| | | if r[0] not in reason_changes_dict: |
| | | reason_changes_dict[r[0]] = r[1] |
| | | # 统计最近下单动作反馈 |
| | | order_reasons_dict = log_analyse.get_cant_order_reasons_dict() |
| | | kpl_can_buy_reasons_dict = log_analyse.get_kpl_can_buy_reasons_dict() |
| | | |
| | | for d in total_datas: |
| | | code = d[3] |
| | | # (代码, 名称, 涨停状态(0 - 无状态 1-涨停 2-炸板), 龙几, 首板, 分值, 涨停时间, 原因, 相同原因代码数量, 自由流通, 涨停原因是否变化,涨停原因的流入净额,下单简介) |
| | | limit_up_state = 0 |
| | | if code in limit_up_dict: |
| | | if limit_up_dict[code][0]: |
| | | limit_up_state = 1 |
| | | elif limit_up_dict[code][1]: |
| | | limit_up_state = 2 |
| | | score = "" |
| | | if code in score_dict: |
| | | score = score_dict[code] |
| | | if code in ignore_codes: |
| | | continue |
| | | |
| | | # 涨停原因的净流入金额 |
| | | reason = d[2] |
| | | reason_money = '' |
| | | if reason in self.__jingxuan_cache_dict: |
| | | reason_money = output_util.money_desc(self.__jingxuan_cache_dict[reason][3]) |
| | | elif reason in self.__industry_cache_dict: |
| | | reason_money = output_util.money_desc(self.__industry_cache_dict[reason][3]) |
| | | |
| | | # 匹配下单反馈 |
| | | order_desc = '' |
| | | order_reason = order_reasons_dict.get(code) |
| | | kpl_can_buy_reason = kpl_can_buy_reasons_dict.get(code) |
| | | if order_reason and kpl_can_buy_reason: |
| | | if int(order_reason[0].replace(":", "").replace(".", "")) > int( |
| | | kpl_can_buy_reason[0].replace(":", "").replace(".", "")): |
| | | order_desc = f"不:{order_reason[1]}" |
| | | else: |
| | | order_desc = f"买:{kpl_can_buy_reason[1]}" |
| | | elif order_reason: |
| | | order_desc = f"不:{order_reason[1]}" |
| | | elif kpl_can_buy_reason: |
| | | order_desc = f"买:{kpl_can_buy_reason[1]}" |
| | | |
| | | fresult.append((code, d[4], limit_up_state, f"龙{rank_dict.get(code)}", d[12], score, |
| | | output_util.time_format(int(d[5])), d[2], d[10], output_util.money_desc(d[13]), |
| | | reason_changes_dict.get(code), reason_money, order_desc)) |
| | | response_data = json.dumps({"code": 0, "data": {"limit_up_count": len(limit_up_codes), |
| | | "open_limit_up_count": len(open_limit_up_codes), |
| | | "limit_up_reason_statistic": limit_up_reason_statistic_info, |
| | | "limit_up_codes": fresult}}) |
| | | response_data = json.dumps({"code": 0, "data": {"limit_up_count": len(current_codes), |
| | | "open_limit_up_count": len(record_codes) - len(current_codes), |
| | | "limit_up_reason_statistic": limit_up_reason_statistic_info}}) |
| | | return response_data |
| | | |
| | | def __get_plate_info(self, ps_dict): |
| | |
| | | break |
| | | response_data = json.dumps( |
| | | {"code": 0, "data": indexes}) |
| | | elif url.path == "/kpl/get_limit_up_list": |
| | | response_data = self.__get_limit_up_list() |
| | | elif url.path == "/kpl/get_limit_up_statistic_infos": |
| | | response_data = self.__get_limit_up_statistic_infos() |
| | | |
| | | elif url.path == "/kpl/get_plate_info": |
| | | ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) |