| | |
| | | from code_attribute import gpcode_manager |
| | | import l2.l2_data_util |
| | | from l2.huaxin import l2_huaxin_util |
| | | from l2.l2_transaction_data_manager import BigOrderDealManager |
| | | from log_module import log, log_export |
| | | from l2 import l2_data_source_util, l2_data_util |
| | | from log_module.log import logger_debug |
| | | from trade import deal_big_money_manager |
| | | from trade.buy_money_count_setting import BuyMoneyUtil |
| | | from utils import tool |
| | | |
| | | # 缓存L2数据,格式:{"日期":{数据}} |
| | |
| | | if datas[i]["index"] == end_index: |
| | | datas = datas[:i] |
| | | break |
| | | # 成交的大单信息[(买单号,总股数,总成交额,成交开始时间,成交结束时间)] |
| | | deal_big_buy_order_list = copy.deepcopy(BigOrderDealManager().get_total_buy_data_list(code)) |
| | | deal_big_buy_order_no_dict = {} |
| | | if deal_big_buy_order_list: |
| | | for d in deal_big_buy_order_list: |
| | | deal_big_buy_order_no_dict[d[0]] = d |
| | | |
| | | fdatas = export_l2_data(code, datas, process_indexs, trade_indexs, real_position_indexes, deal_list_dict, sell_nos, |
| | | active_sell_set, cancel_reasons) |
| | | active_sell_set, cancel_reasons, deal_big_buy_order_no_dict) |
| | | return fdatas |
| | | |
| | | |
| | |
| | | |
| | | |
| | | def export_l2_data(code, datas, process_indexs, trade_indexs, real_position_indexes, deal_list_dict, sell_nos, |
| | | active_sell_nos, cancel_reasons): |
| | | active_sell_nos, cancel_reasons, deal_big_buy_order_no_dict): |
| | | def find_process_index(index): |
| | | for i in range(0, len(process_indexs)): |
| | | if process_indexs[i][0] <= index <= process_indexs[i][1]: |
| | |
| | | # 最新的一条数据 |
| | | latest_data = datas[-1] |
| | | latest_time_str_with_ms = l2.l2_data_util.L2DataUtil.get_time_with_ms(latest_data["val"]) |
| | | |
| | | |
| | | # 数据预处理 |
| | | num_operate_map = {} |
| | |
| | | fdatas = [] |
| | | # 数据太多就需要过滤掉小金额 |
| | | is_data_too_large = len(datas) > 20000 |
| | | |
| | | limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) |
| | | if limit_up_price: |
| | | # 需要订阅的特殊的量 |
| | | special_volumes = BuyMoneyUtil.get_possible_buy_volumes(limit_up_price) |
| | | special_volumes = [x//100 for x in special_volumes] |
| | | else: |
| | | special_volumes = [] |
| | | |
| | | for data in datas: |
| | | index += 1 |
| | | if is_data_too_large and data['val']['num'] * float(data['val']['price']) < 5000: |
| | | if data["index"] not in real_position_indexes: |
| | | # 小单 |
| | | if data["index"] not in real_position_indexes and data['val']['num'] not in special_volumes: |
| | | continue |
| | | |
| | | # 先移除 |
| | | if data['val']['orderNo'] in active_sell_nos: |
| | | # 过滤主动卖 |
| | | continue |
| | | |
| | | # 移除成交大单在L2中已有的订单 |
| | | if l2.l2_data_util.L2DataUtil.is_limit_up_price_buy(data["val"]): |
| | | if int(data['val']['orderNo']) in deal_big_buy_order_no_dict: |
| | | deal_big_buy_order_no_dict.pop(int(data['val']['orderNo'])) |
| | | |
| | | trade_info = find_trade_index(data["index"]) |
| | | if not trade_info: |
| | |
| | | deal_info = deal_list_dict.get(str(data["val"].get("orderNo"))) |
| | | if deal_info and len(deal_info) >= 5: |
| | | # 成交时间不能比当前索引时间大 |
| | | if tool.trade_time_sub_with_ms(cancel_info , latest_time_str_with_ms) <= 0: |
| | | cancel_info = l2_huaxin_util.convert_time(deal_info[4], |
| | | with_ms=True) |
| | | cancel_info = l2_huaxin_util.convert_time(deal_info[4], |
| | | with_ms=True) |
| | | if tool.trade_time_sub_with_ms(cancel_info, latest_time_str_with_ms) > 0: |
| | | cancel_info = None |
| | | format_data.append(cancel_info) |
| | | cancel_order_info = None |
| | | if trade_info: |
| | |
| | | format_data.append(cancel_order_info) |
| | | format_data.append(data["val"].get("orderNo")) |
| | | fdatas.append((style_int, trade_info, format_data)) |
| | | |
| | | if tool.is_sh_code(code) and deal_big_buy_order_no_dict: |
| | | # 上证,有主动成交的大单 |
| | | active_deal_list = [deal_big_buy_order_no_dict[order_no] for order_no in deal_big_buy_order_no_dict] |
| | | active_deal_list.sort(key=lambda x: x[3]) |
| | | for i in range(len(active_deal_list)): |
| | | d = active_deal_list[i] |
| | | format_data = [0] |
| | | format_data.append(l2_huaxin_util.convert_time(d[3], with_ms=True)) |
| | | format_data.append('') |
| | | format_data.append(f"{round(d[2] / 10000, 1)}万") |
| | | format_data.append(round(d[2] / d[1], 2)) |
| | | format_data.append(d[1] // 100) |
| | | format_data.append('主动买') |
| | | format_data.append(1) |
| | | format_data.append(l2_huaxin_util.convert_time(d[4], with_ms=True)) |
| | | format_data.append('') |
| | | format_data.append(d[0]) |
| | | fdatas.insert(i, (0, None, format_data)) |
| | | logger_debug.info("循环组装数据完成") |
| | | return fdatas |
| | | |