| | |
| | | from db.mysql_data_delegate import Mysqldb |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from log_module import log_export, async_log_util |
| | | from log_module.log import logger_pre_close_price, logger_debug |
| | | from log_module.log import logger_pre_close_price, logger_debug, logger_trade |
| | | from trade import trade_record_log_util |
| | | from utils import tool |
| | | import decimal |
| | |
| | | RedisUtils.delete(self.__get_redis(), "green-trade-codes") |
| | | |
| | | |
| | | class CodesContinueBuyMoneyManager: |
| | | """ |
| | | 代码续买金额管理 |
| | | """ |
| | | __db = 2 |
| | | __redis_manager = redis_manager.RedisManager(2) |
| | | __instance = None |
| | | __buy_money_dict = {} |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(CodesContinueBuyMoneyManager, cls).__new__(cls, *args, **kwargs) |
| | | cls.__load_datas() |
| | | |
| | | return cls.__instance |
| | | |
| | | @classmethod |
| | | def __get_redis(cls): |
| | | return cls.__redis_manager.getRedis() |
| | | |
| | | @classmethod |
| | | def __load_datas(cls): |
| | | __redis = cls.__get_redis() |
| | | # 初始化数据 |
| | | keys = RedisUtils.keys(__redis, "continue_buy_money-*", auto_free=False) |
| | | if keys: |
| | | for key in keys: |
| | | code = key.split("-")[-1] |
| | | cls.__buy_money_dict[code] = int(RedisUtils.get(__redis, key, auto_free=False)) |
| | | |
| | | def set_continue_buy_money(self, code, money): |
| | | """ |
| | | 设置续买金额 |
| | | @param code: |
| | | @param money: |
| | | @return: |
| | | """ |
| | | self.__buy_money_dict[code] = money |
| | | RedisUtils.setex_async(self.__db, f"continue_buy_money-{code}", tool.get_expire(), money) |
| | | async_log_util.info(logger_trade, f"设置续买金额:{code}-{money}") |
| | | |
| | | def remove_continue_buy_money(self, code): |
| | | """ |
| | | 移除续买金额 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | if code not in self.__buy_money_dict: |
| | | return |
| | | self.__buy_money_dict.pop(code) |
| | | RedisUtils.delete_async(self.__db, f"continue_buy_money-{code}") |
| | | async_log_util.info(logger_trade, f"移除续买金额:{code}") |
| | | |
| | | def get_continue_buy_money(self, code): |
| | | """ |
| | | 获取续买金额 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | return self.__buy_money_dict.get(code) |
| | | |
| | | |
| | | |
| | | |
| | | def __parse_codes_data(code_datas): |
| | | codes = [] |
| | | name_codes = {} |