| | |
| | | from db import redis_manager_delegate as redis_manager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from l2.huaxin import l2_huaxin_util |
| | | from l2.l2_data_manager import TradePointManager |
| | | from l2.l2_data_util import L2DataUtil |
| | | from l2.l2_transaction_data_manager import BigOrderDealManager, HuaXinBuyOrderManager |
| | | from log_module import async_log_util |
| | |
| | | from third_data.kpl_data_constant import LimitUpDataConstant, LimitUpCodesBlockRecordManager |
| | | from third_data.kpl_data_manager import CodeHighLevel |
| | | from third_data.third_blocks_manager import BlockMapManager |
| | | from trade import trade_record_log_util |
| | | from trade import trade_record_log_util, trade_data_manager, trade_manager, trade_constant |
| | | from trade.buy_money_count_setting import RadicalBuyBlockCodeCountManager |
| | | from trade.buy_radical.block_special_codes_manager import BlockSpecialCodesManager |
| | | from trade.trade_data_manager import RadicalBuyDealCodesManager |
| | | from utils import tool, global_util |
| | | from utils import tool, global_util, trade_util |
| | | |
| | | |
| | | # RadicalBigOrderThresholdManager |
| | |
| | | # 已经成交的累计大卖单金额:用于初次上板尚未订阅的情况 |
| | | __already_total_sell_deal_big_order_money = {} |
| | | __redis_manager = redis_manager.RedisManager(3) |
| | | # 临时大单阈值,初次上板使用 |
| | | __temp_big_order_threshold = {} |
| | | |
| | | def __init__(self): |
| | | self.__load_data() |
| | |
| | | """ |
| | | 获取大单阈值 |
| | | @param code: |
| | | @return: |
| | | @return: 大单金额, 是否默认 |
| | | """ |
| | | if code in self.__big_order_threshold: |
| | | return self.__big_order_threshold.get(code) |
| | | return 2990000 |
| | | return self.__big_order_threshold.get(code), False |
| | | return 2990000, True |
| | | |
| | | def get_big_order_threshold_info(self, code): |
| | | """ |
| | | 获取大单阈值 |
| | | @param code: |
| | | @return:大单阈值,是否是临时大单 |
| | | """ |
| | | if not is_first_limit_up_buy(code): |
| | | return self.get_big_order_threshold(code), False |
| | | else: |
| | | money = self.get_temp_deal_big_order_threshold(code) |
| | | if not money: |
| | | # 默认阈值为 1个亿 |
| | | money = int(round(1e8)) |
| | | return money, True |
| | | |
| | | def __get_base_big_order_threshold(self, code): |
| | | """ |
| | |
| | | # 没有大单成交 |
| | | return False |
| | | return True |
| | | |
| | | def set_temp_deal_big_orders(self, code, money_list): |
| | | """ |
| | | 设置临时大单 |
| | | @param code: |
| | | @param money_list: 成交的大买单 |
| | | @return: |
| | | """ |
| | | if code in self.__temp_big_order_threshold: |
| | | return |
| | | if not money_list or len(money_list) < 2: |
| | | return |
| | | # 计算大单: 前2个大单的均值 |
| | | self.__temp_big_order_threshold[code] = int(sum(money_list[:2]) // 2) |
| | | async_log_util.info(logger_l2_radical_buy_data, |
| | | f"首次上板临时买大单:{code}-{self.__temp_big_order_threshold[code]}-{money_list[:2]}") |
| | | |
| | | def get_temp_deal_big_order_threshold(self, code): |
| | | return self.__temp_big_order_threshold.get(code) |
| | | |
| | | |
| | | @tool.singleton |
| | |
| | | @param code: |
| | | @return: {激进买的板块}, 原因 |
| | | """ |
| | | # =========计算代码买入的目标板块=========== |
| | | # 获取开1的板块 |
| | | |
| | | open_limit_up_code_dict = kpl_data_constant.open_limit_up_code_dict_for_radical_buy |
| | | open_limit_up_blocks = set() |
| | | if open_limit_up_code_dict: |
| | |
| | | for k in keys_: |
| | | block_info = cls.is_block_can_buy_with_block_in(code, k, yesterday_limit_up_codes, is_for_buy=True) |
| | | if block_info[0]: |
| | | if block_info[1] and False: |
| | | # 暂时不需要: 要求大单够了才买 |
| | | big_deal_info = get_total_deal_big_order_info(code, gpcode_manager.get_limit_up_price_as_num(code)) |
| | | if big_deal_info[0] <= 0: |
| | | keys_in_jx.add(k) |
| | | else: |
| | | msgs.append(f"【{k}】大单不够") |
| | | else: |
| | | keys_in_jx.add(k) |
| | | # if block_info[1] and False: |
| | | # # 暂时不需要: 要求大单够了才买 |
| | | # big_deal_info = get_total_deal_big_order_info(code, gpcode_manager.get_limit_up_price_as_num(code), is_for_buy=True) |
| | | # if big_deal_info[0] <= 0: |
| | | # keys_in_jx.add(k) |
| | | # else: |
| | | # msgs.append(f"【{k}】大单不够") |
| | | # else: |
| | | keys_in_jx.add(k) |
| | | if not keys_in_jx: |
| | | msgs.append(f"【{keys_}】板块未在精选流入中:") |
| | | # 板块尚未精选流入,且板块涨停代码个数是否<5个 |
| | | return set(), ",".join(msgs) |
| | | |
| | | keys_ = keys_in_jx |
| | | match_blocks = open_limit_up_blocks & keys_ |
| | | can_buy_blocks = set() |
| | | |
| | | today_history_limit_up_codes = set([d[3] for d in LimitUpDataConstant.history_limit_up_datas]) |
| | | # 初次上板买入方式 |
| | | fmsges = [] |
| | | msges = [] |
| | | for b in match_blocks: |
| | | # 判断板块是否该激进买 |
| | | result = cls.__is_radical_buy_with_open_limitup(code, b, yesterday_limit_up_codes) |
| | | if result[0]: |
| | | can_buy_blocks.add(b) |
| | | msges.append(f"【{b}】:{result[1]}") |
| | | fmsges.append("开1判断##" + ",".join(msges)) |
| | | if not can_buy_blocks: |
| | | msges.clear() |
| | | for b in keys_: |
| | | # 板块快速启动 |
| | | result = cls.__is_radical_buy_with_block_up(code, b, yesterday_limit_up_codes) |
| | | can_buy_blocks = set() |
| | | if code in today_history_limit_up_codes: |
| | | # 回封买入方式 |
| | | match_blocks = open_limit_up_blocks & keys_ |
| | | for b in match_blocks: |
| | | # 判断板块是否该激进买 |
| | | result = cls.__is_radical_buy_with_open_limitup(code, b, yesterday_limit_up_codes) |
| | | if result[0]: |
| | | can_buy_blocks.add(b) |
| | | |
| | | msges.append(f"【{b}】:{result[1]}") |
| | | fmsges.append("板块快速启动判断##" + ",".join(msges)) |
| | | fmsges.append("开1判断##" + ",".join(msges)) |
| | | if not can_buy_blocks: |
| | | msges.clear() |
| | | for b in keys_: |
| | | # 板块快速启动 |
| | | result = cls.__is_radical_buy_with_block_up(code, b, yesterday_limit_up_codes) |
| | | if result[0]: |
| | | can_buy_blocks.add(b) |
| | | |
| | | if not can_buy_blocks: |
| | | msges.clear() |
| | | for b in keys_: |
| | | result = cls.__is_first_can_buy(code, b) |
| | | if result[0]: |
| | | can_buy_blocks.add(b) |
| | | msges.append(f"【{b}】:{result[1]}") |
| | | fmsges.append("板块回封判断##" + ",".join(msges)) |
| | | fmsges.append("板块快速启动判断##" + ",".join(msges)) |
| | | |
| | | if not can_buy_blocks: |
| | | msges.clear() |
| | | for b in keys_: |
| | | result = cls.__block_special_codes(code, b, yesterday_limit_up_codes) |
| | | if result[0]: |
| | | can_buy_blocks.add(b) |
| | | msges.append(f"【{b}】:{result[1]}") |
| | | fmsges.append("板块辨识度判断##" + ",".join(msges)) |
| | | if not can_buy_blocks: |
| | | msges.clear() |
| | | for b in keys_: |
| | | result = cls.__is_first_can_buy(code, b) |
| | | if result[0]: |
| | | can_buy_blocks.add(b) |
| | | msges.append(f"【{b}】:{result[1]}") |
| | | fmsges.append("板块回封判断##" + ",".join(msges)) |
| | | |
| | | # 如果能扫入就需要获取代码在板块中的身位 |
| | | # if can_buy_blocks: |
| | | # excude_codes = set() |
| | | # if kpl_data_constant.open_limit_up_code_dict_for_radical_buy: |
| | | # excude_codes |= kpl_data_constant.open_limit_up_code_dict_for_radical_buy.keys() |
| | | # # 剔除开1的代码 |
| | | # for b in keys_: |
| | | # history_index, history_before_codes_info = cls.__get_history_index(code, b, yesterday_limit_up_codes, |
| | | # excude_codes) |
| | | # if history_index >= 4: |
| | | # return set(), f"在【{b}】中身位({history_index + 1})靠后" |
| | | |
| | | if not can_buy_blocks: |
| | | msges.clear() |
| | | for b in keys_: |
| | | result = cls.__block_special_codes(code, b, yesterday_limit_up_codes) |
| | | if result[0]: |
| | | can_buy_blocks.add(b) |
| | | msges.append(f"【{b}】:{result[1]}") |
| | | fmsges.append("板块辨识度判断##" + ",".join(msges)) |
| | | else: |
| | | # 首次上板, 只买辨识度 |
| | | if not can_buy_blocks: |
| | | msges.clear() |
| | | for b in keys_: |
| | | result = cls.__block_special_codes(code, b, yesterday_limit_up_codes) |
| | | if result[0]: |
| | | can_buy_blocks.add(b) |
| | | msges.append(f"【{b}】:{result[1]}") |
| | | fmsges.append("板块辨识度判断##" + ",".join(msges)) |
| | | # 判断板块是否不能买 |
| | | if can_buy_blocks: |
| | | msges.clear() |
| | |
| | | return buy_money, before_buy_money, sell_money, before_sell_money |
| | | |
| | | |
| | | def get_total_deal_big_order_info(code, limit_up_price): |
| | | def get_total_deal_big_order_info(code, limit_up_price, is_for_buy=False): |
| | | """ |
| | | 总成交大单啊是否足够 |
| | | @param code: |
| | | @return:(缺少的资金,总成交金额, 要求的大单金额) |
| | | """ |
| | | THRESHOLD_MONEY = BeforeSubDealBigOrderManager().get_big_order_threshold(code) |
| | | |
| | | THRESHOLD_MONEY, is_temp_threshold_money = BeforeSubDealBigOrderManager().get_big_order_threshold_info(code) |
| | | |
| | | TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT = round( |
| | | code_volumn_manager.CodeVolumeManager().get_radical_buy_refer_volume(code, |
| | | limit_up_price) * limit_up_price / 1e8, |
| | |
| | | TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT *= 3.3 |
| | | |
| | | TOTAL_BIG_DEAL_MONEY_THRESHOLD_MONEY = TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT * THRESHOLD_MONEY |
| | | |
| | | if is_for_buy and is_temp_threshold_money: |
| | | # 首次上板买入,大单阈值打3折 |
| | | TOTAL_BIG_DEAL_MONEY_THRESHOLD_MONEY //= 3 |
| | | |
| | | big_order_detail_info = get_total_detal_big_order_details(code) |
| | | deal_big_order_money = big_order_detail_info[0] + big_order_detail_info[1] - big_order_detail_info[2] - \ |
| | |
| | | current_threshold_money = current_threshold_count * 2990000 |
| | | |
| | | # ==========判断总大单成交================ |
| | | total_lack_money_info = get_total_deal_big_order_info(code, limit_up_price) |
| | | total_lack_money_info = get_total_deal_big_order_info(code, limit_up_price, is_for_buy=for_buy) |
| | | total_lack_money, total_deal_money, total_threshold_money = total_lack_money_info[0], total_lack_money_info[1], \ |
| | | total_lack_money_info[2] |
| | | # ===========判断单次大单成交============== |
| | |
| | | @param code_: |
| | | @return: |
| | | """ |
| | | # 只有涨停过的代码才需要拉大单 |
| | | if code_ not in LimitUpDataConstant.get_history_limit_up_codes(): |
| | | return |
| | | response_data = requests.get( |
| | | "http://127.0.0.1:9005/get_big_order_list?code=" + code_) |
| | | r_str = response_data.text |
| | |
| | | return None |
| | | |
| | | |
| | | def is_first_limit_up_buy(code): |
| | | """ |
| | | 是否是首封下单: (下单次数为0+没在涨停代码中) 或者 (处于下单状态 + 下单次数为1,且下单为首次下单) |
| | | @param code: |
| | | @return: |
| | | """ |
| | | is_limit_up = code in LimitUpDataConstant.get_history_limit_up_codes() |
| | | place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code) |
| | | if place_order_count is None: |
| | | place_order_count = 0 |
| | | |
| | | if not is_limit_up and place_order_count == 0: |
| | | return True |
| | | |
| | | # 如果当前代码处于下单状态,就判断下单参数中是否为首封下单 |
| | | trade_state = trade_manager.CodesTradeStateManager().get_trade_state_cache(code) |
| | | if place_order_count == 1: |
| | | if trade_state == trade_constant.TRADE_STATE_BUY_PLACE_ORDER or trade_state == trade_constant.TRADE_STATE_BUY_DELEGATED: |
| | | # 处于下单状态, 需要计算是否为首封下单 |
| | | order_begin_pos = TradePointManager().get_buy_compute_start_data_cache(code) |
| | | if order_begin_pos and order_begin_pos.first_limit_up_buy: |
| | | return True |
| | | return False |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | pass |