| | |
| | | return self.__trade_buy_mode_cache |
| | | |
| | | |
| | | # 市场行情等级管理 |
| | | class MarketSituationManager: |
| | | # 差 |
| | | SITUATION_BAD = 0 |
| | | # 一般 |
| | | SITUATION_COMMON = 1 |
| | | # 好 |
| | | SITUATION_GOOD = 2 |
| | | |
| | | __db = 2 |
| | | redisManager = redis_manager.RedisManager(2) |
| | | __situation_cache = SITUATION_BAD |
| | | __instance = None |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(MarketSituationManager, cls).__new__(cls, *args, **kwargs) |
| | | # 初始化设置 |
| | | # 获取交易窗口的锁 |
| | | cls.__instance.__situation_cache = cls.get_situation() |
| | | return cls.__instance |
| | | |
| | | @classmethod |
| | | def __get_redis(cls): |
| | | return cls.redisManager.getRedis() |
| | | |
| | | def set_situation(self, situation): |
| | | if situation not in [self.SITUATION_BAD, self.SITUATION_COMMON, self.SITUATION_GOOD]: |
| | | raise Exception("situation参数值错误") |
| | | self.__situation_cache = situation |
| | | RedisUtils.setex_async(self.__db, "market_situation", tool.get_expire(), situation) |
| | | |
| | | # 是否可以下单 |
| | | @classmethod |
| | | def get_situation(cls): |
| | | # 默认设置为可交易 |
| | | val = RedisUtils.get(cls.__get_redis(), "market_situation") |
| | | if val is None: |
| | | return cls.SITUATION_BAD |
| | | return int(val) |
| | | |
| | | def get_situation_cache(self): |
| | | return self.__situation_cache |
| | | |
| | | |
| | | # 根据分数禁止买的票管理 |
| | | class ForbiddenBuyCodeByScoreManager: |
| | | __instance = None |
| | |
| | | __db = 2 |
| | | __redis_manager = redis_manager.RedisManager(2) |
| | | __instance = None |
| | | |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |