From 70b51a2636858fb8cfbf39d3764d88d07286d8ad Mon Sep 17 00:00:00 2001 From: admin <admin@example.com> Date: 星期二, 08 四月 2025 11:27:42 +0800 Subject: [PATCH] 增加并行数量 --- huaxin_client/l1_api_client.py | 27 +++++++++++++++++++++++---- 1 files changed, 23 insertions(+), 4 deletions(-) diff --git a/huaxin_client/l1_api_client.py b/huaxin_client/l1_api_client.py index 5c60f4f..9a929c5 100644 --- a/huaxin_client/l1_api_client.py +++ b/huaxin_client/l1_api_client.py @@ -22,6 +22,8 @@ class sampleSpi(qcvalueaddproapi.CQCValueAddProSpi): __result_cache = {} __temp_cache = {} + # 鎸囨暟鏁版嵁 + stock_index_data_dict = {} def __init__(self, t_tapi): qcvalueaddproapi.CQCValueAddProSpi.__init__(self) @@ -162,7 +164,8 @@ 璁㈤槄鑲$エ鎸囨暟琛屾儏 """ # 娌繁300 - self.m_api.SubscribeStockIndexData(qcvalueaddproapi.QCVD_EXD_SSE, "000300") # 娌繁300 + self.m_api.SubscribeStockIndexData(qcvalueaddproapi.QCVD_EXD_COMM, "000300") # 娌繁300 + self.m_api.SubscribeStockIndexData(qcvalueaddproapi.QCVD_EXD_SZSE, "000300") self.m_api.SubscribeStockIndexData(qcvalueaddproapi.QCVD_EXD_SSE, "000001") # 涓婅瘉 self.m_api.SubscribeStockIndexData(qcvalueaddproapi.QCVD_EXD_SZSE, "399006") # 鍒涗笟鏉挎寚鏁� self.m_api.SubscribeStockIndexData(qcvalueaddproapi.QCVD_EXD_SZSE, "399001") # 娣卞湷鎴愭寚 @@ -203,6 +206,7 @@ # 鎸囨暟鏁版嵁 try: data = { + "PreClosePrice":pStockIndexData.PreClosePrice, "LastPrice": pStockIndexData.LastPrice, "SecurityID": pStockIndexData.SecurityID, "UpdateTime": pStockIndexData.UpdateTime, @@ -210,10 +214,10 @@ "Turnover": pStockIndexData.Turnover, "LXLastPrice": pStockIndexData.LXLastPrice, } - logger_debug.info(f"鎸囨暟琛屾儏搴旂瓟锛歿data}") + self.stock_index_data_dict[data["SecurityID"]] = data + # logger_debug.info(f"鎸囨暟琛屾儏搴旂瓟锛歿data}") except Exception as e: logging.exception(e) - def ReqQryGGTEODPrices(self): QryField = qcvalueaddproapi.CQCVDQryGGTEODPricesField() @@ -300,11 +304,25 @@ pass -def run(request_queue: multiprocessing.Queue, response_queue: multiprocessing.Queue): +def __upload_datas(data_queue: multiprocessing.Queue): + # 1s涓婁紶涓�娆� + while True: + try: + if thespi.stock_index_data_dict: + data_queue.put_nowait(("stock_index_datas", thespi.stock_index_data_dict)) + except: + pass + finally: + time.sleep(1) + + +def run(request_queue: multiprocessing.Queue, response_queue: multiprocessing.Queue, + data_callback_queue: multiprocessing.Queue): """ 杩愯 @param request_queue: 璇锋眰闃熷垪 @param response_queue: 鍝嶅簲闃熷垪 + @param data_callback_queue: 鏁版嵁鍥炶皟 @return: """ global g_userid, g_passwd, g_address, g_port @@ -329,6 +347,7 @@ theapi.RegisterSpi(thespi) theapi.RegisterFront(g_address, g_port) threading.Thread(target=__read_request, args=(request_queue, response_queue,), daemon=True).start() + threading.Thread(target=__upload_datas, args=(data_callback_queue,), daemon=True).start() theapi.Run() -- Gitblit v1.8.0