Administrator
2024-06-14 1471480f5307d9f75b6e87e246cc14c131fb4639
L2订阅接口更新
8个文件已修改
150 ■■■■■ 已修改文件
_lev2mdapi.cp37-win32.pyd 补丁 | 查看 | 原始文档 | blame | 历史
_lev2mdapi.cp37-win_amd64.pyd 补丁 | 查看 | 原始文档 | blame | 历史
_lev2mdapi.cpython-37m-x86_64-linux-gnu.so 补丁 | 查看 | 原始文档 | blame | 历史
cancel_strategy/s_l_h_cancel_strategy.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
code_attribute/code_volumn_manager.py 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/l2_client.py 110 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lev2mdapi.py 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
_lev2mdapi.cp37-win32.pyd
Binary files differ
_lev2mdapi.cp37-win_amd64.pyd
Binary files differ
_lev2mdapi.cpython-37m-x86_64-linux-gnu.so
Binary files differ
cancel_strategy/s_l_h_cancel_strategy.py
@@ -1485,10 +1485,10 @@
                    watch_indexes_info = self.__get_watch_indexes_cache(code)
                    if watch_indexes_info and watch_indexes_info[2]:
                        # 没有囊括
                        watch_indexes|=set(watch_indexes_info[2])
                        watch_indexes |= set(watch_indexes_info[2])
                        self.__set_watch_indexes(code, watch_indexes_info[0], watch_indexes_info[1], watch_indexes)
        except Exception as e:
            l2_log.l_cancel_debug(code,"L后后半段计算出错:{}", str(e))
            l2_log.l_cancel_debug(code, "L后后半段计算出错:{}", str(e))
        return can_cancel, cancel_data, extra_msg
code_attribute/code_volumn_manager.py
@@ -91,6 +91,8 @@
def get_volume_rate(code, total_sell_volume=0, with_info=False):
    today = get_today_volumn(code)
    max60, yesterday = get_histry_volumn(code)
    if today is None:
        today = 0
    if today is None or max60 is None or yesterday is None:
        raise Exception(f"获取量失败:{code}")
    rate = round((int(today) + total_sell_volume) / max(int(max60[0]), int(yesterday)), 2)
huaxin_client/l2_client.py
@@ -53,6 +53,8 @@
set_codes_data_queue = queue.Queue()
market_code_dict = {}
ENABLE_NGST = True
class Lev2MdSpi(lev2mdapi.CTORATstpLev2MdSpi):
    latest_codes_set = set()
@@ -91,10 +93,14 @@
        logger_local_huaxin_l2_subscript.info(f"取消订阅上证:{sh}")
        logger_local_huaxin_l2_subscript.info(f"取消订阅深证:{sz}")
        if sh:
            # 取消订阅逐笔委托
            self.__api.UnSubscribeOrderDetail(sh, lev2mdapi.TORA_TSTP_EXD_SSE)
            # 取消订阅逐笔成交
            self.__api.UnSubscribeTransaction(sh, lev2mdapi.TORA_TSTP_EXD_SSE)
            if ENABLE_NGST:
                result = self.__api.UnSubscribeNGTSTick(sh, lev2mdapi.TORA_TSTP_EXD_SSE)
                logger_local_huaxin_l2_subscript.info(f"逐笔NGTS订阅结果sh:{result}")
            else:
                # 取消订阅逐笔委托
                self.__api.UnSubscribeOrderDetail(sh, lev2mdapi.TORA_TSTP_EXD_SSE)
                # 取消订阅逐笔成交
                self.__api.UnSubscribeTransaction(sh, lev2mdapi.TORA_TSTP_EXD_SSE)
            self.__api.UnSubscribeMarketData(sh, lev2mdapi.TORA_TSTP_EXD_SSE)
        if sz:
            self.__api.UnSubscribeOrderDetail(sz, lev2mdapi.TORA_TSTP_EXD_SZSE)
@@ -106,12 +112,16 @@
        logger_local_huaxin_l2_subscript.info(f"订阅上证:{sh}")
        logger_local_huaxin_l2_subscript.info(f"订阅深证:{sz}")
        if sh:
            # 订阅逐笔委托
            result = self.__api.SubscribeOrderDetail(sh, lev2mdapi.TORA_TSTP_EXD_SSE)
            logger_local_huaxin_l2_subscript.info(f"逐笔委托订阅结果sh:{result}")
            # 订阅逐笔成交
            result = self.__api.SubscribeTransaction(sh, lev2mdapi.TORA_TSTP_EXD_SSE)
            logger_local_huaxin_l2_subscript.info(f"逐笔成交订阅结果sh:{result}")
            if ENABLE_NGST:
                result = self.__api.SubscribeNGTSTick(sh, lev2mdapi.TORA_TSTP_EXD_SSE)
                logger_local_huaxin_l2_subscript.info(f"逐笔NGTS订阅结果sh:{result}")
            else:
                # 订阅逐笔委托
                result = self.__api.SubscribeOrderDetail(sh, lev2mdapi.TORA_TSTP_EXD_SSE)
                logger_local_huaxin_l2_subscript.info(f"逐笔委托订阅结果sh:{result}")
                # 订阅逐笔成交
                result = self.__api.SubscribeTransaction(sh, lev2mdapi.TORA_TSTP_EXD_SSE)
                logger_local_huaxin_l2_subscript.info(f"逐笔成交订阅结果sh:{result}")
            result = self.__api.SubscribeMarketData(sh, lev2mdapi.TORA_TSTP_EXD_SSE)
            logger_local_huaxin_l2_subscript.info(f"市场订阅结果sh:{result}")
