From 2f2516749615da866e96d8d24e499b7ecbb63a3e Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 23 六月 2025 12:28:52 +0800 Subject: [PATCH] 默认交易模式变更/真实下单位置计算位置修改 --- output/code_info_output.py | 373 +++++++++++++++++++++++++++++++++++----------------- 1 files changed, 251 insertions(+), 122 deletions(-) diff --git a/output/code_info_output.py b/output/code_info_output.py index c47e614..c4b5844 100644 --- a/output/code_info_output.py +++ b/output/code_info_output.py @@ -6,21 +6,26 @@ # 涓嬪崟鍙傛暟淇℃伅 # 閫夎偂瀹� # 甯傚満鐑害 +import logging import sys import time import code_attribute -from code_attribute import code_volumn_manager, limit_up_time_manager, global_data_loader, gpcode_manager -import constant +from code_attribute import code_volumn_manager, limit_up_time_manager, global_data_loader, gpcode_manager, \ + code_nature_analyse +from l2.l2_data_manager import OrderBeginPosInfo +from l2.l2_data_util import L2DataUtil +from third_data.code_plate_key_manager import KPLCodeJXBlockManager +from third_data.kpl_data_constant import LimitUpCodesBlockRecordManager +from trade.buy_radical.block_special_codes_manager import BlockSpecialCodesManager from utils import global_util, tool from log_module import log, log_export from l2 import l2_data_manager, l2_data_util, transaction_progress, l2_data_manager_new, code_price_manager -from l2.cancel_buy_strategy import HourCancelBigNumComputer +from cancel_strategy.s_l_h_cancel_strategy import HourCancelBigNumComputer import l2.l2_data_manager_new from third_data import kpl_data_manager, kpl_api from third_data.kpl_data_manager import KPLLimitUpDataRecordManager -from trade import first_code_score_manager, l2_trade_factor, trade_manager, l2_trade_util, trade_record_log_util +from trade import l2_trade_factor, trade_manager, l2_trade_util, trade_record_log_util, trade_constant from trade.l2_trade_factor import L2TradeFactorUtil -import trade.deal_big_money_manager base_output_content = {} kpl_block_info_dict = {} @@ -29,7 +34,6 @@ def __get_base_html_content(): - print("璺緞", sys.path[0]) if base_output_content.get('css') is None: __base_html_content = "" with open("./output/css/style.css", mode='r') as f: @@ -66,9 +70,9 @@ day = tool.get_now_date_str() is_target_code = gpcode_manager.FirstCodeManager().is_in_first_record_cache(code) code_extra_infos = [] - if l2_trade_util.BlackListCodeManager().is_in_cache(code): + if gpcode_manager.BlackListCodeManager().is_in_cache(code): code_extra_infos.append("榛戝悕鍗�") - if l2_trade_util.WhiteListCodeManager().is_in_cache(code): + if gpcode_manager.WhiteListCodeManager().is_in_cache(code): code_extra_infos.append("鐧藉悕鍗�") # 鑾峰彇鐧藉悕鍗�,榛戝悕鍗� if code_attribute.gpcode_manager.WantBuyCodesManager().is_in_cache(code): @@ -77,48 +81,55 @@ code_extra_infos.append("鏆備笉涔�") params["code"] = code params["code_name"] = f"{gpcode_manager.get_code_name(code)} {code} 锛坽','.join(code_extra_infos)}锛�" - - score_info = None - buy_params_info = None - xgb_infos = None total_datas = l2_data_util.local_today_datas.get(code) if total_datas is None: - l2_data_util.load_l2_data(code) - total_datas = l2_data_util.local_today_datas.get(code) + total_datas = [] + # l2_data_util.load_l2_data(code) + # total_datas = l2_data_util.local_today_datas.get(code) if is_target_code: limit_up_price = gpcode_manager.get_limit_up_price(code) limit_up_time = limit_up_time_manager.LimitUpTimeManager().get_limit_up_time_cache(code) - volume_rate, volume_info = code_volumn_manager.get_volume_rate(code, True) - (score, score_list), score_source_list = first_code_score_manager.get_score(code, volume_rate, limit_up_time, - True) + volume_rate, volume_info = code_volumn_manager.CodeVolumeManager().get_volume_rate(code, with_info=True) ################################涔板墠璇勫垎################################ # zyltgb, limit_price, bidding, k_form, code_nature, hot_block, volume_rate, limit_up_time, # deal_big_money - log.logger_debug.info(f"鏉垮潡鐑害鑰楁椂锛歿time.time() - __start_time}") + # log.logger_debug.info(f"鏉垮潡鐑害鑰楁椂锛歿time.time() - __start_time}") __start_time = time.time() ###############################涓嬪崟淇℃伅############################### params["trade_data"] = {} # 鑾峰彇涔板叆鎰忔効 - volume_rate = score_source_list[6] __L2PlaceOrderParamsManager = l2_trade_factor.L2PlaceOrderParamsManager(code, True, volume_rate, - code_volumn_manager.get_volume_rate_index( + code_volumn_manager.CodeVolumeManager().get_volume_rate_index( volume_rate), - ( - (score, score_list), - score_source_list)) + None) # 鏄惁鍙互涔板叆鐨勪俊鎭� - can_buy_info = l2.l2_data_manager_new.L2TradeDataProcessor.can_buy_first(code, limit_up_price) - params["trade_data"]["can_buy_info"] = can_buy_info + try: + can_buy_info = l2.l2_data_manager_new.L2TradeDataProcessor.can_buy_first_new(code, limit_up_price) + params["trade_data"]["can_buy_info"] = can_buy_info + except: + pass + + # 鑾峰彇閲忓弬鑰冩棩鏈� + try: + volume_refer_date, volume_refer_date_distance = code_volumn_manager.CodeVolumeManager().get_volume_refer_date( + code) + params["trade_data"]["volume_refer_date"] = volume_refer_date + except: + pass + + # 鑾峰彇鏄惁 + k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) + if k_format: + params["trade_data"]["special_info"] = k_format[8] __base_L2PlaceOrderParamsManager = l2_trade_factor.L2PlaceOrderParamsManager(code, False, volume_rate, - code_volumn_manager.get_volume_rate_index( + code_volumn_manager.CodeVolumeManager().get_volume_rate_index( volume_rate), - ((score, score_list), - score_source_list)) + None) if -1 < __L2PlaceOrderParamsManager.score_index < 3: params["trade_data"]["star"] = {"desc": "涓诲姩涔板叆"} if __L2PlaceOrderParamsManager.score_index == 0: @@ -155,53 +166,68 @@ pass else: if trade_progress < len(total_datas): + + trade_progress_datas = [] + for min_money in [30000, 20000, 10000]: + for i in range(trade_progress - 1, -1, -1): + # 鏄惁涓烘定鍋滀拱 + data = total_datas[i] + if L2DataUtil.is_limit_up_price_buy(total_datas[i]['val']): + if data['val']['num'] * float(data['val']['price']) > min_money: + trade_progress_datas.append({"time": data['val']['time'], + "num": data['val']['num'], "money": money_desc(round( + data['val']['num'] * float(data['val']['price']) * 100))}) + break + if trade_progress_datas: + break data = total_datas[trade_progress] - params["trade_data"]["trade_progress"] = {"time": data['val']['time'], - "num": data['val']['num'], "money": round( - data['val']['num'] * float(data['val']['price']) * 100 / 10000, 1)} + trade_progress_datas.append({"time": data['val']['time'], + "num": data['val']['num'], "money": money_desc(round( + data['val']['num'] * float(data['val']['price']) * 100))}) + params["trade_data"]["trade_progress"] = trade_progress_datas # 涔板叆淇″彿 - buy_single_index, buy_exec_index, compute_index, num, count, max_num_set, volume_rate = l2_data_manager.TradePointManager().get_buy_compute_start_data_cache( + order_begin_pos = l2_data_manager.TradePointManager().get_buy_compute_start_data_cache( code) - if buy_single_index is None: + if order_begin_pos.buy_single_index is None: # buy_params_info.append("鏃犱俊鍙�") pass else: - data = total_datas[buy_single_index] + data = total_datas[order_begin_pos.buy_single_index] params["trade_data"]["buy_single"] = {"time": data['val']['time'], "num": data['val']['num'], "money": round(data['val']['num'] * float( data['val']['price']) * 100 / 10000, 1)} - if buy_exec_index is None or buy_exec_index < 0: + if order_begin_pos.buy_exec_index is None or order_begin_pos.buy_exec_index < 0: # buy_params_info.append("鏈笅鍗�") pass else: - data = total_datas[buy_exec_index] + data = total_datas[order_begin_pos.buy_exec_index] params["trade_data"]["buy_exec"] = {"time": data['val']['time'], "num": data['val']['num'], "money": round(data['val']['num'] * float( data['val']['price']) * 100 / 10000, 1)} params["trade_data"]["trade_state"] = {} trade_state = trade_manager.CodesTradeStateManager().get_trade_state_cache(code) - if trade_state == trade_manager.TRADE_STATE_BUY_PLACE_ORDER or trade_state == trade_manager.TRADE_STATE_BUY_DELEGATED: + if trade_state == trade_constant.TRADE_STATE_BUY_PLACE_ORDER or trade_state == trade_constant.TRADE_STATE_BUY_DELEGATED: params["trade_data"]["trade_state"]["order"] = True params["trade_data"]["trade_state"]["desc"] = "宸蹭笅鍗�" else: params["trade_data"]["trade_state"]["order"] = False - if trade_state == trade_manager.TRADE_STATE_NOT_TRADE: + if trade_state == trade_constant.TRADE_STATE_NOT_TRADE: params["trade_data"]["trade_state"]["desc"] = "鏈氦鏄�" - elif trade_state == trade_manager.TRADE_STATE_BUY_CANCEL_ING: + elif trade_state == trade_constant.TRADE_STATE_BUY_CANCEL_ING: params["trade_data"]["trade_state"]["desc"] = "鎾ゅ崟涓�" - elif trade_state == trade_manager.TRADE_STATE_BUY_CANCEL_SUCCESS: + elif trade_state == trade_constant.TRADE_STATE_BUY_CANCEL_SUCCESS: params["trade_data"]["trade_state"]["desc"] = "鎾ゅ崟鎴愬姛" - elif trade_state == trade_manager.TRADE_STATE_BUY_SUCCESS: + elif trade_state == trade_constant.TRADE_STATE_BUY_SUCCESS: params["trade_data"]["trade_state"]["desc"] = "宸叉垚浜�" - log.logger_debug.info(f"涓嬪崟淇℃伅鑰楁椂锛歿time.time() - __start_time}") + # log.logger_debug.info(f"涓嬪崟淇℃伅鑰楁椂锛歿time.time() - __start_time}") __start_time = time.time() # H鎾ょ洃鍚寖鍥� - if trade_state == trade_manager.TRADE_STATE_BUY_PLACE_ORDER or trade_state == trade_manager.TRADE_STATE_BUY_DELEGATED or trade_state == trade_manager.TRADE_STATE_BUY_SUCCESS: + if trade_state == trade_constant.TRADE_STATE_BUY_PLACE_ORDER or trade_state == trade_constant.TRADE_STATE_BUY_DELEGATED or trade_state == trade_constant.TRADE_STATE_BUY_SUCCESS: hcancel_datas_dict, cancel_indexes_set = HourCancelBigNumComputer().get_watch_index_dict(code) # 鏍规嵁鏃ュ織璇诲彇瀹炴椂鐨勮绠楁暟鎹� h_cancel_latest_compute_info = log_export.get_h_cancel_compute_info(code) @@ -219,30 +245,30 @@ params["trade_data"]["h_cancel"]["datas"].append( (val["time"], val["num"], money_desc(val["num"] * float(val["price"]) * 100), (1 if canceled else 0))) - log.logger_debug.info(f"H鎾ょ洃鍚寖鍥磋�楁椂锛歿time.time() - __start_time}") + # log.logger_debug.info(f"H鎾ょ洃鍚寖鍥磋�楁椂锛歿time.time() - __start_time}") __start_time = time.time() ##############################涓诲姩涔帮紝琚姩涔�################################## # 杩斿洖涓诲姩涔�,琚姩涔�,涓嶄拱鐨勫垪琛�(浠g爜, 鍚嶇О, 寰楀垎, 鏄惁娑ㄥ仠) - codes_score = __load_codes_scores() + # codes_score = __load_codes_scores() params["initiative_buy_codes"] = [] - for d in codes_score[0]: - params["initiative_buy_codes"].append( - {"name": d[1], "code": d[0], "score": d[2], "limit_up": d[3], "open_limit_up": d[4]}) + # for d in codes_score[0]: + # params["initiative_buy_codes"].append( + # {"name": d[1], "code": d[0], "score": d[2], "limit_up": d[3], "open_limit_up": d[4]}) params["passive_buy_codes"] = [] - for d in codes_score[1]: - params["passive_buy_codes"].append( - {"name": d[1], "code": d[0], "score": d[2], "limit_up": d[3], "open_limit_up": d[4]}) + # for d in codes_score[1]: + # params["passive_buy_codes"].append( + # {"name": d[1], "code": d[0], "score": d[2], "limit_up": d[3], "open_limit_up": d[4]}) params["passive_buy_codes"] = params["passive_buy_codes"] - log.logger_debug.info(f"涓诲姩涔帮紝琚姩涔拌�楁椂锛歿time.time() - __start_time}") + # log.logger_debug.info(f"涓诲姩涔帮紝琚姩涔拌�楁椂锛歿time.time() - __start_time}") __start_time = time.time() - trade_info = __load_trade_record(code, total_datas) + trade_info = load_trade_record(code, total_datas) params["trade_record"] = {"open_limit_up": trade_info[0], "records": trade_info[2]} - log.logger_debug.info(f"璇诲彇浜ゆ槗璁板綍鑰楁椂锛歿time.time() - __start_time}") + # log.logger_debug.info(f"璇诲彇浜ゆ槗璁板綍鑰楁椂锛歿time.time() - __start_time}") __start_time = time.time() ##############################寮�鐩樺暒鐩稿叧淇℃伅################################## @@ -251,17 +277,24 @@ "industry": format_plate_output(industry)} # 鑾峰彇寮�鐩樺暒鏉垮潡 plate_info = None - if code not in kpl_block_info_dict: - plate_info = kpl_api.getStockIDPlate(code) - else: - plate_info = kpl_block_info_dict.get(code) + jingxuan_block_info = KPLCodeJXBlockManager().get_jx_blocks_cache(code) + if not jingxuan_block_info: + jingxuan_block_info = KPLCodeJXBlockManager().get_jx_blocks_cache(code, by=True) + if jingxuan_block_info: + jingxuan_blocks = jingxuan_block_info[0] + plate_info = [(0, x, 0) for x in jingxuan_blocks] # set([x[1] for x in jingxuan_blocks]) + if not plate_info: + if code not in kpl_block_info_dict: + plate_info = kpl_api.getStockIDPlate(code) + else: + plate_info = kpl_block_info_dict.get(code) if plate_info: kpl_block_info_dict[code] = plate_info plate_info.sort(key=lambda x: x[2]) plate_info.reverse() params["kpl_code_info"]["plate"] = [(k[0], k[1], k[2], format_plate_output(k[1])[1]) for k in plate_info] - log.logger_debug.info(f"寮�鐩樺暒鏉垮潡鑰楁椂锛歿time.time() - __start_time}") + # log.logger_debug.info(f"寮�鐩樺暒鏉垮潡鑰楁椂锛歿time.time() - __start_time}") __start_time = time.time() # 鑾峰彇浠g爜鐨勫巻鍙叉定鍋滄暟鎹�,(娑ㄥ仠鍘熷洜,鏃ユ湡,鏉垮潡) @@ -269,6 +302,13 @@ if code_records: code_records = [(format_plate_output(k[0]), k[1], [format_plate_output(k1) for k1 in k[2].split("銆�")]) for k in code_records] + # 淇敼鍘嗗彶 + # code_records = LimitUpCodesBlockRecordManager().get_radical_buy_blocks_origin_data(code) + # if code_records: + # code_records = [(f"{x[0]}x{x[1]}", x[2], '') for x in code_records] + # else: + # code_records = [] + params["kpl_code_info"]["code_records"] = code_records if not KPLLimitUpDataRecordManager.total_datas: @@ -281,64 +321,72 @@ params["kpl_code_info"]["today"] = (format_plate_output(d[2]), d[1], plates) break - log.logger_debug.info(f"鑾峰彇浠g爜鐨勫巻鍙叉定鍋滄暟鎹�楁椂锛歿time.time() - __start_time}") + # log.logger_debug.info(f"鑾峰彇浠g爜鐨勫巻鍙叉定鍋滄暟鎹�楁椂锛歿time.time() - __start_time}") __start_time = time.time() return params -def __load_codes_scores(): - # 鑾峰彇鎵�鏈夌洃鍚腑鐨勪唬鐮� - codes = gpcode_manager.FirstGPCodesManager().get_first_gp_codes() - scores = {} # l2_data_manager_new.L2TradeDataProcessor.get_code_scores() - for code in codes: - if code not in scores: - # 鑾峰彇鍒嗘暟 - try: - limit_up_time = limit_up_time_manager.LimitUpTimeManager().get_limit_up_time_cache(code) - volume_rate, volume_info = code_volumn_manager.get_volume_rate(code, True) - (score, score_list), score_source_list = first_code_score_manager.get_score(code, volume_rate, - limit_up_time, - True) - scores[code] = score - except: - pass - # 绛涢��180鍒嗕互涓婄殑浠g爜 - scores_list = [] - for code in scores: - code_name = gpcode_manager.get_code_name(code) - # 鑾峰彇鐜颁环锛屽垽鏂槸鍚︽定鍋� - current_price_info = global_util.cuurent_prices.get(code) - limit_up_info = code_price_manager.Buy1PriceManager().get_limit_up_info(code) - is_limit_up = True - open_limit_up = limit_up_info[0] and limit_up_info[1] - if current_price_info is not None and not current_price_info[1]: - is_limit_up = False +# 鑾峰彇寮�鐩樺暒鏉垮潡淇℃伅 +def get_kpl_block_info(code): + def format_plate_output(_plat): + return _plat, '' + + ##############################寮�鐩樺暒鐩稿叧淇℃伅################################## + industry = global_util.code_industry_map.get(code) + kpl_code_info = { + "industry": format_plate_output(industry)} + # 鑾峰彇寮�鐩樺暒鏉垮潡 + plate_info = None + jingxuan_block_info = KPLCodeJXBlockManager().get_jx_blocks_cache(code) + if not jingxuan_block_info: + jingxuan_block_info = KPLCodeJXBlockManager().get_jx_blocks_cache(code, by=True) + if jingxuan_block_info: + jingxuan_blocks = jingxuan_block_info[0] + plate_info = [(0, x, 0) for x in jingxuan_blocks] # set([x[1] for x in jingxuan_blocks]) + if not plate_info: + if code not in kpl_block_info_dict: + plate_info = kpl_api.getStockIDPlate(code) else: - is_limit_up = True - scores_list.append((code, code_name, scores[code], is_limit_up, open_limit_up)) - scores_list.sort(key=lambda x: x[2], reverse=True) - fscores_list = [[], [], []] - for score in scores_list: - if score[2] >= constant.BUY_SCORE_RANK_1: - fscores_list[0].append(score) - elif score[2] >= constant.BUY_SCORE_RANK_0: - fscores_list[1].append(score) - else: - fscores_list[2].append(score) + plate_info = kpl_block_info_dict.get(code) + if plate_info: + kpl_block_info_dict[code] = plate_info + plate_info.sort(key=lambda x: x[2]) + plate_info.reverse() + kpl_code_info["plate"] = [(k[0], k[1], k[2], format_plate_output(k[1])[1]) for k in plate_info] - return fscores_list + code_records = KPLLimitUpDataRecordManager.get_latest_infos(code, 4, False)[:2] + if code_records: + code_records = [(format_plate_output(k[0]), k[1], [format_plate_output(k1) for k1 in k[2].split("銆�")]) for k in + code_records] + kpl_code_info["code_records"] = code_records + + if not KPLLimitUpDataRecordManager.total_datas: + KPLLimitUpDataRecordManager.load_total_datas() + for d in KPLLimitUpDataRecordManager.total_datas: + if d[3] == code: + # 鑾峰彇浠婃棩 + plates = d[6].split("銆�") + plates = [format_plate_output(p) for p in plates] + kpl_code_info["today"] = (format_plate_output(d[2]), d[1], plates) + break + return kpl_code_info -def __load_trade_record(code, total_datas): +def load_trade_record(code, total_datas, date=tool.get_now_date_str()): def format_l2_data(item): return f"{item['val']['time']}#{item['val']['num']}鎵�#{round(item['val']['num'] * float(item['val']['price']) * 100 / 10000, 1)}涓�" + + def load_cancel_watch_index(latest_cancel_watch_index_dict_): + for k in latest_cancel_watch_index_dict_: + records_new_data.append(latest_cancel_watch_index_dict_[k]) + latest_cancel_watch_index_dict_.clear() # 鑾峰彇鐐告澘淇℃伅 limit_up_info = code_price_manager.Buy1PriceManager().get_limit_up_info(code) break_time = limit_up_info[1] records = [] try: - records = log_export.load_trade_recod(code) + records = log_export.load_trade_recod(code, date=date) except: pass records_new = [] @@ -346,28 +394,80 @@ index = 0 if records: try: + latest_cancel_watch_index_dict = {} for record in records: time_ = record[0] type = record[1] data = record[2] if type == trade_record_log_util.TYPE_PLACE_ORDER: + # if data['kpl_blocks'] and (type(data['kpl_blocks'][0]) == list or type(data['kpl_blocks'][0]) == tuple): + # records_new_data.append((time_, "寮�鐩樺暒鎺ㄨ崘鍘熷洜", + # f"{'銆�'.join([k[1] for k in data['kpl_blocks']])}", + # None)) + # else: records_new_data.append((time_, "寮�鐩樺暒鎺ㄨ崘鍘熷洜", f"{'銆�'.join(data['kpl_blocks'])}", None)) + if "kpl_match_blocks" in data: + if data["kpl_match_blocks"]: + records_new_data.append((time_, "鍖归厤鍘熷洜", + f"{'銆�'.join(data['kpl_match_blocks'])}", + None)) + else: + records_new_data.append((time_, "鍖归厤鍘熷洜", + f"鐙嫍", + None)) extra_datas = [] - if data['big_num_indexes']: + if data.get('big_num_indexes'): big_num_desc = [] for i in data['big_num_indexes']: big_num_desc.append(format_l2_data(total_datas[i])) extra_datas.append(f"鍖呭惈澶у崟锛歿' & '.join(big_num_desc)}") - extra_datas.append(f"M鍊硷細{money_desc(data['m_val'])}") - extra_datas.append(f"瀹夊叏绗旀暟锛歿data['safe_count']}") + if data.get('m_val'): + extra_datas.append(f"M鍊硷細{money_desc(data['m_val'])}") + if data.get('safe_count'): + extra_datas.append(f"瀹夊叏绗旀暟锛歿data['safe_count']}") + extra_datas.append(f"鎬诲崠棰濓細{data.get('sell_info')}") - records_new_data.append((time_, "涓嬪崟", - f"銆恵format_l2_data(total_datas[data['buy_single_index']])}銆�-銆恵format_l2_data(total_datas[data['buy_exec_index']])}銆�", - data)) + records_new_data.append((time_, "", "-------------------------", [])) + mode = data.get('mode') + mode_desc = data.get('mode_desc') + if mode == OrderBeginPosInfo.MODE_ACTIVE: + records_new_data.append((time_, "绉瀬涓嬪崟", + mode_desc, + extra_datas)) + elif mode == OrderBeginPosInfo.MODE_FAST: + records_new_data.append((time_, "闂數涓嬪崟", + mode_desc, + extra_datas)) + elif mode == OrderBeginPosInfo.MODE_RADICAL: + records_new_data.append((time_, "鎵叆涓嬪崟", + mode_desc, + extra_datas)) + else: + records_new_data.append((time_, "甯歌涓嬪崟", + mode_desc, + extra_datas)) elif type == trade_record_log_util.TYPE_REAL_PLACE_ORDER_POSITION: - records_new_data.append((time_, "瀹為檯鎸傚崟浣�", f"銆恵format_l2_data(data['index'])}銆�", None)) + _datas = [] + MIN_MONEYS = [30000, 20000, 10000] + for min_money in MIN_MONEYS: + for i in range(data['index'] - 2, 0, -1): + if L2DataUtil.is_limit_up_price_buy(total_datas[i]['val']) and total_datas[i]['val'][ + 'num'] * float(total_datas[i]['val']['price']) >= min_money: + _datas.append(f"銆恵format_l2_data(total_datas[i])}銆�") + if len(_datas) >= 1: + break + if len(_datas) >= 1: + break + for i in range(data['index'], 0, -1): + if L2DataUtil.is_limit_up_price_buy(total_datas[i]['val']) and total_datas[i]['val'][ + 'num'] * float(total_datas[i]['val']['price']) >= 3000: + _datas.append(f"銆恵format_l2_data(total_datas[i])}銆�") + break + records_new_data.append( + (time_, "瀹為檯鎸傚崟浣�", "".join(_datas), [])) + elif type == trade_record_log_util.TYPE_CANCEL_WATCH_INDEXES: indexes = data['watch_indexes'] if indexes: @@ -378,30 +478,59 @@ indexes_data.append(format_l2_data(total_datas[index])) desc = f"銆恵format_l2_data(total_datas[indexes[0]])}銆�-銆恵format_l2_data(total_datas[indexes[-1]])}銆�" if cancel_type == trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_DOWN: - records_new_data.append((time_, "L鎾ゅ悗鍥婃嫭", desc, indexes_data)) + latest_cancel_watch_index_dict[cancel_type] = (time_, "L鎾ゅ悗鍥婃嫭", desc, indexes_data) elif cancel_type == trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_UP: - records_new_data.append((time_, "L鎾ゅ墠鍥婃嫭", desc, indexes_data)) + latest_cancel_watch_index_dict[cancel_type] = (time_, "L鎾ゅ墠鍥婃嫭", desc, indexes_data) elif cancel_type == trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_H: - records_new_data.append((time_, "H鎾ゅ泭鎷�", desc, indexes_data)) + latest_cancel_watch_index_dict[cancel_type] = (time_, "H鎾ゅ泭鎷�", desc, indexes_data) elif cancel_type == trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_D: - records_new_data.append((time_, "D鎾ゅ泭鎷�", desc, indexes_data)) + latest_cancel_watch_index_dict[cancel_type] = (time_, "D鎾ゅ泭鎷�", desc, indexes_data) elif cancel_type == trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_S: - records_new_data.append((time_, "S鎾ゅ泭鎷�", desc, indexes_data)) + latest_cancel_watch_index_dict[cancel_type] = (time_, "S鎾ゅ泭鎷�", desc, indexes_data) elif type == trade_record_log_util.TYPE_FORBIDDEN_BUY: - records_new_data.append((time_, "鍔犲叆榛戝悕鍗�", f"鍘熷洜锛歿data['msg']}", None)) + records_new_data.append((time_, "鍔犲叆榛戝悕鍗�", f"鍘熷洜锛歿data['msg']}", [])) elif type == trade_record_log_util.TYPE_CANT_PLACE_ORDER: - records_new_data.append((time_, "涓嶈兘涓嬪崟", f"鍘熷洜锛歿data['msg']}", None)) + records_new_data.append((time_, "涓嶈兘涓嬪崟", f"鍘熷洜锛歿data['msg']}", [])) elif type == trade_record_log_util.TYPE_CANCEL: - records_new_data.append((time_, "鎾ゅ崟", f"鍘熷洜锛歿data['msg']}", None)) + load_cancel_watch_index(latest_cancel_watch_index_dict) + records_new_data.append((time_, "鎾ゅ崟", f"鍘熷洜锛歿data['msg']}", [])) + elif type == trade_record_log_util.TYPE_ACTION: + records_new_data.append((time_, data['type'], f"{data['msg']}", [])) + load_cancel_watch_index(latest_cancel_watch_index_dict) + records_new_data.sort(key=lambda x: x[0]) if records_new_data: for d in records_new_data: - records_new.append(f"銆恵d[0]}銆�"+"{:<10}".format(d[1])+d[2]) - except: - pass - + records_new.append(f"銆恵d[0]}銆�" + "{:<10}".format(f'銆恵d[1]}銆�') + d[2]) + except Exception as e: + logging.exception(e) + records_new.reverse() + records_new_data.reverse() return break_time, records_new, records_new_data +# 杩斿洖鍐呭[锛堢被鍨�,buy_single_index,indexes锛塢 +def load_trade_record_cancel_watch_indexes(code, cancel_type=None, date=tool.get_now_date_str()): + fresults = [] + records = [] + try: + records = log_export.load_trade_recod(code, date=date) + except: + pass + if records: + for record in records: + time_ = record[0] + type = record[1] + data = record[2] + if type == trade_record_log_util.TYPE_CANCEL_WATCH_INDEXES: + indexes = data['watch_indexes'] + if indexes: + if cancel_type and cancel_type != data.get("cancel_type"): + continue + fresults.append((data.get("cancel_type"), data.get('buy_single_index'), indexes)) + return fresults + + if __name__ == '__main__': - ts = ("0", "1", "2", "3") - print(','.join(ts[:-1])) + code = '603616' + records = load_trade_record_cancel_watch_indexes(code, + trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_H) -- Gitblit v1.8.0