| | |
| | | import schedule |
| | | |
| | | from code_atrribute import gpcode_manager |
| | | from code_atrribute.history_k_data_util import HistoryKDatasUtils |
| | | from huaxin_client.client_network import SendResponseSkManager |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_trade, logger_debug, logger_system, logger_local_huaxin_l1_trade_info, \ |
| | |
| | | except Exception as e: |
| | | self.send_response({"code": 1, "msg": str(e)}, client_id, request_id) |
| | | |
| | | def OnCommonRequest(self, client_id, request_id, data): |
| | | ctype = data["ctype"] |
| | | if ctype == "get_positions": |
| | | # 获取所有持仓信息 |
| | | positions = PositionManager.latest_positions |
| | | fdatas = [] |
| | | if positions: |
| | | for d in positions: |
| | | code_ = d["securityID"] |
| | | code_name = d["securityName"] |
| | | if d["prePosition"] <= 0: |
| | | continue |
| | | fdatas.append({"code": code_, "code_name": code_name, "total": d["prePosition"], |
| | | "available": d["availablePosition"]}) |
| | | result = {"code": 0, "data": fdatas} |
| | | self.send_response(result, client_id, request_id) |
| | | elif ctype == "get_buy1_info": |
| | | # 获取代码的买1信息 |
| | | code = data["code"] |
| | | results = HistoryKDatasUtils.get_gp_current_info([code]) |
| | | item = results[0]["quotes"][0] |
| | | result = {"code": 0, "data": {"price": item["bid_p"], "volume": item["bid_v"]}} |
| | | self.send_response(result, client_id, request_id) |
| | | |
| | | |
| | | class L1DataProcessor: |
| | | __current_price_dict = {} |
| | |
| | | API_TYPE_SELL_RULE = "sell_rule" # 卖出规则 |
| | | API_TYPE_REFRESH_TRADE_DATA = "refresh_trade_data" # 交易数据刷新 |
| | | API_TYPE_GET_CODE_POSITION_INFO = "get_code_position_info" # 获取代码持仓信息 |
| | | API_TYPE_COMMON_REQUEST = "common_request" # 通用请求 |
| | | |
| | | |
| | | class ActionCallback(object): |
| | |
| | | pass |
| | | |
| | | def OnGetCodePositionInfo(self, client_id, request_id, data): |
| | | pass |
| | | |
| | | def OnCommonRequest(self, client_id, request_id, data): |
| | | pass |
| | | |
| | | |
| | |
| | | cls.action_callback.OnRefreshTradeData(client_id, request_id, data) |
| | | elif content_type == API_TYPE_GET_CODE_POSITION_INFO: |
| | | cls.action_callback.OnGetCodePositionInfo(client_id, request_id, data) |
| | | elif content_type == API_TYPE_COMMON_REQUEST: |
| | | cls.action_callback.OnCommonRequest(client_id, request_id, data) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | finally: |