New file |
| | |
| | | # 涨停时间管理器 |
| | | """ |
| | | 今日最高价管理 |
| | | """ |
| | | import json |
| | | |
| | | from db import redis_manager_delegate as redis_manager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_debug |
| | | from utils import global_util, tool |
| | | |
| | | |
| | | class MaxPriceInfoManager: |
| | | __max_price_info_cache = {} |
| | | __db = 4 |
| | | _redisManager = redis_manager.RedisManager(4) |
| | | __instance = None |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(MaxPriceInfoManager, cls).__new__(cls, *args, **kwargs) |
| | | cls.load_max_price_info() |
| | | return cls.__instance |
| | | |
| | | @classmethod |
| | | def load_max_price_info(cls): |
| | | redis = cls._redisManager.getRedis() |
| | | keys = RedisUtils.keys(redis, "max_price_info-*", auto_free=False) |
| | | for key in keys: |
| | | code = key.replace("max_price_info-", "") |
| | | val = RedisUtils.get(redis, key, auto_free=False) |
| | | if val: |
| | | val = json.loads(val) |
| | | cls.__max_price_info_cache[code] = val |
| | | |
| | | def set_price_info(self, code, price, time): |
| | | """ |
| | | 设置价格信息 |
| | | @param code: |
| | | @param price: |
| | | @param time: |
| | | @return: |
| | | """ |
| | | old_price_info = self.__max_price_info_cache.get(code) |
| | | if old_price_info and old_price_info[0] >= price: |
| | | return |
| | | price_info = (price, time) |
| | | tool.CodeDataCacheUtil.set_cache(self.__max_price_info_cache, code, price_info) |
| | | RedisUtils.setex_async( |
| | | self.__db, "max_price_info-{}".format(code), tool.get_expire(), json.dumps(price_info)) |
| | | async_log_util.info(logger_debug, f"最大现价-{price_info}") |
| | | |
| | | def get_price_info_cache(self, code): |
| | | return self.__max_price_info_cache.get(code) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | list = [("1234578", "09:00:03", None), ("12345", "09:00:01", True), ("123456", "09:00:00", True), |
| | | ("123457", "09:00:04", False)] |
| | |
| | | import constant |
| | | from code_attribute import global_data_loader, code_volumn_manager, first_target_code_data_processor, gpcode_manager |
| | | from code_attribute.code_data_util import ZYLTGBUtil |
| | | from code_attribute.today_max_price_manager import MaxPriceInfoManager |
| | | from db import redis_manager_delegate as redis_manager |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_l2_codes_subscript, logger_debug |
| | |
| | | if zylt_volume and price > 0: |
| | | zylt = zylt_volume * price |
| | | if not zylt: |
| | | try: |
| | | __start_time = time.time() |
| | | zylt = kpl_api.getZYLTAmount(code) |
| | | async_log_util.info(logger_l2_codes_subscript, |
| | | f"{request_id} {code}获取自由流通市值耗时-{round((time.time() - __start_time) * 1000)}ms") |
| | | # 保存自由流通股本 |
| | | if zylt: |
| | | ZYLTGBUtil.save_async(code, zylt, price) |
| | | except: |
| | | pass |
| | | # 默认20亿 |
| | | zylt = 20 * 1e8 |
| | | if zylt: |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | | if not limit_up_price: |
| | |
| | | global_util.zyltgb_map[code] = int(zylt) |
| | | # 保存今日实时量 |
| | | temp_volumns.append((code, d[3])) |
| | | |
| | | zyltgb = 0 |
| | | if code in global_util.zyltgb_map: |
| | | zyltgb = global_util.zyltgb_map[code] |
| | |
| | | yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() |
| | | if yesterday_codes is None: |
| | | yesterday_codes = set() |
| | | current_price_process_manager.accept_prices(tick_datas, request_id, in_blocks, yesterday_codes, top_out_blocks=out_blocks) |
| | | current_price_process_manager.accept_prices(tick_datas, request_id, in_blocks, yesterday_codes, |
| | | top_out_blocks=out_blocks) |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | finally: |
| | |
| | | if order_begin_pos.buy_volume_rate is None: |
| | | order_begin_pos.buy_volume_rate = 0.2 |
| | | cancel_data, cancel_msg, cancel_type = None, "", None |
| | | if order_begin_pos.mode == OrderBeginPosInfo.MODE_RADICAL: |
| | | |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg, cancel_type = rd_cancel(order_begin_pos.buy_single_index, |
| | | order_begin_pos.buy_exec_index) |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg, cancel_type = rd_cancel(order_begin_pos.buy_single_index, |
| | | order_begin_pos.buy_exec_index) |
| | | |
| | | # 扫入下单只有L撤 |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg, cancel_type = l_cancel(order_begin_pos.buy_single_index, |
| | | order_begin_pos.buy_exec_index) |
| | | else: |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg, cancel_type = rd_cancel(order_begin_pos.buy_single_index, |
| | | order_begin_pos.buy_exec_index) |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = g_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | cancel_type = trade_constant.CANCEL_TYPE_G |
| | | # 依次处理 |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg, cancel_type = l_cancel(order_begin_pos.buy_single_index, |
| | | order_begin_pos.buy_exec_index) |
| | | # B撤 |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = b_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | cancel_type = trade_constant.CANCEL_TYPE_G |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = h_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | cancel_type = trade_constant.CANCEL_TYPE_H |
| | | # J撤 |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = j_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | cancel_type = trade_constant.CANCEL_TYPE_J |
| | | # 扫入下单只有L撤 |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg, cancel_type = l_cancel(order_begin_pos.buy_single_index, |
| | | order_begin_pos.buy_exec_index) |
| | | |
| | | if cancel_data and not DCancelBigNumComputer().has_auto_cancel_rules(code): |
| | | try: |
| | |
| | | from code_attribute.code_l1_data_manager import L1DataManager |
| | | from code_attribute.gpcode_manager import CodePrePriceManager, CodesNameManager, \ |
| | | WantBuyCodesManager |
| | | from code_attribute.today_max_price_manager import MaxPriceInfoManager |
| | | from huaxin_client import l2_data_transform_protocol, l1_subscript_codes_manager |
| | | from huaxin_client.trade_transform_protocol import TradeResponse |
| | | from l2 import l2_data_manager_new, l2_log, code_price_manager, l2_data_util, transaction_progress, \ |
| | |
| | | datas = data["data"] |
| | | cls.__save_l1_current_price(datas) |
| | | cls.__process_buy_open_limit_up_datas(datas) |
| | | |
| | | try: |
| | | # 记录今日最高价 |
| | | # 09:25之后才开始记录 |
| | | if datas and tool.get_now_time_str() > '09:25:00': |
| | | for d in datas: |
| | | MaxPriceInfoManager().set_price_info(d[0], price=d[1], time=l2_huaxin_util.convert_time(d[9])) |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | |
| | | # 根据高标的实时涨幅计算拉黑板块 |
| | | rate_dict = {d[0]: d[2] for d in datas} |
| | | cls.__process_l1_data_thread_pool.submit( |
| | |
| | | import constant |
| | | import l2_data_util |
| | | from code_attribute.code_volumn_manager import CodeVolumeManager |
| | | from code_attribute.today_max_price_manager import MaxPriceInfoManager |
| | | from l2 import l2_data_util as l2_data_util_new, l2_log, l2_data_manager |
| | | from code_attribute import code_nature_analyse, code_volumn_manager, gpcode_manager |
| | | from code_attribute.code_l1_data_manager import L1DataManager |
| | |
| | | @return: |
| | | """ |
| | | is_limit_up = code in LimitUpDataConstant.get_history_limit_up_codes() |
| | | # 是否涨停 |
| | | if not is_limit_up: |
| | | # 根据L1判断是否涨停 |
| | | max_price_info = MaxPriceInfoManager().get_price_info_cache(code) |
| | | limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) |
| | | if max_price_info and abs(max_price_info[0] - limit_up_price)<0.001 and tool.trade_time_sub(tool.get_now_time_str(), max_price_info[1])>=3: |
| | | # 是涨停价且涨停时间距离现在3s以上 |
| | | is_limit_up = True |
| | | |
| | | place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code) |
| | | if place_order_count is None: |
| | | place_order_count = 0 |