@@ -149,7 +159,7 @@
                self.l2_data_upload_manager.distribute_upload_queue(c)
                l2_data_manager.add_target_code(c)
        except Exception as e:
            #TODO 清除原来还没释放掉的数据
            # TODO 清除原来还没释放掉的数据
            logger_system.error(f"L2代码分配上传队列出错:{str(e)}")
            logger_system.exception(e)
        self.__subscribe(add_codes)
@@ -246,6 +256,26 @@
        except Exception as e:
            logging.exception(e)
    def OnRspSubNGTSTick(self, pSpecificSecurity, pRspInfo, nRequestID, bIsLast):
        async_log_util.info(logger_local_huaxin_l2_subscript,
                            f"订阅结果:{pSpecificSecurity['SecurityID']} {pRspInfo['ErrorID']} {pRspInfo['ErrorMsg']}")
        if pRspInfo["ErrorID"] == 0:
            print("订阅成功")
            self.subscripted_codes.add(pSpecificSecurity['SecurityID'])
        if bIsLast == 1:
            print("订阅响应结束", self.subscripted_codes)
            l2_data_manager.add_subscript_codes(self.subscripted_codes)
    def OnRspUnSubNGTSTick(self, pSpecificSecurity, pRspInfo, nRequestID, bIsLast):
        try:
            code = pSpecificSecurity['SecurityID']
            self.subscripted_codes.discard(code)
            if bIsLast == 1:
                print("取消订阅响应结束", self.subscripted_codes)
                l2_data_manager.add_subscript_codes(self.subscripted_codes)
        except Exception as e:
            logging.exception(e)
    def OnRspSubBondMarketData(self, pSpecificSecurity, pRspInfo, nRequestID, bIsLast):
        print("OnRspSubBondMarketData")
@@ -260,10 +290,6 @@
    def OnRspSubXTSTick(self, pSpecificSecurity, pRspInfo, nRequestID, bIsLast):
        print("OnRspSubXTSTick")
    # 4.0.5版本接口
    def OnRspSubNGTSTick(self, pSpecificSecurity, pRspInfo, nRequestID, bIsLast):
        print("OnRspSubNGTSTick")
    def OnRtnMarketData(self, pDepthMarketData, FirstLevelBuyNum, FirstLevelBuyOrderVolumes, FirstLevelSellNum,
                        FirstLevelSellOrderVolumes):
@@ -345,28 +371,6 @@
            self.l2_data_upload_manager.add_transaction_detail(item)
    def OnRtnOrderDetail(self, pOrderDetail):
        # can_listen = False
        # code = str(pOrderDetail['SecurityID'])
        # start_time = 0
        # if code in self.special_code_volume_for_order_dict:
        #     start_time = time.time()
        #     if self.special_code_volume_for_order_dict[code][0] == pOrderDetail[
        #         'Volume'] or constant.SHADOW_ORDER_VOLUME == pOrderDetail['Volume']:
        #         # 监控目标订单与影子订单
        #         if self.special_code_volume_for_order_dict[code][1] > time.time():
        #             # 特殊量监听
        #             can_listen = True
        #         else:
        #             self.special_code_volume_for_order_dict.pop(code)
        # if not can_listen:
        #     min_volume, limit_up_price = self.codes_volume_and_price_dict.get(code)
        #     if min_volume is None:
        #         # 默认筛选50w
        #         if pOrderDetail['Price'] * pOrderDetail['Volume'] < 500000:
        #             return
        #     elif pOrderDetail['Volume'] < min_volume:
        #         return
        # 输出逐笔委托数据
        # 上证OrderStatus=b"D"表示撤单
        item = {"SecurityID": pOrderDetail['SecurityID'], "Price": pOrderDetail['Price'],
                "Volume": pOrderDetail['Volume'],
@@ -376,6 +380,38 @@
                "OrderStatus": pOrderDetail['OrderStatus'].decode()}
        self.l2_data_upload_manager.add_l2_order_detail(item, 0)
    def OnRtnNGTSTick(self, pTick):
        """
        上证股票的逐笔委托与成交
        @param pTick:
        @return:
        """
        try:
            if pTick['TickType'] == b'T':
                # 成交
                item = {"SecurityID": pTick['SecurityID'], "TradePrice": pTick['Price'],
                        "TradeVolume": pTick['Volume'],
                        "OrderTime": pTick['TickTime'], "MainSeq": pTick['MainSeq'],
                        "SubSeq": pTick['SubSeq'], "BuyNo": pTick['BuyNo'],
                        "SellNo": pTick['SellNo'],
                        "ExecType": '1'}
                self.l2_data_upload_manager.add_transaction_detail(item)
            elif pTick['TickType'] == b'A' or pTick['TickType'] == b'D':
                # 撤单
                item = {"SecurityID": pTick['SecurityID'], "Price": pTick['Price'],
                        "Volume": pTick['Volume'],
                        "Side": pTick['Side'].decode(), "OrderType": pTick['TickType'].decode(),
                        "OrderTime": pTick['TickTime'], "MainSeq": pTick['MainSeq'],
                        "SubSeq": pTick['SubSeq'], "OrderNO": '',
                        "OrderStatus": pTick['TickType'].decode()}
                if pTick['Side'] == b'1':
                    item['OrderNO'] = pTick['BuyNo']
                elif pTick['Side'] == b'2':
                    item['OrderNO'] = pTick['SellNo']
                self.l2_data_upload_manager.add_l2_order_detail(item, 0)
        except Exception as e:
            logger_local_huaxin_l2_subscript.exception(e)
    def OnRtnBondMarketData(self, pDepthMarketData, FirstLevelBuyNum, FirstLevelBuyOrderVolumes, FirstLevelSellNum,
                            FirstLevelSellOrderVolumes):
        # 输出行情快照数据
