| | |
| | | |
| | | from cancel_strategy.s_l_h_cancel_strategy import CancelRateHumanSettingManager |
| | | from code_attribute import gpcode_manager |
| | | from code_attribute.gpcode_manager import CodesContinueBuyMoneyManager |
| | | from db import mysql_data_delegate as mysql_data, redis_manager_delegate as redis_manager |
| | | from db.mysql_data_delegate import Mysqldb |
| | | from db.redis_manager_delegate import RedisUtils |
| | |
| | | return 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) |
| | | |
| | | |
| | | # 保存交易成功的数据 |