| | |
| | | from code_atrribute import gpcode_manager, history_k_data_util |
| | | from code_atrribute.gpcode_manager import CodesNameManager |
| | | from code_atrribute.history_k_data_util import HistoryKDatasUtils |
| | | from code_atrribute.position_code_data_manager import PositionCodeDataManager |
| | | from huaxin_client.client_network import SendResponseSkManager |
| | | from huaxin_client.l2_data_transform_protocol import L2DataCallBack |
| | | from l2 import l2_data_util |
| | |
| | | if direction == 2: |
| | | # price_type: 0-价格笼子 1-跌停价 2-涨停价 3-现价 4-买5价 |
| | | async_log_util.info(logger_trade, f"API卖: 接收数据-{data}") |
| | | current_price = L1DataProcessor.get_l1_current_price(code) |
| | | current_price = PositionCodeDataManager.get_l1_current_price(code) |
| | | if current_price is None: |
| | | results = history_k_data_util.HistoryKDatasUtils.get_gp_current_info([code]) |
| | | if results: |
| | |
| | | else: |
| | | # 开盘之后 |
| | | # 没有传入价格,以最新价买入 |
| | | current_price = L1DataProcessor.get_l1_current_price(code) |
| | | current_price = PositionCodeDataManager.get_l1_current_price(code) |
| | | if not current_price: |
| | | raise Exception("尚未获取到现价") |
| | | # 获取买1金额 |
| | | price = round(float(current_price), 2) |
| | | buy1_info = L1DataProcessor.current_buy1_dict.get(code) |
| | | buy1_info = PositionCodeDataManager.get_l1_current_buy1_data(code) |
| | | if buy1_info and buy1_info[0] * buy1_info[1] > 50 * 10000: |
| | | # 如果买1在50w以上就加一档 |
| | | price += 0.01 |
| | |
| | | fdata["code_info"] = (code, name) |
| | | |
| | | # 有现价就获取现价 |
| | | current_price = L1DataProcessor.get_l1_current_price(code) |
| | | current_price = PositionCodeDataManager.get_l1_current_price(code) |
| | | pre_close_price = gpcode_manager.get_price_pre_cache(code) |
| | | if current_price: |
| | | fdata["cost_price"] = current_price |
| | |
| | | continue |
| | | # 获取现价 |
| | | fdata = {"code": code_, "code_name": code_name, "total": d["prePosition"], |
| | | "available": d["availablePosition"], "cost_price": d["historyPosPrice"]} |
| | | current_price = L1DataProcessor.get_l1_current_price(code_) |
| | | "available": d["availablePosition"], "cost_price": d["historyPosPrice"], "volume_rate": 0} |
| | | |
| | | current_volume, pre_volume = PositionCodeDataManager.get_l1_current_volume( |
| | | code_), PositionCodeDataManager.get_pre_volume(code_) |
| | | if current_volume and pre_volume and pre_volume > 0: |
| | | fdata["volume_rate"] = round(current_volume / pre_volume, 2) |
| | | current_price = PositionCodeDataManager.get_l1_current_price(code_) |
| | | if current_price: |
| | | fdata["cost_price"] = current_price |
| | | fdatas.append(fdata) |
| | |
| | | |
| | | |
| | | class L1DataProcessor: |
| | | __current_price_dict = {} |
| | | current_buy1_dict = {} |
| | | # L1数据更新时间 |
| | | __l1_data_update_time_dict = {} |
| | | |
| | |
| | | data = data_json["data"] |
| | | request_id = data_json["request_id"] |
| | | datas = data["data"] |
| | | cls.__save_l1_current_price(datas) |
| | | PositionCodeDataManager.set_current_l1_datas(datas) |
| | | cls.process_for_sell(datas) |
| | | |
| | | @classmethod |
| | |
| | | logger_debug.exception(e) |
| | | finally: |
| | | TradeRuleManager().release_sell_lock(r.id_) |
| | | |
| | | # 获取L1现价 |
| | | @classmethod |
| | | def get_l1_current_price(cls, code): |
| | | return cls.__current_price_dict.get(code) |
| | | |
| | | # 保存现价 |
| | | @classmethod |
| | | def __save_l1_current_price(cls, datas): |
| | | for d in datas: |
| | | code = d[0] |
| | | # 格式 (代码,现价,涨幅,量,更新时间,买1价格,买1量) |
| | | price = d[1] |
| | | cls.__current_price_dict[code] = price |
| | | cls.current_buy1_dict[code] = (d[5], d[6]) |
| | | |
| | | |
| | | # 读取L1的数据 |