From 41bc8133fe7e7bb64e44ca6a09489bb21acf5029 Mon Sep 17 00:00:00 2001 From: admin <admin@example.com> Date: 星期五, 29 八月 2025 14:07:26 +0800 Subject: [PATCH] bug修复 --- huaxin_client/l1_api_client.py | 46 ++++++++++++++++++++++++++++++++++------------ 1 files changed, 34 insertions(+), 12 deletions(-) diff --git a/huaxin_client/l1_api_client.py b/huaxin_client/l1_api_client.py index e0b0af0..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") # 娣卞湷鎴愭寚 @@ -201,16 +204,20 @@ def OnRtnStockIndexData(self, pStockIndexData): # 鎸囨暟鏁版嵁 - data = { - "LastPrice": pStockIndexData["LastPrice"], - "SecurityID": pStockIndexData["SecurityID"], - "UpdateTime": pStockIndexData["UpdateTime"], - "Volume": pStockIndexData["Volume"], - "Turnover": pStockIndexData["Turnover"], - "LXLastPrice": pStockIndexData["LXLastPrice"] - } - logger_debug.info(f"鎸囨暟琛屾儏搴旂瓟锛歿data}") - + try: + data = { + "PreClosePrice":pStockIndexData.PreClosePrice, + "LastPrice": pStockIndexData.LastPrice, + "SecurityID": pStockIndexData.SecurityID, + "UpdateTime": pStockIndexData.UpdateTime, + "Volume": pStockIndexData.Volume, + "Turnover": pStockIndexData.Turnover, + "LXLastPrice": pStockIndexData.LXLastPrice, + } + 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() @@ -297,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 @@ -326,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