Administrator
1 天以前 ecfbb56f1ce77b2288d272fa1ed2a02623e92d5a
code_attribute/gpcode_manager.py
@@ -8,7 +8,7 @@
from db import redis_manager_delegate as redis_manager
from db.mysql_data_delegate import Mysqldb
from db.redis_manager_delegate import RedisUtils
from log_module import log_export
from log_module import log_export, async_log_util
from log_module.log import logger_pre_close_price, logger_debug
from trade import trade_record_log_util
from utils import tool
@@ -214,7 +214,7 @@
@tool.singleton
class HumanRemoveForbiddenManager:
    """
    认为移黑管理
    人为移黑管理
    """
    __db = 0
    redisManager = redis_manager.RedisManager(0)
@@ -283,7 +283,6 @@
    def is_in_cache(self, code):
        return code in self.__codes_cache
# 暂停下单代码管理
@@ -401,6 +400,7 @@
class WhiteListCodeManager:
    __instance = None
    __redis_manager = redis_manager.RedisManager(2)
    __human_remove_codes = set()
    def __new__(cls, *args, **kwargs):
        if not cls.__instance:
@@ -421,14 +421,21 @@
        if data:
            self.__white_codes_cache |= data
    def add_code(self, code):
    def add_code(self, code, is_human=False):
        if not is_human and code in self.__human_remove_codes:
            # 机器加白,且被人为移白了就不能再加白
            return
        self.__white_codes_cache.add(code)
        RedisUtils.sadd(self.__get_redis(), "white_list_codes", code)
        RedisUtils.expire(self.__get_redis(), "white_list_codes", tool.get_expire())
    def remove_code(self, code):
    def remove_code(self, code, is_human=False):
        self.__white_codes_cache.discard(code)
        RedisUtils.srem(self.__get_redis(), "white_list_codes", code)
        if is_human:
            self.human_remove(code)
    def is_in(self, code):
        return RedisUtils.sismember(self.__get_redis(), "white_list_codes", code)
@@ -445,6 +452,23 @@
    def clear(self):
        self.__white_codes_cache.clear()
        RedisUtils.delete(self.__get_redis(), "white_list_codes")
    def human_remove(self, code):
        """
        人为移白
        @param code:
        @return:
        """
        self.__human_remove_codes.add(code)
    def clear_huamn_info(self, code):
        """
        移除人为干预信息
        @param code:
        @return:
        """
        if code in self.__human_remove_codes:
            self.__human_remove_codes.discard(code)
class BlackListCodeManager:
@@ -743,36 +767,42 @@
    return list
@tool.singleton
class CodePrePriceManager:
    __price_pre_cache = {}
    __redisManager = redis_manager.RedisManager(0)
    def __init__(self):
        fdatas = log_export.load_pre_close_price()
        for code, v in fdatas.items():
            self.__price_pre_cache[code] = round(float(v), 2)
    # 获取收盘价
    @classmethod
    def get_price_pre(cls, code):
    def get_price_pre(self, code):
        fdatas = log_export.load_pre_close_price()
        if code in fdatas:
            return round(float(fdatas.get(code)), 2)
        return None
    # 获取缓存
    @classmethod
    def get_price_pre_cache(cls, code):
        if code in cls.__price_pre_cache:
            return float(cls.__price_pre_cache[code])
        val = cls.get_price_pre(code)
    def get_price_pre_cache(self, code):
        if code in self.__price_pre_cache:
            return float(self.__price_pre_cache[code])
        val = self.get_price_pre(code)
        if val:
            cls.__price_pre_cache[code] = val
            self.__price_pre_cache[code] = val
        return val
    # 设置收盘价
    @classmethod
    def set_price_pre(cls, code, price, force=False):
        if code in cls.__price_pre_cache and not force:
    def set_price_pre(self, code, price, force=False):
        if float(price) > 1000:
            async_log_util.info(logger_debug, f"获取昨日收盘价异常:{code}-{price}")
            return
        if code in self.__price_pre_cache and not force:
            return
        price = round(float(price), 2)
        logger_pre_close_price.info(f"{code}-{price}")
        cls.__price_pre_cache[code] = price
        self.__price_pre_cache[code] = price
__limit_up_price_dict = {}
@@ -783,12 +813,17 @@
    # 读取内存中的值
    if code in __limit_up_price_dict:
        return __limit_up_price_dict[code]
    price = CodePrePriceManager.get_price_pre_cache(code)
    price = CodePrePriceManager().get_price_pre_cache(code)
    if price is None:
        return None
    limit_up_price = tool.to_price(decimal.Decimal(str(price)) * decimal.Decimal(tool.get_limit_up_rate(code)))
    __limit_up_price_dict[code] = limit_up_price
    return limit_up_price
def clear_limit_up_price_cache(code):
    if code in __limit_up_price_dict:
        __limit_up_price_dict.pop(code)
def get_limit_up_price_as_num(code):
@@ -818,7 +853,7 @@
# 获取跌停价
def get_limit_down_price(code):
    price = CodePrePriceManager.get_price_pre_cache(code)
    price = CodePrePriceManager().get_price_pre_cache(code)
    if price is None:
        return None
    return tool.to_price(decimal.Decimal(str(price)) * decimal.Decimal(f"{tool.get_limit_down_rate(code)}"))
@@ -945,4 +980,4 @@
        RedisUtils.delete(redis_instance, "first_code_record", auto_free=False)
        RedisUtils.delete(redis_instance, "first_code_limited_up_record", auto_free=False)
    finally:
        RedisUtils.realse(redis_instance)
        RedisUtils.realse(redis_instance)