Administrator
2024-08-27 97ec997e855faee25f8f2e35734f87afa5af6f95
9:25之前的订阅数据处理
3个文件已修改
62 ■■■■■ 已修改文件
huaxin_client/l1_client.py 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/tool.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
servers/huaxin_trade_api_server.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/l1_client.py
@@ -123,7 +123,22 @@
            return
        close_price = round(pMarketDataField.UpperLimitPrice / out_tool.get_limit_up_rate(pMarketDataField.SecurityID),
                            2)
        rate = round((pMarketDataField.LastPrice - close_price) * 100 / close_price, 2)
        try:
            # 测试L1数据
            if pMarketDataField.SecurityID == '600636' or pMarketDataField.SecurityID == '002430' or pMarketDataField.SecurityID == '300466':
                d = {"SecurityID": pMarketDataField.SecurityID, "PreClosePrice": pMarketDataField.PreClosePrice,
                     "LastPrice": pMarketDataField.LastPrice, "BidPrice1": pMarketDataField.BidPrice1,
                     "BidVolume1": pMarketDataField.BidVolume1, "AskVolume1": pMarketDataField.AskVolume1,
                     "AskPrice1": pMarketDataField.AskPrice1, "UpperLimitPrice": pMarketDataField.UpperLimitPrice,
                     "UpdateTime": pMarketDataField.UpdateTime, "UpdateMillisec": pMarketDataField.UpdateMillisec}
                logger_local_huaxin_l1.info(f"L1数据:{d}")
        except:
            pass
        lastPrice = pMarketDataField.LastPrice
        if pMarketDataField.BidPrice1:
            lastPrice = pMarketDataField.BidPrice1
        rate = round((lastPrice - close_price) * 100 / close_price, 2)
        if out_tool.get_limit_up_rate(pMarketDataField.SecurityID) > 1.1001:
            # 涨停板20%以上的打折
            rate = rate / 2
@@ -165,16 +180,9 @@
        logger_local_huaxin_l1.info(f"({request_id})新增加订阅的代码:{add_codes}")
is_re_subscript = False
# 重新订阅代码
def re_subscript(spi: MdSpi):
    try:
        global is_re_subscript
        if is_re_subscript:
            return
        is_re_subscript = True
        codes_sh, codes_sz = l1_subscript_codes_manager.request_l1_subscript_target_codes()
        if len(codes_sh) > 100 and len(codes_sz) > 100:
            logger_local_huaxin_l1.info(f"重新订阅 sh-{len(codes_sh)} sz-{len(codes_sz)}")
@@ -201,6 +209,26 @@
            pass
        finally:
            time.sleep(1)
def __run_subscript_task(spi):
    """
    运行订阅任务,在9:19到9:29之间开始订阅
    @return:
    """
    is_re_subscript = False
    while True:
        try:
            # 判断是否需要重新订阅
            if tool.is_pre_trade_time():
                re_subscript(spi)
                is_re_subscript = True
            if is_re_subscript:
                break
        except:
            pass
        finally:
            time.sleep(3)
def run(queue_l1_w_strategy_r, queue_l1_r_strategy_w):
@@ -254,6 +282,9 @@
    #     "002292", 8.06, 9.96, 969500 * 100, time.time())
    threading.Thread(target=__read_from_strategy, args=(queue_l1_r_strategy_w,), daemon=True).start()
    threading.Thread(target=__run_subscript_task, args=(spi,), daemon=True).start()
    # 等待程序结束
    while True:
        print("数量", len(level1_data_dict))
@@ -294,15 +325,6 @@
            logging.exception(e)
        finally:
            time.sleep(3)
            try:
                # 判断是否需要重新订阅
                if tool.is_pre_trade_time():
                    re_subscript(spi)
                else:
                    global is_re_subscript
                    is_re_subscript = False
            except:
                pass
    # 释放接口对象
    api.Release()
huaxin_client/tool.py
@@ -18,7 +18,7 @@
# 是否为交易前时间:9:25:00到9:30:00
def is_pre_trade_time():
    relative_timestamp = time.time() % (24 * 60 * 60) + 8 * 60 * 60
    start1 = 60 * 60 * 9 + 24 * 60
    start1 = 60 * 60 * 9 + 19 * 60
    end1 = 60 * 60 * 9 + 29 * 60
    if start1 < relative_timestamp < end1:
        return True
servers/huaxin_trade_api_server.py
@@ -450,8 +450,8 @@
                    root_data = {"type": ClientSocketManager.CLIENT_TYPE_CMD_L2,
                                 "data": datas}
                    queue_other_w_l2_r.put_nowait(json.dumps(root_data))
                    # 如果在9:24-9:29 需要加载板块
                    if int("092400") < int(tool.get_now_time_str().replace(":", "")) < int("092900"):
                    # 如果在9:25-9:29 需要加载板块
                    if int("092500") < int(tool.get_now_time_str().replace(":", "")) < int("092900"):
                        for d in datas:
                            threading.Thread(target=lambda: KPLCodeJXBlockManager().load_jx_blocks(d[0],
                                                                                                   gpcode_manager.get_price(