From 21b84025d0d2543b5f6dc8c22859d25ce0e5de30 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期二, 10 十月 2023 18:13:46 +0800 Subject: [PATCH] 交易日志格式化处理 --- l2/l2_data_manager_new.py | 61 +++++++++++++++++++++++++++--- 1 files changed, 54 insertions(+), 7 deletions(-) diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py index 138310e..e263301 100644 --- a/l2/l2_data_manager_new.py +++ b/l2/l2_data_manager_new.py @@ -13,9 +13,9 @@ from utils import global_util, ths_industry_util, tool import l2_data_util from db import redis_manager_delegate as redis_manager -from third_data.code_plate_key_manager import CodePlateKeyBuyManager +from third_data.code_plate_key_manager import CodePlateKeyBuyManager, KPLCodeJXBlockManager from trade import trade_manager, trade_queue_manager, l2_trade_factor, l2_trade_util, \ - trade_result_manager, current_price_process_manager, trade_data_manager, trade_huaxin + trade_result_manager, current_price_process_manager, trade_data_manager, trade_huaxin, trade_record_log_util from l2 import safe_count_manager, l2_data_manager, l2_log, l2_data_source_util, code_price_manager, \ transaction_progress, cancel_buy_strategy, l2_data_log from l2.cancel_buy_strategy import SecondCancelBigNumComputer, HourCancelBigNumComputer, DCancelBigNumComputer, \ @@ -214,6 +214,7 @@ __TradeBuyQueue = transaction_progress.TradeBuyQueue() __latest_process_order_unique_keys = {} __latest_process_not_order_unique_keys_count = {} + __trade_log_placr_order_info_dict = {} # 涓嬪崟淇℃伅淇濆瓨 # 鍒濆鍖� __TradePointManager = l2_data_manager.TradePointManager() __SecondCancelBigNumComputer = SecondCancelBigNumComputer() @@ -287,6 +288,7 @@ @classmethod def set_real_place_order_index(cls, code, index, buy_single_index): + trade_record_log_util.add_real_place_order_position_log(code, index, buy_single_index) cancel_buy_strategy.set_real_place_position(code, index, buy_single_index) # 澶勭悊鍗庨懌L2鏁版嵁 @@ -324,6 +326,8 @@ def process_add_datas(cls, code, add_datas, capture_timestamp, __start_time): now_time_str = tool.get_now_time_str() if len(add_datas) > 0: + if code not in cls.__trade_log_placr_order_info_dict: + cls.__trade_log_placr_order_info_dict[code] = trade_record_log_util.PlaceOrderInfo() # 鎷兼帴鏁版嵁 local_today_datas[code].extend(add_datas) l2.l2_data_util.load_num_operate_map(local_today_num_operate_map, code, add_datas) @@ -541,6 +545,7 @@ code) if not can: l2_log.debug(code, "涓嶅彲浠ヤ笅鍗曪紝鍘熷洜锛歿}", reason) + trade_record_log_util.add_cant_place_order_log(code, reason) if need_clear_data: trade_result_manager.real_cancel_success(code, buy_single_index, buy_exec_index, local_today_datas.get(code)) @@ -559,10 +564,25 @@ l2_log.debug(code, "澶勭悊涔板叆鎴愬姛") params_desc = cls.__l2PlaceOrderParamsManagerDict[code].get_buy_rank_desc() l2_log.debug(code, params_desc) - l2_log.trade_record(code, "涓嬪崟", - "'buy_start_index':{} ,'buy_exec_index':{},'volume_reate':{},'desc':'{}'", - buy_single_index, buy_exec_index, cls.volume_rate_info[code][0], - params_desc) + ############璁板綍涓嬪崟鏃剁殑鏁版嵁############ + try: + jx_blocks, jx_blocks_by = KPLCodeJXBlockManager().get_jx_blocks_cache( + code), KPLCodeJXBlockManager().get_jx_blocks_cache(code, by=True) + info = cls.__trade_log_placr_order_info_dict[code] + info.set_buy_index(buy_single_index, buy_exec_index) + if jx_blocks: + info.set_kpl_blocks(list(jx_blocks)) + elif jx_blocks_by: + info.set_kpl_blocks(list(jx_blocks_by)) + else: + info.set_kpl_blocks([]) + + trade_record_log_util.add_place_order_log(code, info) + except Exception as e: + async_log_util.error(logger_l2_error, f"鍔犲叆涔板叆璁板綍鏃ュ織鍑洪敊锛歿str(e)}") + + + except Exception as e: async_log_util.exception(logger_l2_error, e) l2_log.debug(code, "鎵ц涔板叆寮傚父:{}", str(e)) @@ -929,9 +949,10 @@ if cancel_index is None: cancel_index = total_datas[-1]["index"] cls.__LatestCancelIndexManager.set_latest_cancel_index(code, cancel_index) + # 娣诲姞鎾ゅ崟鏃ュ織璁板綍 + trade_record_log_util.add_cancel_msg_log(code, msg) cancel_result = cls.__cancel_buy(code) if cancel_result: - l2_log.trade_record(code, "鎾ゅ崟", "'index':{} , 'msg':'{}'", cancel_index, msg) trade_result_manager.real_cancel_success(code, buy_single_index, buy_exec_index, total_datas) l2_log.debug(code, "鎵ц鎾ゅ崟缁撴潫锛屽師鍥狅細{}", msg) return True @@ -1248,6 +1269,12 @@ max_buy_num_set_count += total_datas[i1]["re"] # 鏈夋挙鍗曚俊鍙凤紝涓斿皬浜庨槇鍊� if buy_nums >= threshold_num and buy_count >= threshold_count and trigger_buy and max_buy_num_set_count >= big_num_count: + try: + info = cls.__trade_log_placr_order_info_dict[code] + info.set_trade_factor(threshold_money, threshold_count, list(max_buy_num_set)) + except Exception as e: + async_log_util.error(logger_l2_error, f"璁板綍浜ゆ槗鍥犲瓙鍑洪敊锛歿str(e)}") + return i, buy_nums, buy_count, None, max_buy_num_set l2_log.buy_debug(code, "灏氭湭鑾峰彇鍒颁拱鍏ユ墽琛岀偣锛岃捣濮嬭绠椾綅缃細{} 缁熻绾拱鎵嬫暟锛歿} 鐩爣绾拱鎵嬫暟锛歿} 缁熻绾拱鍗曟暟锛歿} 鐩爣绾拱鍗曟暟锛歿} 澶у崟鏁伴噺锛歿} 鐩爣澶у崟鏁伴噺锛歿}", @@ -1258,7 +1285,27 @@ return None, buy_nums, buy_count, None, max_buy_num_set +def test_trade_record(): + code = "000333" + __trade_log_placr_order_info_dict = {code: trade_record_log_util.PlaceOrderInfo()} + try: + jx_blocks, jx_blocks_by = KPLCodeJXBlockManager().get_jx_blocks_cache( + code), KPLCodeJXBlockManager().get_jx_blocks_cache(code, by=True) + info = __trade_log_placr_order_info_dict[code] + info.set_buy_index(0, 1) + if jx_blocks: + info.set_kpl_blocks(list(jx_blocks)) + elif jx_blocks_by: + info.set_kpl_blocks(list(jx_blocks_by)) + else: + info.set_kpl_blocks([]) + + trade_record_log_util.add_place_order_log(code, info) + except: + pass + if __name__ == "__main__": + test_trade_record() # yesterday_limit_up_data_records = kpl_data_manager.get_current_limit_up_data_records(1)[0][1] # yesterday_codes = set([x[0] for x in yesterday_limit_up_data_records]) # print(yesterday_codes) -- Gitblit v1.8.0