| | |
| | | @classmethod |
| | | def get_active_buy_blocks(cls, code): |
| | | """ |
| | | 获取激进买入的板块 |
| | | 获取积极买入的板块 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | if tool.is_sh_code(code): |
| | | # 上证不激进下单 |
| | | # 上证不积极下单 |
| | | return None |
| | | |
| | | current_total_sell_data = L2MarketSellManager().get_current_total_sell_data(code) |
| | | place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code) |
| | | # 只有初次下单 + 总抛压大于500w能激进下单 |
| | | # 只有初次下单 + 总抛压大于500w能积极下单 |
| | | if place_order_count > 0 or current_total_sell_data is None or current_total_sell_data[1] < 500 * 10000: |
| | | return None |
| | | |
| | | if global_util.zyltgb_map.get(code) > 50 * 100000000: |
| | | # 50亿以上的无法激进下单 |
| | | # 50亿以上的无法积极下单 |
| | | return None |
| | | can_buy_result = CodePlateKeyBuyManager.can_buy(code) |
| | | if can_buy_result: |
| | | if can_buy_result[5]: |
| | | return can_buy_result[5] |
| | | elif not can_buy_result[0] and can_buy_result[1]: |
| | | # 10:00:00 前的独苗可激进买入 |
| | | # 10:00:00 前的独苗可积极买入 |
| | | if tool.trade_time_sub(tool.get_now_time_str(), "10:00:00") <= 0: |
| | | return ["独苗"] |
| | | return None |
| | |
| | | code) |
| | | |
| | | if order_begin_pos.MODE_RADICAL == order_begin_pos.mode: |
| | | # 激进下单不判断条件 |
| | | # 积极下单不判断条件 |
| | | can, need_clear_data, reason, is_valid_exec_index = True, False, "激进下单", True |
| | | else: |
| | | can, need_clear_data, reason, is_valid_exec_index = cls.__can_buy_first(code) |
| | |
| | | temps = [] |
| | | temps.extend([f"{x[0]}" for x in can_buy_result[0]]) |
| | | if can_buy_result[5]: |
| | | temps.append(f"激进买入:{can_buy_result[5]}") |
| | | temps.append(f"积极买入:{can_buy_result[5]}") |
| | | info.set_kpl_match_blocks(temps) |
| | | trade_record_log_util.add_place_order_log(code, info) |
| | | except Exception as e: |
| | |
| | | return True, "" |
| | | |
| | | @classmethod |
| | | def __is_on_limit_up_buy(cls, code, buy_exec_index): |
| | | def __is_at_limit_up_buy(cls, code, buy_exec_index=None): |
| | | """ |
| | | 是否是板上放量买 |
| | | @param code: |
| | | @param buy_exec_index: |
| | | @return: |
| | | """ |
| | | total_data = local_today_datas.get(code) |
| | | if buy_exec_index is None: |
| | | # 执行位置为空,就取最近的一条数据 |
| | | buy_exec_index = total_data[-1]["index"] |
| | | latest_exec_indexes = cls.__latest_exec_indexes[code] |
| | | if not latest_exec_indexes: |
| | | latest_exec_indexes = [] |
| | |
| | | # 1.当前成交价为涨停价 |
| | | # 2.距离最近的非板上成交的时间大于一个阈值 |
| | | if abs(limit_up_price - float(trade_price)) < 0.001: |
| | | is_limit_up_buy = cls.__is_on_limit_up_buy(code, order_begin_pos.buy_exec_index) |
| | | is_limit_up_buy = cls.__is_at_limit_up_buy(code, order_begin_pos.buy_exec_index) |
| | | if is_limit_up_buy: |
| | | # 板上买且非加绿 |
| | | # 获取最近的非涨停价成交时间 |
| | |
| | | cls.unreal_buy_dict[code] = (buy_exec_index, capture_time) |
| | | trade_result_manager.virtual_buy_success(code) |
| | | |
| | | # 是否是在板上买 |
| | | @classmethod |
| | | def __is_at_limit_up_buy(cls, code_): |
| | | # 总卖为0,当前成交价为涨停价就判断为板上买 |
| | | current_sell_data = cls.__L2MarketSellManager.get_current_total_sell_data(code_) |
| | | if current_sell_data and tool.trade_time_sub(tool.get_now_time_str(), current_sell_data[0]) < 5: |
| | | # 5s内的数据才有效 |
| | | if current_sell_data[1] <= 0: |
| | | # 总卖为0 |
| | | trade_price = current_price_process_manager.get_trade_price(code_) |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code_) |
| | | if trade_price and limit_up_price and abs(float(trade_price) - float(limit_up_price)) <= 0.001: |
| | | # 当前成交价为涨停价 |
| | | return True |
| | | return False |
| | | def __process_with_find_exec_index(cls, code, order_begin_pos: OrderBeginPosInfo, compute_end_index): |
| | | """ |
| | | 处理找到执行位置 |
| | | @return: |
| | | """ |
| | | total_datas = local_today_datas.get(code) |
| | | l2_log.debug(code, "获取到买入执行位置:{} m值:{} 纯买手数:{} 纯买单数:{} 是否板上买:{} 数据:{} ,量比:{} ,下单模式:{}", |
| | | order_begin_pos.buy_exec_index, |
| | | order_begin_pos.threshold_money, |
| | | order_begin_pos.num, |
| | | order_begin_pos.count, order_begin_pos.at_limit_up, total_datas[order_begin_pos.buy_exec_index], |
| | | cls.volume_rate_info[code], order_begin_pos.mode) |
| | | cls.__save_order_begin_data(code, order_begin_pos) |
| | | cls.__LimitUpTimeManager.save_limit_up_time(code, total_datas[order_begin_pos.buy_exec_index]["val"]["time"]) |
| | | l2_log.debug(code, "delete_buy_cancel_point") |
| | | if code not in cls.__latest_exec_indexes: |
| | | cls.__latest_exec_indexes[code] = [] |
| | | cls.__latest_exec_indexes[code].append(order_begin_pos.buy_exec_index) |
| | | # 保留最近3次的买入执行位置 |
| | | if len(cls.__latest_exec_indexes[code]) > 3: |
| | | cls.__latest_exec_indexes[code] = cls.__latest_exec_indexes[code][-3:] |
| | | |
| | | # 直接下单 |
| | | ordered = cls.__buy(code, 0, total_datas[-1], total_datas[-1]["index"], True) |
| | | |
| | | # 数据是否处理完毕 |
| | | if order_begin_pos.buy_exec_index < compute_end_index: |
| | | if ordered: |
| | | cls.__process_order(code, order_begin_pos.buy_exec_index + 1, compute_end_index, 0, True, |
| | | False) |
| | | else: |
| | | cls.__start_compute_buy(code, order_begin_pos.buy_exec_index + 1, compute_end_index, |
| | | order_begin_pos.threshold_money, |
| | | 0, |
| | | True, False) |
| | | |
| | | @classmethod |
| | | def __start_compute_buy(cls, code, compute_start_index, compute_end_index, threshold_money, capture_time, |
| | |
| | | _start_time = tool.get_now_timestamp() |
| | | total_datas = local_today_datas[code] |
| | | |
| | | # ---------计算激进买入的信号--------- |
| | | radical_result = cls.__compute_radical_order_begin_pos(code, compute_start_index, compute_end_index) |
| | | if radical_result[0]: |
| | | buy_single_index, buy_exec_index = radical_result[1], radical_result[1] |
| | | buy_volume_rate = cls.volume_rate_info[code][0] |
| | | refer_sell_data = cls.__L2MarketSellManager.get_refer_sell_data(code, total_datas[buy_single_index]["val"][ |
| | | "time"]) |
| | | if refer_sell_data: |
| | | sell_info = (refer_sell_data[0], refer_sell_data[1]) |
| | | else: |
| | | sell_info = (total_datas[buy_single_index]["val"]["time"], 0) |
| | | threshold_money = 0 |
| | | |
| | | order_begin_pos_info = OrderBeginPosInfo(buy_single_index=buy_single_index, |
| | | buy_exec_index=buy_exec_index, |
| | | buy_compute_index=buy_exec_index, |
| | | num=total_datas[buy_single_index]["val"]["num"], count=1, |
| | | max_num_set=set(), |
| | | buy_volume_rate=buy_volume_rate, |
| | | mode=OrderBeginPosInfo.MODE_RADICAL, |
| | | mode_desc="激进买入", |
| | | sell_info=sell_info, |
| | | threshold_money=threshold_money) |
| | | order_begin_pos_info.at_limit_up = cls.__is_at_limit_up_buy(code) |
| | | cls.__process_with_find_exec_index(code, order_begin_pos_info, compute_end_index) |
| | | return |
| | | |
| | | # 获取买入信号计算起始位置 |
| | | order_begin_pos = cls.__get_order_begin_pos( |
| | | code) |
| | | order_begin_pos = cls.__get_order_begin_pos(code) |
| | | |
| | | # 是否为新获取到的位置 |
| | | new_get_single = False |
| | | buy_single_index = order_begin_pos.buy_single_index |
| | | if buy_single_index is None: |
| | | # ------------------------------确定信号种类---------------------------------- |
| | | # 第一步:获取激进下单信号 |
| | | # 第一步:获取积极下单信号 |
| | | # if code.find('60') == 0: |
| | | # 激进买 |
| | | # 积极买 |
| | | continue_count = 1 |
| | | has_single, _index, sell_info, single_msg, mode = cls.__compute_active_order_begin_pos(code, continue_count, |
| | | compute_start_index, |
| | |
| | | if new_get_single: |
| | | start_process_index = order_begin_pos.buy_single_index |
| | | |
| | | # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "计算m值大单") |
| | | |
| | | # threshold_money, msg = cls.__get_threshmoney(code) |
| | | |
| | | # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "m值阈值计算") |
| | | |
| | | # 设置为总卖额 |
| | | new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, threshold_money_new, max_num_set_new, not_buy_msg, clear_buy_single = cls.__sum_buy_num_for_order_active( |
| | | code, |
| | |
| | | return |
| | | |
| | | if new_buy_exec_index is not None: |
| | | l2_log.debug(code, "获取到买入执行位置:{} m值:{} 纯买手数:{} 纯买单数:{} 是否板上买:{} 数据:{} ,量比:{} ,下单模式:{}", new_buy_exec_index, |
| | | threshold_money, |
| | | buy_nums, |
| | | buy_count, order_begin_pos.at_limit_up, total_datas[new_buy_exec_index], |
| | | cls.volume_rate_info[code], order_begin_pos.mode) |
| | | cls.__save_order_begin_data(code, OrderBeginPosInfo(buy_single_index=buy_single_index, |
| | | buy_exec_index=new_buy_exec_index, |
| | | buy_compute_index=new_buy_exec_index, |
| | | num=buy_nums, count=buy_count, |
| | | max_num_set=max_num_set_new, |
| | | buy_volume_rate=cls.volume_rate_info[code][0], |
| | | mode=order_begin_pos.mode, |
| | | mode_desc=order_begin_pos.mode_desc, |
| | | sell_info=order_begin_pos.sell_info, |
| | | threshold_money=threshold_money)) |
| | | cls.__LimitUpTimeManager.save_limit_up_time(code, total_datas[new_buy_exec_index]["val"]["time"]) |
| | | l2_log.debug(code, "delete_buy_cancel_point") |
| | | if code not in cls.__latest_exec_indexes: |
| | | cls.__latest_exec_indexes[code] = [] |
| | | cls.__latest_exec_indexes[code].append(new_buy_exec_index) |
| | | # 保留最近3次的买入执行位置 |
| | | if len(cls.__latest_exec_indexes[code]) > 3: |
| | | cls.__latest_exec_indexes[code] = cls.__latest_exec_indexes[code][-3:] |
| | | |
| | | # 直接下单 |
| | | ordered = cls.__buy(code, capture_time, total_datas[-1], total_datas[-1]["index"], is_first_code) |
| | | |
| | | # 数据是否处理完毕 |
| | | if new_buy_exec_index < compute_end_index: |
| | | if ordered: |
| | | cls.__process_order(code, new_buy_exec_index + 1, compute_end_index, capture_time, is_first_code, |
| | | False) |
| | | else: |
| | | cls.__start_compute_buy(code, new_buy_exec_index + 1, compute_end_index, threshold_money, |
| | | capture_time, |
| | | is_first_code, False) |
| | | cls.__process_with_find_exec_index(code, OrderBeginPosInfo(buy_single_index=buy_single_index, |
| | | buy_exec_index=new_buy_exec_index, |
| | | buy_compute_index=new_buy_exec_index, |
| | | num=buy_nums, count=buy_count, |
| | | max_num_set=max_num_set_new, |
| | | buy_volume_rate=cls.volume_rate_info[code][0], |
| | | mode=order_begin_pos.mode, |
| | | mode_desc=order_begin_pos.mode_desc, |
| | | sell_info=order_begin_pos.sell_info, |
| | | threshold_money=threshold_money), |
| | | compute_end_index) |
| | | else: |
| | | # 未达到下单条件,保存纯买额,设置纯买额 |
| | | # 记录买入信号位置 |
| | |
| | | |
| | | return True, i, [refer_sell_data[0], |
| | | 0], '上证买入', OrderBeginPosInfo.MODE_ACTIVE if active_buy_blocks else OrderBeginPosInfo.MODE_FAST |
| | | return False, -1, "未获取到激进买的起始信号", '', OrderBeginPosInfo.MODE_NORMAL |
| | | return False, -1, "未获取到积极买的起始信号", '', OrderBeginPosInfo.MODE_NORMAL |
| | | else: |
| | | # 深证 |
| | | if refer_sell_data is None: |
| | |
| | | # 判断最近有没有涨停卖数据 |
| | | limit_up_sell_count = L2TradeSingleDataProcessor.get_latest_limit_up_sell_order_count(code) |
| | | if (limit_up_sell_count == 0 or active_buy_blocks) and not single: |
| | | # 如果没有涨停卖数据/激进下单而且还没有成交买入信号,就按照原来的总卖额计算 |
| | | # 如果没有涨停卖数据/积极下单而且还没有成交买入信号,就按照原来的总卖额计算 |
| | | threshold_money, sell_1_price = copy.deepcopy(refer_sell_data[1]), refer_sell_data[3][0] |
| | | for i in range(start_index - 1, -1, -1): |
| | | val = total_datas[i]["val"] |
| | |
| | | return True, buy_single_index, [refer_sell_data[0], |
| | | 0], "板上放量", OrderBeginPosInfo.MODE_ACTIVE if active_buy_blocks else OrderBeginPosInfo.MODE_NORMAL |
| | | |
| | | return False, -1, "未获取到激进买的起始信号", '', OrderBeginPosInfo.MODE_NORMAL |
| | | return False, -1, "未获取到积极买的起始信号", '', OrderBeginPosInfo.MODE_NORMAL |
| | | |
| | | # 计算激进买的下单信号 |
| | | @classmethod |
| | |
| | | @param code: |
| | | @param start_index: |
| | | @param end_index: |
| | | @return: (是否获取到信号, 信号位置) |
| | | @return: (是否获取到信号, 信号位置, 消息) |
| | | """ |
| | | # 激进买信号的时间 |
| | | |
| | | |
| | | radical_data = RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict.get(code) |
| | | if not radical_data: |
| | |
| | | if t.time() > radical_data[0]: |
| | | return False, None, "超过生效时间" |
| | | |
| | | |
| | | # 判断是否是板上放量 |
| | | if cls.__is_on_limit_up_buy(code, start_index): |
| | | if cls.__is_at_limit_up_buy(code, start_index): |
| | | return False, None, "板上放量" |
| | | total_datas = local_today_datas[code] |
| | | min_num = int(29900 / gpcode_manager.get_limit_up_price_as_num(code)) |