| | |
| | | # 设置交易账户的可用金额 |
| | | |
| | | |
| | | 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 save_trade_success_data(datas, day=datetime.datetime.now().strftime("%Y%m%d")): |
| | | time_str = tool.get_now_time_str() |
| | |
| | | @return: |
| | | """ |
| | | price = gpcode_manager.get_limit_up_price(code) |
| | | __buy(code, price, trade_constant.TRADE_STATE_NOT_TRADE, 0, last_data, last_data["index"], 0, exec_index=exec_index) |
| | | __buy(code, price, trade_constant.TRADE_STATE_NOT_TRADE, 0, last_data, last_data["index"], 0, exec_index=exec_index) |
| | | |
| | | |
| | | # 中断买入 |
| | |
| | | continue |
| | | # 买入成功 |
| | | if code is not None and int(data["type"]) == 0: |
| | | l2_trade_util.forbidden_trade(code, msg="交易成功", force=True) |
| | | if not CodesContinueBuyMoneyManager().get_continue_buy_money(code): |
| | | l2_trade_util.forbidden_trade(code, msg="交易成功", force=True) |
| | | state = CodesTradeStateManager().get_trade_state_cache(code) |
| | | if state != trade_constant.TRADE_STATE_BUY_SUCCESS: |
| | | CodesTradeStateManager().set_trade_state(code, trade_constant.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) |
| | | if not CodesContinueBuyMoneyManager().get_continue_buy_money(code): |
| | | l2_trade_util.forbidden_trade(code, "buy success", force=True) |
| | | mode = TradePointManager().get_latest_place_order_mode(code) |
| | | if mode is None: |
| | | mode = OrderBeginPosInfo.MODE_NORMAL |