| | |
| | | |
| | | from huaxin_client import l1_api_client |
| | | from log_module.log import logger_debug |
| | | from strategy import data_cache |
| | | from utils import tool |
| | | |
| | | __response_data = {} |
| | |
| | | return None |
| | | |
| | | |
| | | def __read_callback_data(data_callback_queue: multiprocessing.Queue): |
| | | """ |
| | | 读取数据回调 |
| | | :param data_callback_queue: |
| | | :return: |
| | | """ |
| | | while True: |
| | | try: |
| | | data = data_callback_queue.get() |
| | | type_ = data[0] |
| | | data = data[1] |
| | | if type_ == "stock_index_datas": |
| | | for k in data: |
| | | """ |
| | | 值的格式为: |
| | | { |
| | | "LastPrice": pStockIndexData.LastPrice, |
| | | "SecurityID": pStockIndexData.SecurityID, |
| | | "UpdateTime": pStockIndexData.UpdateTime, |
| | | "Volume": pStockIndexData.Volume, |
| | | "Turnover": pStockIndexData.Turnover, |
| | | "LXLastPrice": pStockIndexData.LXLastPrice, |
| | | } |
| | | """ |
| | | d = data[k] |
| | | data_cache.stock_index_dict[k] = (round(d["LastPrice"], 2), d["Volume"], d["Turnover"]) |
| | | except: |
| | | pass |
| | | |
| | | |
| | | def run(): |
| | | global request_queue |
| | | request_queue, response_queue = multiprocessing.Queue(), multiprocessing.Queue() |
| | | request_queue, response_queue, data_callback_queue = multiprocessing.Queue(), multiprocessing.Queue(), multiprocessing.Queue() |
| | | # 启动增值服务进程 |
| | | process = multiprocessing.Process(target=l1_api_client.run, args=(request_queue, response_queue,), daemon=True) |
| | | process = multiprocessing.Process(target=l1_api_client.run, |
| | | args=(request_queue, response_queue, data_callback_queue,), daemon=True) |
| | | process.start() |
| | | |
| | | # 读取数据回调 |
| | | threading.Thread(target=__read_callback_data, args=(data_callback_queue,), daemon=True).start() |
| | | |
| | | __set_response(response_queue) |
| | | |
| | | |