New file |
| | |
| | | """ |
| | | 涨停时间管理器 |
| | | """ |
| | | from log_module import log_export, async_log_util |
| | | from log_module.log import logger_first_limit_up_time |
| | | from utils import tool, l2_huaxin_util |
| | | |
| | | |
| | | class FirstLimitUpTimeManager: |
| | | """ |
| | | 首次涨停时间管理器 |
| | | """ |
| | | __instance = None |
| | | __first_limit_up_price_dict = {} |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(FirstLimitUpTimeManager, cls).__new__(cls, *args, **kwargs) |
| | | cls.__load_data() |
| | | return cls.__instance |
| | | |
| | | def process(self, market_info): |
| | | """ |
| | | 处理Market数据 |
| | | :param market_info: |
| | | :return: |
| | | """ |
| | | # 只处理股票代码 |
| | | if not tool.is_stock(market_info[0]): |
| | | return |
| | | if market_info[0] in self.__first_limit_up_price_dict: |
| | | return |
| | | limit_up_price = tool.get_limit_up_price(market_info[0], market_info[8]) |
| | | if abs(float(limit_up_price) - market_info[1]) < 0.0001: |
| | | # 涨停价 |
| | | time_str = l2_huaxin_util.convert_time(market_info[9]) |
| | | async_log_util.info(logger_first_limit_up_time, f"{(market_info[0], time_str)}") |
| | | self.__first_limit_up_price_dict[market_info[0]] = time_str |
| | | |
| | | def get_first_limit_up_time(self, code): |
| | | """ |
| | | 获取首次涨停时间 |
| | | :param code: |
| | | :return: |
| | | """ |
| | | self.__first_limit_up_price_dict.get(code) |
| | | |
| | | @classmethod |
| | | def __load_data(cls): |
| | | cls.__first_limit_up_price_dict = log_export.load_first_limit_up_time() |
| | | |
| | |
| | | filter=lambda record: record["extra"].get("name") == "profile", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | | |
| | | logger.add(self.get_path("market", "first_limit_up_time"), |
| | | filter=lambda record: record["extra"].get("name") == "first_limit_up_time", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | | |
| | | ################################华鑫日志################################ |
| | | logger.add(self.get_hx_path("l2", "transaction"), |
| | | filter=lambda record: record["extra"].get("name") == "hx_l2_transaction", |
| | |
| | | |
| | | logger_mysql_debug = __mylogger.get_logger("mysql_debug") |
| | | |
| | | logger_first_limit_up_time = __mylogger.get_logger("first_limit_up_time") |
| | | |
| | | # -------------------------------华鑫日志--------------------------------- |
| | | hx_logger_l2_orderdetail = __mylogger.get_logger("hx_l2_orderdetail") |
| | | hx_logger_l2_transaction = __mylogger.get_logger("hx_l2_transaction") |
| | |
| | | return fdatas |
| | | |
| | | |
| | | def load_first_limit_up_time(date=tool.get_now_date_str()): |
| | | """ |
| | | 加载下单的order_ref对应的策略 |
| | | :param date: |
| | | :return: |
| | | """ |
| | | fdatas = {} |
| | | path = f"{constant.get_path_prefix()}/{constant.LOG_DIR}/gp/market/first_limit_up_time.{date}.log" |
| | | with open(path, 'r', encoding='utf-8') as file: |
| | | lines = file.readlines() |
| | | for line in lines: |
| | | if line.find("]") > -1: |
| | | line = line[line.find("]") + 1:] |
| | | data = eval(line) |
| | | fdatas[data[0]] = data[1] |
| | | return fdatas |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | fdatas = load_order_ref_strategy() |
| | | print(fdatas) |
| | |
| | | |
| | | from code_attribute import target_codes_manager, gpcode_manager, code_market_manager, history_k_data_util |
| | | from code_attribute.gpcode_manager import CodesNameManager |
| | | from code_attribute.limit_up_time_manager import FirstLimitUpTimeManager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from huaxin_client import l2_client_for_cb |
| | | from huaxin_client.client_network import SendResponseSkManager |
| | |
| | | for k in temp_dict: |
| | | volume = sum([x["volume"] for x in temp_dict[k]]) |
| | | x = temp_dict[k][0] |
| | | r["buy_list"].append({"price": str(x["price"]), "tradeTime": x["tradeTime"], "volume": volume, "type":StrategyBuyOrderRefManager().get_strategy_type(x["orderRef"])}) |
| | | r["buy_list"].append({"price": str(x["price"]), "tradeTime": x["tradeTime"], "volume": volume, |
| | | "type": StrategyBuyOrderRefManager().get_strategy_type(x["orderRef"])}) |
| | | r["createTime"] = int(buys[0]["tradeTime"].replace(":", "")) |
| | | |
| | | if "sell_list" not in r: |
| | |
| | | cb_code, strategy_type): |
| | | # 已经买了且没在想买单 |
| | | continue |
| | | # 如果之前就涨停了且没在想买单中 |
| | | underlying_code = target_codes_manager.get_underlying_code(cb_code) |
| | | underlying_limit_up_time = FirstLimitUpTimeManager().get_first_limit_up_time(underlying_code) |
| | | if not WantBuyCodesManager().is_in_cache(cb_code, strategy_type) and underlying_limit_up_time: |
| | | continue |
| | | |
| | | # 获取可转债的涨停价 |
| | | market_info = code_market_manager.get_market_info(cb_code) |
| | | limit_up_price = target_codes_manager.get_limit_up_price(cb_code) |
| | |
| | | if result: |
| | | # (代码, 最近的价格, 涨幅, 买1价, 买1量, 成交总量, 买入量, 卖出量, 昨日收盘价, 时间戳) |
| | | code_market_manager.set_market_info(result) |
| | | time_str = l2_huaxin_util.convert_time(result[9]) |
| | | if int(time_str.split(":", "")) < int("092455"): |
| | | continue |
| | | code = result[0] |
| | | # 正股需要加载板块 |
| | | if code.find("11") != 0 and code.find("12") != 0: |
| | |
| | | KPLCodeJXBlockManager().load_jx_blocks(result[0], result[3], |
| | | float(limit_up_price), |
| | | KPLLimitUpDataRecordManager.get_current_reasons()) |
| | | FirstLimitUpTimeManager().process(result) |
| | | else: |
| | | # 可转债代码,处理 |
| | | sell_strategy.process_market_info(result, __BuyStrategyDataManager) |