| | |
| | | class sampleSpi(qcvalueaddproapi.CQCValueAddProSpi): |
| | | __result_cache = {} |
| | | __temp_cache = {} |
| | | # 指数数据 |
| | | stock_index_data_dict = {} |
| | | |
| | | def __init__(self, t_tapi): |
| | | qcvalueaddproapi.CQCValueAddProSpi.__init__(self) |
| | |
| | | 订阅股票指数行情 |
| | | """ |
| | | # 沪深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") # 深圳成指 |
| | |
| | | |
| | | 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() |
| | |
| | | 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 |
| | |
| | | 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() |
| | | |
| | | |