| | |
| | | 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: |
| | |
| | | continue |
| | | # 买入成功 |
| | | if code is not None and int(data["type"]) == 0: |
| | | l2_trade_util.forbidden_trade(code, msg="交易成功",force = True) |
| | | l2_trade_util.forbidden_trade(code, msg="交易成功", force=True) |
| | | state = CodesTradeStateManager().get_trade_state_cache(code) |
| | | if state != TRADE_STATE_BUY_SUCCESS: |
| | | CodesTradeStateManager().set_trade_state(code, TRADE_STATE_BUY_SUCCESS) |
| | |
| | | def buy_success(code): |
| | | # 加入黑名单 |
| | | if not l2_trade_util.is_in_forbidden_trade_codes(code): |
| | | l2_trade_util.forbidden_trade(code, "buy success",force=True) |
| | | l2_trade_util.forbidden_trade(code, "buy success", force=True) |
| | | # 取s消所有的挂单 |
| | | if constant.API_TRADE_ENABLE: |
| | | if constant.TRADE_WAY == constant.TRADE_WAY_JUEJIN: |