From ddd49deef7ac6daff95086f112a0061a641c4fe3 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期四, 13 六月 2024 15:36:00 +0800 Subject: [PATCH] 添加订阅日志 --- code_attribute/first_target_code_data_processor.py | 153 +++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 118 insertions(+), 35 deletions(-) diff --git a/code_attribute/first_target_code_data_processor.py b/code_attribute/first_target_code_data_processor.py index f337e6f..e2fff56 100644 --- a/code_attribute/first_target_code_data_processor.py +++ b/code_attribute/first_target_code_data_processor.py @@ -3,28 +3,47 @@ """ # 澶勭悊棣栨澘浠g爜淇℃伅 -import logging import constant -import inited_data -from code_attribute import gpcode_manager, gpcode_first_screen_manager, global_data_loader, code_nature_analyse, \ +from code_attribute import gpcode_manager, gpcode_first_screen_manager, code_nature_analyse, \ code_volumn_manager from code_attribute.code_data_util import ZYLTGBUtil +from code_attribute.code_nature_analyse import HighIncreaseCodeManager +from code_attribute.gpcode_manager import WantBuyCodesManager from log_module.log import logger_first_code_record, logger_l2_codes_subscript -from third_data import kpl_api, block_info from third_data.code_plate_key_manager import CodesHisReasonAndBlocksManager -from third_data.history_k_data_util import HistoryKDatasUtils -from third_data.kpl_data_manager import KPLLimitUpDataRecordManager +from third_data.history_k_data_util import HistoryKDatasUtils, JueJinApi from ths import l2_code_operate -from trade import trade_data_manager -from utils import global_util, tool +from trade import trade_data_manager, l2_trade_util +from settings.trade_setting import MarketSituationManager +from utils import global_util, tool, init_data_util, buy_condition_util __CodesPlateKeysManager = CodesHisReasonAndBlocksManager() + + +def __is_normal_in_5d(code): + """ + 鏈�杩�5澶╂槸鍚﹀浜庢甯哥姸鎬� + @param code: + @return: + """ + now_day = tool.get_now_date_str() + results = JueJinApi.get_history_instruments(JueJinApi.get_juejin_code_list_with_prefix([code]), + tool.date_sub(now_day, 30), tool.date_sub(now_day, 1)) + results = results[-5:] + normal = True + for r in results: + if r["sec_level"] != 1: + normal = False + break + return normal def process_first_codes_datas(dataList, request_id=None): logger_l2_codes_subscript.info(f"{request_id}鍔犺浇l2浠g爜鐩稿叧鏁版嵁") print("棣栨澘浠g爜鏁伴噺锛�", len(dataList)) + # 鑾峰彇鏈�杩�5澶╃殑浜ゆ槗鏃ユ湡锛屼负鍚庨潰鐨勬暟鎹绠楀仛鍑嗗 + HistoryKDatasUtils.get_latest_trading_date_cache(5) limit_up_price_dict = {} temp_codes = [] codes = [] @@ -41,12 +60,11 @@ diff_codes = set(want_codes) - set(codes) if diff_codes: # 鎯充拱鍗曠殑浠g爜杩樻病鏈夊湪鐩爣浠g爜涓� - zyltgb_list = [] for code in diff_codes: # 鑾峰彇娑ㄥ仠浠� _limit_up_price = gpcode_manager.get_limit_up_price(code) if not _limit_up_price: - inited_data.re_set_price_pres([code], True) + init_data_util.re_set_price_pres([code], True) # 鍐嶆鑾峰彇娑ㄥ仠浠� _limit_up_price = gpcode_manager.get_limit_up_price(code) if _limit_up_price: @@ -55,14 +73,6 @@ dataList.append({"code": code, "price": f"{_limit_up_price}", "volume": "0", "volumeUnit": 0, "time": "00:00:00", "zyltgb": "100", "zyltgbUnit": 0}) - # 寮哄埗鏇存柊鑷敱娴侀�氳偂鏈� - if zyltgb_list: - ZYLTGBUtil.save_list(zyltgb_list) - # 灏嗕繚瀛樼殑鏁版嵁鏇存柊鍒板唴瀛樹腑 - for z in zyltgb_list: - val = ZYLTGBUtil.get(z["code"]) - if val: - global_util.zyltgb_map[z["code"]] = val # ---淇濆瓨鏈瓫閫夌殑棣栨澘浠g爜 new_add_codes = gpcode_first_screen_manager.set_target_no_screen_codes(codes) @@ -83,7 +93,7 @@ for code in codes: # 濡傛灉娑ㄥ仠浠锋槸绌哄�煎氨闇�瑕佽缃槰鏃ユ敹鐩樹环鏍� if gpcode_manager.get_limit_up_price(code) is None: - inited_data.re_set_price_pres([code], True) + init_data_util.re_set_price_pres([code], True) # 鏉垮潡鍏抽敭瀛楀噯澶� 鏆傛椂鍒犻櫎 # for code in codes: @@ -100,11 +110,12 @@ # except Exception as e: # logging.exception(e) # pass - + logger_l2_codes_subscript.info(f"{request_id}鍔犺浇l2浠g爜娑ㄥ仠浠风粨鏉�") # 鑾峰彇60澶╂渶澶ц褰� for code in codes: need_get_volumn = False - if code not in global_util.max60_volumn or global_util.max60_volumn.get(code) is None: + if code not in global_util.max60_volumn or global_util.max60_volumn.get( + code) is None or code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) is None: need_get_volumn = True # if not need_get_volumn and code_nature_analyse.CodeNatureRecordManager.get_nature_cache( # code) is None: @@ -114,13 +125,66 @@ if limit_up_price is None: continue try: - volumes_data = inited_data.get_volumns_by_code(code, 150) - volumes = inited_data.parse_max_volume(volumes_data[:90], - code_nature_analyse.is_new_top( - limit_up_price, - volumes_data[:90])) + volumes_data = init_data_util.get_volumns_by_code(code, 150) + volumes = init_data_util.parse_max_volume(code, volumes_data[:90], + code_nature_analyse.is_new_top(code, + limit_up_price, + volumes_data[ + :90]) or code_nature_analyse.is_near_top( + code, + limit_up_price, + volumes_data[:90])) logger_first_code_record.info("{} 鑾峰彇鍒伴鏉�60澶╂渶澶ч噺锛歿}", code, volumes) - code_volumn_manager.set_histry_volumn(code, volumes[0], volumes[1], volumes[2]) + code_volumn_manager.set_histry_volumn(code, volumes[0], volumes[1], volumes[2], volumes[3]) + + # 淇濆瓨K绾垮舰鎬� + k_format = code_nature_analyse.get_k_format(code, limit_up_price, volumes_data) + code_nature_analyse.CodeNatureRecordManager().save_k_format(code, k_format) + + # 鏄惁鍏锋湁杈ㄨ瘑搴� + is_special = True if k_format and k_format[8][0] else False + if not WantBuyCodesManager().is_in_cache(code): + if not is_special: + situation = MarketSituationManager().get_situation_cache() + zylt_threshold_as_yi = buy_condition_util.get_zyltgb_threshold(situation) + if global_util.zyltgb_map.get(code) and global_util.zyltgb_map.get(code) > zylt_threshold_as_yi[ + 1] * 100000000: + l2_trade_util.forbidden_trade(code, + f"鏃犺鲸璇嗗害锛岃嚜鐢辨祦閫氬競鍊�({global_util.zyltgb_map.get(code) // 100000000})>{zylt_threshold_as_yi[1]}浜�") + continue + elif limit_up_price and float(limit_up_price) >= 50: + l2_trade_util.forbidden_trade(code, + f"鏃犺鲸璇嗗害锛屾定鍋滀环({limit_up_price})>50") + continue + if code_nature_analyse.is_price_too_high_in_days(code, volumes_data, limit_up_price)[0]: + # 鍒ゆ柇鏄惁澶珮 + l2_trade_util.forbidden_trade(code, "6澶╁唴鑲′环闀垮緱澶珮") + continue + pass + + if code_nature_analyse.is_continue_limit_up_not_enough_fall_dwon(code, volumes_data): + # 鍒ゆ柇鏄惁澶珮 + l2_trade_util.forbidden_trade(code, "鍥炶俯涓嶅") + continue + + if not __is_normal_in_5d(code): + l2_trade_util.forbidden_trade(code, "鏈�杩�5澶╂湁ST/闈炴甯哥姸鎬�") + continue + + if code_nature_analyse.is_up_too_high_in_10d_with_limit_up(code, volumes_data): + # 鍒ゆ柇鏄惁澶珮 + HighIncreaseCodeManager().add_code(code) + + if code_nature_analyse.is_up_too_high_in_120d(code, volumes_data): + # 鍒ゆ柇鏄惁澶珮 + # l2_trade_util.forbidden_trade(code, "120澶╁唴鑲′环闀垮緱澶珮") + # HighIncreaseCodeManager().add_code(code) + pass + + if code_nature_analyse.is_have_latest_max_volume(code, volumes_data, 2): + # 鏈�杩�2澶╂槸鍚︽槸鏈�楂橀噺 + code_nature_analyse.LatestMaxVolumeManager().set_has_latest_max_volume(code) + # 鍒ゆ柇K绾垮舰鎬� # is_has_k_format, msg = code_nature_analyse.is_has_k_format( # gpcode_manager.get_limit_up_price(code), volumes_data) @@ -136,6 +200,10 @@ # volumes_data) except Exception as e: logger_first_code_record.error(f"{code}:{str(e)}") + logger_first_code_record.exception(e) + + logger_l2_codes_subscript.info(f"{request_id}鍔犺浇l2浠g爜K绾跨粨鏉�") + gpcode_manager.FirstCodeManager().add_record(codes) # 鍒濆鍖栨澘鍧椾俊鎭紝鏆傛椂鍒犻櫎 # for code in codes: @@ -156,6 +224,9 @@ l2_code_operate.L2CodeOperate.get_instance().add_operate(0, lc, "浠g爜琚Щ闄�") # 淇濆瓨鐜颁环 if dataList: + situation = MarketSituationManager().get_situation_cache() + zyltgb_thresholds = buy_condition_util.get_zyltgb_threshold(situation) + want_codes = gpcode_manager.WantBuyCodesManager().list_code_cache() for data in dataList: code = data["code"] codes.append(code) @@ -164,12 +235,30 @@ limit_up_price_dict[code] = limit_up_price else: temp_codes.append(code) + # 鑷敱娴侀�氬競鍊间笉绗﹀悎鏍囧噯 + if not want_codes or code not in want_codes: + # 娌″湪鎯充拱鍗� + zyltgb = global_util.zyltgb_map.get(code) + if zyltgb: + zyltgb_as_yi = round(zyltgb / 100000000, 2) + if zyltgb_as_yi < zyltgb_thresholds[0] or zyltgb_as_yi > zyltgb_thresholds[6]: + # 鎯充拱鍗曚腑鐨勪笉鑳芥帓闄� + continue + elif zyltgb_as_yi > zyltgb_thresholds[1]: + # 姣旀渶澶у彲涔板ぇ鐨勶紝濡傛灉娌℃湁鐭湡杈ㄨ瘑搴﹀氨涓嶄拱 + k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) + if k_format and k_format[8][0] and k_format[8][1].find("鐭湡") >= 0: + pass + else: + # 鏃犵煭鏈熻鲸璇嗗害 + continue + tick_datas.append({"code": code, "price": data["price"], "volume": data["volume"], "volumeUnit": data["volumeUnit"]}) # 鑾峰彇娑ㄥ仠浠� if temp_codes: # 鑾峰彇娑ㄥ仠浠� - inited_data.re_set_price_pres(temp_codes) + init_data_util.re_set_price_pres(temp_codes) # 閲嶆柊鑾峰彇娑ㄥ仠浠� for code in temp_codes: limit_up_price = gpcode_manager.get_limit_up_price(code) @@ -195,18 +284,12 @@ gpcode_manager.FirstCodeManager().add_limited_up_record([code]) pricePre = gpcode_manager.CodePrePriceManager.get_price_pre_cache(code) if pricePre is None: - inited_data.re_set_price_pres([code]) + init_data_util.re_set_price_pres([code]) rate = round((float(price) - pricePre) * 100 / pricePre, 1) prices.append( {"code": code, "time": limit_up_time, "rate": rate, "limit_up": is_limit_up}) - if code in new_add_codes: - if is_limit_up: - place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count( - code) - if place_order_count == 0: - trade_data_manager.PlaceOrderCountManager().place_order(code) gpcode_first_screen_manager.process_ticks(prices) logger_l2_codes_subscript.info(f"({request_id})l2浠g爜鐩稿叧鏁版嵁鍔犺浇瀹屾垚") -- Gitblit v1.8.0