Administrator
2024-04-12 59a4f0a14ddb580739cc2f89b8a6c034abb17d91
逐笔成交触发买信号
2个文件已修改
1个文件已添加
99 ■■■■■ 已修改文件
l2/l2_data_manager_new.py 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_transaction_data_manager.py 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/place_order_single_data_manager.py 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py
@@ -8,6 +8,7 @@
from l2.huaxin import l2_huaxin_util, huaxin_delegate_postion_manager
from l2.l2_sell_manager import L2MarketSellManager, L2LimitUpSellManager
from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager
from l2.place_order_single_data_manager import L2TradeSingleManager
from l2.transaction_progress import TradeBuyQueue
from log_module import async_log_util, log_export
from third_data import kpl_data_manager, block_info
@@ -394,6 +395,17 @@
                                pass
                            async_log_util.info(logger_l2_process, f"code:{code} 获取到下单真实位置:{place_order_index}")
                    # 处理涨停卖与涨停卖撤
                    try:
                        for d in add_datas:
                            if L2DataUtil.is_limit_up_price_sell(d['val']):
                                L2TradeSingleManager.add_l2_delegate_limit_up_sell(code,d)
                            elif  L2DataUtil.is_limit_up_price_sell_cancel(d['val']):
                                L2TradeSingleManager.add_l2_delegate_limit_up_sell_cancel(code,d['val']['orderNo'])
                    except Exception as e:
                        logger_debug.exception(e)
                except:
                    async_log_util.error(logger_l2_error, f"{code} 处理真实下单位置出错")
            # 第1条数据是否为09:30:00
l2/l2_transaction_data_manager.py
@@ -8,6 +8,7 @@
from l2 import l2_log
from l2.huaxin import l2_huaxin_util
from l2.l2_data_util import local_today_sellno_map, local_today_datas
from l2.place_order_single_data_manager import L2TradeSingleManager
from log_module import async_log_util
from log_module.log import hx_logger_l2_transaction_desc, hx_logger_l2_transaction_sell_order
@@ -142,8 +143,8 @@
            # 获取当前是否为主动买
            _is_active_sell = is_active_sell(d[7], d[6])
            if not _is_active_sell and d[1] == limit_up_price:
                # TODO 被动涨停卖,这个卖的订单是否在最近的涨停卖列表中
                pass
                # 被动涨停卖,这个卖的订单是否在最近的涨停卖列表中
                L2TradeSingleManager.process_passive_limit_up_sell_data(d)
            if not _is_active_sell:
                continue
l2/place_order_single_data_manager.py
New file
@@ -0,0 +1,82 @@
"""
下单信号管理
"""
from l2 import l2_data_util, l2_log
from log_module.log import logger_l2_trade_buy, logger_debug
class L2TradeSingleManager:
    """
    L2逐笔成交数据信号管理
    """
    __latest_sell_data = {}
    __latest_limit_up_sell_list_dict = {}
    __latest_limit_up_sell_order_no_index_dict = {}
    @classmethod
    def add_l2_delegate_limit_up_sell(cls, code, data):
        """
        添加涨停卖单数据,当前不是涨停成交时才加
        @param code:
        @param data:
        @return:
        """
        l2_log.info(code, logger_l2_trade_buy,f"涨停卖数据:{data['val']['orderNo']}")
        if code not in  cls.__latest_limit_up_sell_list_dict:
            cls.__latest_limit_up_sell_list_dict[code] = []
        cls.__latest_limit_up_sell_list_dict[code].append(data)
        if code not in cls.__latest_limit_up_sell_order_no_index_dict:
            cls.__latest_limit_up_sell_order_no_index_dict[code] = {}
        cls.__latest_limit_up_sell_order_no_index_dict[code][data['val']['orderNo']] = len(cls.__latest_limit_up_sell_list_dict[code]) - 1
    @classmethod
    def add_l2_delegate_limit_up_sell_cancel(cls, code, order_no):
        """
        涨停卖撤
        @param code:
        @param order_no:
        @return:
        """
        if code not in cls.__latest_limit_up_sell_order_no_index_dict:
            return
        index = cls.__latest_limit_up_sell_order_no_index_dict[code].get(order_no)
        if index is None:
            return
        cls.__latest_limit_up_sell_order_no_index_dict[code].pop(order_no)
        del cls.__latest_limit_up_sell_list_dict[code][index]
    @classmethod
    def process_passive_limit_up_sell_data(cls, data):
        """
        添加涨停被动卖成交数据
        @param data: 数据格式:(data['SecurityID'], data['TradePrice'], data['TradeVolume'],
        #           data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'],
        #           data['SellNo'], data['ExecType'])
        @return:
        """
        try:
            # 需要判断当前单是否已经成交完成
            code = data[0]
            sell_no = data[7]
            if code not in cls.__latest_sell_data:
                cls.__latest_sell_data[code] = [sell_no, data[2]]
            else:
                if cls.__latest_sell_data[code][0] == sell_no:
                    cls.__latest_sell_data[code][1] += data[2]
                else:
                    cls.__latest_sell_data[code] = [sell_no, data[2]]
            # 判断是否是最后一笔卖单
            # 判断这个订单号是否成交完
            sell_list = cls.__latest_limit_up_sell_list_dict.get(code)
            if not sell_list:
                return
            sell_info = sell_list[-1]
            if str(sell_no) == sell_info['val']['orderNo'] and sell_info["val"]["num"] == cls.__latest_sell_data[code][1]//100:
                # 成交完成
                l2_log.info(code, logger_l2_trade_buy, f"找到最近的被动涨停卖单数据:{data['val']['orderNo']}, 可以触发下单")
        except Exception as e:
            logger_debug.exception(e)