| | |
| | | from trade.sell import sell_manager |
| | | from trade.sell.sell_rule_manager import TradeRuleManager, SellRule |
| | | from trade.trade_data_manager import RadicalBuyDealCodesManager |
| | | from trade.trade_manager import TradeTargetCodeModeManager, AutoCancelSellModeManager |
| | | from trade.trade_manager import TradeTargetCodeModeManager, AutoCancelSellModeManager, CodesContinueBuyMoneyManager |
| | | from settings.trade_setting import MarketSituationManager, TradeBlockBuyModeManager |
| | | from utils import socket_util, data_export_util, tool, huaxin_util, output_util, global_util, init_data_util |
| | | from servers import server_util |
| | |
| | | client_id, |
| | | request_id) |
| | | return |
| | | TotalDealBigOrderThresholdMoneyManager().set_money(code, int(money), trade_manager.CodesTradeStateManager().get_trade_state_cache(code)) |
| | | TotalDealBigOrderThresholdMoneyManager().set_money(code, int(money), |
| | | trade_manager.CodesTradeStateManager().get_trade_state_cache( |
| | | code)) |
| | | |
| | | # 如果是加红状态,且大单不够就需要移红 |
| | | if gpcode_manager.MustBuyCodesManager().is_in_cache(code): |
| | | deal_big_order_info = radical_buy_data_manager.get_total_deal_big_order_info(code, gpcode_manager.get_limit_up_price_as_num(code)) |
| | | deal_big_order_info = radical_buy_data_manager.get_total_deal_big_order_info(code, |
| | | gpcode_manager.get_limit_up_price_as_num( |
| | | code)) |
| | | if deal_big_order_info[0] > 0: |
| | | gpcode_manager.MustBuyCodesManager().remove_code(code) |
| | | trade_record_log_util.add_common_msg(code, "移红", f"大单阈值修改({money})") |
| | |
| | | client_id, |
| | | request_id) |
| | | |
| | | elif ctype == "get_continue_buy_info": |
| | | # 设置L后撤单比例 |
| | | code = data.get("code") |
| | | money = CodesContinueBuyMoneyManager().get_continue_buy_money(code) |
| | | if money is None: |
| | | money = 0 |
| | | self.send_response({"code": 0, "data": {"money": money, "money_list": constant.AVAILABLE_BUY_MONEYS}}, |
| | | client_id, |
| | | request_id) |
| | | elif ctype == "set_continue_buy_money": |
| | | # 设置L后撤单比例 |
| | | code = data.get("code") |
| | | money = data.get("money") |
| | | if money <= 0: |
| | | # 表示移除续买金额 |
| | | CodesContinueBuyMoneyManager().remove_continue_buy_money(code) |
| | | self.send_response({"code": 0, "data": {}}, |
| | | client_id, |
| | | request_id) |
| | | return |
| | | if money not in constant.AVAILABLE_BUY_MONEYS: |
| | | self.send_response({"code": 1, "msg": f"金额({money})没在{constant.AVAILABLE_BUY_MONEYS}中"}, |
| | | client_id, |
| | | request_id) |
| | | return |
| | | CodesContinueBuyMoneyManager().set_continue_buy_money(code, money) |
| | | l2_trade_util.remove_from_forbidden_trade_codes(code) |
| | | self.send_response({"code": 0, "data": {}}, |
| | | client_id, |
| | | request_id) |
| | | |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | logger_debug.exception(e) |
| | |
| | | """ |
| | | try: |
| | | must_buy = cls.__MustBuyCodesManager.is_in_cache(code) |
| | | if buy_mode == OrderBeginPosInfo.MODE_RADICAL: |
| | | if buy_mode == OrderBeginPosInfo.MODE_RADICAL or True: |
| | | try: |
| | | human_rate = CancelRateHumanSettingManager().get_l_down(code) |
| | | if human_rate is None: |
| | |
| | | # 目标撤单比例大于大单撤单比例就取比例均值 |
| | | thresh_hold_rate = round((thresh_hold_rate + temp_thresh_hold_rate) / 2, 2) |
| | | l2_log.l_cancel_debug(code, |
| | | f"L后计算范围:{start_index}-{end_index},已撤单比例:{rate}/{thresh_hold_rate}, 下单位之后的索引:{after_place_order_index_dict}, 最大单-({max_num},{max_num_count})") |
| | | f"L后计算范围:{start_index}-{end_index},已撤单比例:{rate}/{thresh_hold_rate}, 下单位之后的索引:{after_place_order_index_dict}, 最大单-({max_num},{max_num_count}), 人为设置-{cancel_rate_info}") |
| | | if rate >= thresh_hold_rate: |
| | | canceled_indexes.sort() |
| | | l2_log.l_cancel_debug(code, f"L后撤单,撤单位置:{canceled_indexes[-1]}") |
| | |
| | | L2_DATA_IS_LOADED = False |
| | | |
| | | # 可买入的金额 |
| | | AVAILABLE_BUY_MONEYS = [5000, 20000, 40000, 45000, 50000, 55000, 60000, 65000, 70000] |
| | | AVAILABLE_BUY_MONEYS = [25000, 30000, 35000, 45000, 50000] |
| | | |
| | | # 板上放量是否可扫入 |
| | | CAN_RADICAL_BUY_AT_LIMIT_UP = False |
| | |
| | | EveryLimitupBigDelegateOrderManager |
| | | from trade.sell.sell_rule_manager import TradeRuleManager |
| | | from trade.trade_data_manager import RadicalBuyDealCodesManager |
| | | from trade.trade_manager import CodesTradeStateManager |
| | | from trade.trade_manager import CodesTradeStateManager, CodesContinueBuyMoneyManager |
| | | from utils import socket_util, middle_api_protocol, tool, huaxin_util, global_util, trade_util, init_data_util, \ |
| | | output_util |
| | | |
| | |
| | | huaxin_trade_record_manager.DelegateRecordManager.add([data]) |
| | | if huaxin_util.is_deal(order_status): |
| | | if int(str(data["direction"])) == huaxin_util.TORA_TSTP_D_Buy: |
| | | # 订单成交回调,移除续买金额+拉黑 |
| | | CodesContinueBuyMoneyManager().remove_continue_buy_money(data["securityID"]) |
| | | l2_trade_util.forbidden_trade(data["securityID"], msg="已成交", force=True) |
| | | if TradePointManager.get_latest_place_order_mode( |
| | | data["securityID"]) == OrderBeginPosInfo.MODE_RADICAL: |
| | |
| | | normal_buy_setting = BuyMoneyAndCountSetting().get_normal_buy_setting() |
| | | if normal_buy_setting: |
| | | moneys |= set([x[1] for x in normal_buy_setting[1]]) |
| | | moneys.add(constant.BUY_MONEY_PER_CODE) |
| | | print(moneys) |
| | | moneys |= set(constant.AVAILABLE_BUY_MONEYS) |
| | | return moneys |
| | | |
| | | @classmethod |
| | |
| | | special_volumes = BuyMoneyUtil.get_possible_buy_volumes(limit_up_price) |
| | | special_volumes |= set([tool.get_buy_volume_by_money(limit_up_price, x) for x in constant.AVAILABLE_BUY_MONEYS]) |
| | | print(special_volumes) |
| | | |
| | | |
| | | # print(json.dumps(list(BuyMoneyUtil.get_possible_buy_moneys()))) |
| | |
| | | # 设置交易账户的可用金额 |
| | | |
| | | |
| | | 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() |
| | |
| | | continue |
| | | # 买入成功 |
| | | if code is not None and int(data["type"]) == 0: |
| | | 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: |
| | |
| | | def buy_success(code): |
| | | # 加入黑名单 |
| | | if not l2_trade_util.is_in_forbidden_trade_codes(code): |
| | | 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: |