| | |
| | | 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 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 |
| | | |
| | | base_output_content = {} |
| | |
| | | |
| | | |
| | | 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: |
| | |
| | | code_extra_infos.append("暂不买") |
| | | params["code"] = code |
| | | params["code_name"] = f"{gpcode_manager.get_code_name(code)} {code} ({','.join(code_extra_infos)})" |
| | | |
| | | 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, with_info=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() |
| | | |
| | | ###############################下单信息############################### |
| | |
| | | |
| | | # 获取买入意愿 |
| | | __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), |
| | | None) |
| | | # 是否可以买入的信息 |
| | | try: |
| | | can_buy_info = l2.l2_data_manager_new.L2TradeDataProcessor.can_buy_first(code, limit_up_price) |
| | | 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 = code_volumn_manager.get_volume_refer_date(code) |
| | | 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), |
| | | None) |
| | | if -1 < __L2PlaceOrderParamsManager.score_index < 3: |
| | |
| | | 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) |
| | |
| | | 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() |
| | | |
| | | ##############################主动买,被动买################################## |
| | |
| | | # {"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() |
| | | |
| | | ##############################开盘啦相关信息################################## |
| | |
| | | "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() |
| | | |
| | | # 获取代码的历史涨停数据,(涨停原因,日期,板块) |
| | |
| | | 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: |
| | |
| | | params["kpl_code_info"]["today"] = (format_plate_output(d[2]), d[1], plates) |
| | | break |
| | | |
| | | log.logger_debug.info(f"获取代码的历史涨停数据耗时:{time.time() - __start_time}") |
| | | # log.logger_debug.info(f"获取代码的历史涨停数据耗时:{time.time() - __start_time}") |
| | | __start_time = time.time() |
| | | return params |
| | | |
| | | |
| | | def __load_trade_record(code, total_datas): |
| | | # 获取开盘啦板块信息 |
| | | 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: |
| | | 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] |
| | | |
| | | 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, 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)}万" |
| | | |
| | |
| | | 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 = [] |
| | |
| | | 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_, "", "-------------------------", [])) |
| | | mode = data.get('mode') |
| | | if mode == OrderBeginPosInfo.MODE_FAST: |
| | | 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_, "闪电下单", |
| | | f"【{format_l2_data(total_datas[data['buy_single_index']])}】-【{format_l2_data(total_datas[data['buy_exec_index']])}】", |
| | | mode_desc, |
| | | extra_datas)) |
| | | elif mode == OrderBeginPosInfo.MODE_RADICAL: |
| | | records_new_data.append((time_, "扫入下单", |
| | | mode_desc, |
| | | extra_datas)) |
| | | else: |
| | | records_new_data.append((time_, "下单", |
| | | f"【{format_l2_data(total_datas[data['buy_single_index']])}】-【{format_l2_data(total_datas[data['buy_exec_index']])}】", |
| | | records_new_data.append((time_, "常规下单", |
| | | mode_desc, |
| | | extra_datas)) |
| | | elif type == trade_record_log_util.TYPE_REAL_PLACE_ORDER_POSITION: |
| | | _datas = [] |
| | |
| | | elif type == trade_record_log_util.TYPE_CANCEL: |
| | | 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: |
| | |
| | | |
| | | |
| | | # 返回内容[(类型,buy_single_index,indexes)] |
| | | def load_trade_record_cancel_watch_indexes(code, cancel_type=None): |
| | | 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) |
| | | records = log_export.load_trade_recod(code, date=date) |
| | | except: |
| | | pass |
| | | if records: |
| | |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | code = '600713' |
| | | l2_data_util.load_l2_data(code) |
| | | fresults = __load_trade_record(code, l2_data_util.local_today_datas.get(code)) |
| | | print(fresults) |
| | | code = '603616' |
| | | records = load_trade_record_cancel_watch_indexes(code, |
| | | trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_H) |