l2/l2_data_manager_new.py
@@ -954,6 +954,9 @@
    @classmethod
    def __can_buy_first(cls, code):
        if code.find("60") == 0:
            return False, True, f"上证暂不交易"
        if not cls.__TradeStateManager.is_can_buy_cache():
            return False, True, f"今日已禁止交易"
@@ -1064,13 +1067,15 @@
                    limit_up_price = round(float(gpcode_manager.get_limit_up_price(code)), 2)
                    # 从成交进度位到截至位置计算大单
                    min_money = l2_data_util.get_big_money_val(limit_up_price)
                    left_count, left_money = cancel_buy_strategy.L2DataComputeUtil.compute_left_buy_order(code, trade_index, total_data[-1]["index"],
                                                                                      limit_up_price,
                                                                                      min_money=min_money)
                    left_count, left_money = cancel_buy_strategy.L2DataComputeUtil.compute_left_buy_order(code,
                                                                                                          trade_index,
                                                                                                          total_data[
                                                                                                              -1][
                                                                                                              "index"],
                                                                                                          limit_up_price,
                                                                                                          min_money=min_money)
                    if left_count < 1:
                        return False, False, f"没有已挂或者成交的大单"
        # 暂时注释想买单功能
        if not cls.__WantBuyCodesManager.is_in_cache(code):
@@ -1509,7 +1514,8 @@
        threshold_money = threshold_money_new
        order_begin_pos.threshold_money = threshold_money
        l2_log.debug(code, "范围:{}-{} m值-{} 量比:{} rebegin_buy_pos:{} clear_buy_single:{}", compute_start_index, compute_end_index,
        l2_log.debug(code, "范围:{}-{} m值-{} 量比:{} rebegin_buy_pos:{} clear_buy_single:{}", compute_start_index,
                     compute_end_index,
                     threshold_money, cls.volume_rate_info[code][0],
                     rebegin_buy_pos, clear_buy_single)
@@ -1555,13 +1561,14 @@
            # 记录买入信号位置
            if not clear_buy_single:
                # 没有清除信号位置就保存下单位置信息
                cls.__save_order_begin_data(code, OrderBeginPosInfo(buy_single_index=buy_single_index, buy_exec_index=-1,
                                                                    buy_compute_index=compute_end_index, num=buy_nums,
                                                                    count=buy_count,
                                                                    mode_desc=order_begin_pos.mode_desc,
                                                                    max_num_set=max_num_set_new, mode=order_begin_pos.mode,
                                                                    sell_info=order_begin_pos.sell_info,
                                                                    threshold_money=threshold_money))
                cls.__save_order_begin_data(code,
                                            OrderBeginPosInfo(buy_single_index=buy_single_index, buy_exec_index=-1,
                                                              buy_compute_index=compute_end_index, num=buy_nums,
                                                              count=buy_count,
                                                              mode_desc=order_begin_pos.mode_desc,
                                                              max_num_set=max_num_set_new, mode=order_begin_pos.mode,
                                                              sell_info=order_begin_pos.sell_info,
                                                              threshold_money=threshold_money))
                # 记录没下单原因
                async_log_util.info(logger_l2_not_buy_reasons, f"{code}#{not_buy_msg}")
                _start_time = t.time()
lev2mdapi.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 4.0.2
#