| | |
| | | import l2.l2_data_util |
| | | from log_module.log import logger_l2_trade_buy_queue, logger_l2_trade_buy_progress |
| | | |
| | | buy_progress_index_cache = {} |
| | | |
| | | |
| | | class TradeBuyQueue: |
| | | buy_progress_index_cache = {} |
| | | |
| | | __db = 0 |
| | | __redis_manager = redis_manager.RedisManager(0) |
| | | __instance = None |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(TradeBuyQueue, cls).__new__(cls, *args, **kwargs) |
| | | cls.__load_datas() |
| | | return cls.__instance |
| | | |
| | | def __init__(self): |
| | | self.last_buy_queue_data = {} |
| | | |
| | | def __getRedis(self): |
| | | return self.__redis_manager.getRedis() |
| | | @classmethod |
| | | def __get_redis(cls): |
| | | return cls.__redis_manager.getRedis() |
| | | |
| | | @classmethod |
| | | def __load_datas(cls): |
| | | __redis = cls.__get_redis() |
| | | try: |
| | | keys = RedisUtils.keys(__redis, "trade_buy_progress_index-*") |
| | | for k in keys: |
| | | code = k.split("-")[-1] |
| | | val = RedisUtils.get(__redis, k) |
| | | val = json.loads(val) |
| | | tool.CodeDataCacheUtil.set_cache(cls.buy_progress_index_cache, code, val) |
| | | |
| | | finally: |
| | | RedisUtils.realse(__redis) |
| | | |
| | | def __save_buy_queue_data(self, code, num_list): |
| | | key = "trade_buy_queue_data-{}".format(code) |
| | | RedisUtils.setex(self.__getRedis(), key, tool.get_expire(), json.dumps((num_list, tool.get_now_time_str()))) |
| | | RedisUtils.setex(self.__get_redis(), key, tool.get_expire(), json.dumps((num_list, tool.get_now_time_str()))) |
| | | |
| | | # 返回数据与更新时间 |
| | | def __get_buy_queue_data(self, code): |
| | | key = "trade_buy_queue_data-{}".format(code) |
| | | val = RedisUtils.get(self.__getRedis(), key) |
| | | val = RedisUtils.get(self.__get_redis(), key) |
| | | if val is None: |
| | | return None, None |
| | | val = json.loads(val) |
| | | return val[0], [1] |
| | | |
| | | def __save_buy_progress_index(self, code, index, is_default): |
| | | tool.CodeDataCacheUtil.set_cache(buy_progress_index_cache, code, (index, is_default)) |
| | | tool.CodeDataCacheUtil.set_cache(self.buy_progress_index_cache, code, (index, is_default)) |
| | | key = "trade_buy_progress_index-{}".format(code) |
| | | RedisUtils.setex_async(self.__db, key, tool.get_expire(), json.dumps((index, is_default))) |
| | | # 返回数据与更新时间 |
| | | |
| | | def __get_buy_progress_index(self, code): |
| | | key = "trade_buy_progress_index-{}".format(code) |
| | | val = RedisUtils.get(self.__getRedis(), key) |
| | | val = RedisUtils.get(self.__get_redis(), key) |
| | | if val is None: |
| | | return None, True |
| | | val = json.loads(val) |
| | | return int(val[0]), bool(val[1]) |
| | | |
| | | def __get_buy_progress_index_cache(self, code): |
| | | cache_result = tool.CodeDataCacheUtil.get_cache(buy_progress_index_cache, code) |
| | | cache_result = tool.CodeDataCacheUtil.get_cache(self.buy_progress_index_cache, code) |
| | | if cache_result[0]: |
| | | return cache_result[1] |
| | | val = self.__get_buy_progress_index(code) |
| | | tool.CodeDataCacheUtil.set_cache(buy_progress_index_cache, code, val) |
| | | return val |
| | | return None, True |
| | | |
| | | # 最近的非涨停买1的时间 |
| | | def __save_latest_not_limit_up_time(self, code, time_str): |
| | | key = "latest_not_limit_up_time-{}".format(code) |
| | | RedisUtils.setex(self.__getRedis(), key, tool.get_expire(), time_str) |
| | | RedisUtils.setex(self.__get_redis(), key, tool.get_expire(), time_str) |
| | | |
| | | def __get_latest_not_limit_up_time(self, code): |
| | | key = "latest_not_limit_up_time-{}".format(code) |
| | | if not constant.TEST: |
| | | return RedisUtils.get(self.__getRedis(), key) |
| | | return RedisUtils.get(self.__get_redis(), key) |
| | | return None |
| | | |
| | | # 保存数据,返回保存数据的条数 |