| | |
| | | codes = L1DataProcessor.get_latest_update_codes() |
| | | result = {"code": 0, "data": list(codes)} |
| | | self.send_response(result, client_id, request_id) |
| | | elif ctype == "get_l2_deal_price": |
| | | # 根据L2数据获取成交价 |
| | | code = data["code"] |
| | | price_info = L2DataProcessor.get_deal_price(code) |
| | | if price_info: |
| | | fdata = {"price": price_info[0], "time": price_info[1]} |
| | | pre_price = gpcode_manager.get_price_pre_cache(code) |
| | | if pre_price: |
| | | fdata["rate"] = round((price_info[0] - pre_price) / pre_price, 4) |
| | | result = {"code": 0, "data": fdata} |
| | | else: |
| | | result = {"code": 1, "msg": "尚未获取到价格"} |
| | | self.send_response(result, client_id, request_id) |
| | | elif ctype == "get_l2_datas": |
| | | # 获取L2数据 |
| | | code = data["code"] |
| | |
| | | logging.exception(e) |
| | | |
| | | |
| | | class L2DataProcessor: |
| | | __latest_deal_price_info = {} |
| | | |
| | | @classmethod |
| | | def set_deal_price(cls, code, price, time_str): |
| | | """ |
| | | 设置成交价格 |
| | | :param code: 代码 |
| | | :param price: 价格 |
| | | :param time_str: 时间 |
| | | :return: |
| | | """ |
| | | cls.__latest_deal_price_info[code] = (price, time_str) |
| | | |
| | | @classmethod |
| | | def get_deal_price(cls, code): |
| | | """ |
| | | 获取成交价格 |
| | | :param code: |
| | | :return: |
| | | """ |
| | | return cls.__latest_deal_price_info.get(code) |
| | | |
| | | |
| | | class MyL2DataCallback(L2DataCallBack): |
| | | |
| | | def OnL2Order(self, code, origin_datas, timestamp): |
| | | # 保存L2数据 |
| | | datas = None |
| | |
| | | |
| | | def OnL2Transaction(self, code, datas): |
| | | async_log_util.info(hx_logger_l2_transaction, f"{code}#{datas}") |
| | | if datas: |
| | | # 获取最近的成交价 |
| | | price, time_str = datas[-1][1], l2_huaxin_util.convert_time(datas[-1][3]) |
| | | L2DataProcessor.set_deal_price(code, price, time_str) |
| | | |
| | | |
| | | # 做一些初始化的操作 |
| | |
| | | |
| | | threading.Thread(target=lambda: async_log_util.run_sync(), daemon=True).start() |
| | | |
| | | threading.Thread(target=lambda: async_log_util.l2_data_log.run_sync(), daemon=True).start() |
| | | threading.Thread(target=lambda: async_log_util.l2_data_log.run_sync(), daemon=True).start() |
| | | |
| | | huaxin_trade_data_update.run(queue_l1_trade_r_strategy_w, queue_strategy_w_l2_r) |
| | | |