| | |
| | | from l2.l2_data_util import local_today_datas, L2DataUtil, local_today_num_operate_map, local_today_buyno_map, \ |
| | | local_latest_datas, local_today_canceled_buyno_map |
| | | import l2.l2_data_util |
| | | from log_module.log import logger_l2_trade_buy, logger_l2_process, logger_l2_error, logger_debug |
| | | from log_module.log import logger_l2_trade_buy, logger_l2_process, logger_l2_error, logger_debug, \ |
| | | logger_l2_not_buy_reasons |
| | | |
| | | from trade.trade_data_manager import CodeActualPriceProcessor, PlaceOrderCountManager |
| | | |
| | |
| | | # 是否是强势30分钟 |
| | | is_in_strong_time_30 = now_timestamp <= int("100000") |
| | | |
| | | |
| | | # 量参考是否在最近30天 |
| | | # is_refer_volume_date_in_30_days = False |
| | | # try: |
| | |
| | | # is_refer_volume_date_in_30_days = True |
| | | # except: |
| | | # pass |
| | | |
| | | if k_format and (k_format[1][0] or k_format[3][0]) and len(k_format) >= 12 and k_format[11]: |
| | | # 破前高/接近前高且30天内有涨停 |
| | | if code in cls.volume_rate_info and cls.volume_rate_info[code][0] < volume_rate_thresholds[1]: |
| | | return False, True, f"股价创新高或者逼近前高且30天内有涨停,当日量比({cls.volume_rate_info[code][0]})小于{volume_rate_thresholds[1]}" |
| | | |
| | | # 获取市场行情 |
| | | situation = cls.__MarketSituationManager.get_situation_cache() |
| | |
| | | if is_in_strong_time_30 and is_best_zylt and can_buy_result[0]: |
| | | # 强势30分钟,最优市值, 有可以下单的板块,不看量 |
| | | return True, False, can_buy_result[2] |
| | | |
| | | if k_format and (k_format[1][0] or k_format[3][0]) and len(k_format) >= 12 and k_format[11]: |
| | | # 破前高/接近前高且30天内有涨停 |
| | | if code in cls.volume_rate_info and cls.volume_rate_info[code][0] < volume_rate_thresholds[1]: |
| | | return False, True, f"股价创新高或者逼近前高且30天内有涨停,当日量比({cls.volume_rate_info[code][0]})小于{volume_rate_thresholds[1]}" |
| | | |
| | | if HighIncreaseCodeManager().is_in(code): |
| | | if code in cls.volume_rate_info and cls.volume_rate_info[code][0] < 0.8: |
| | |
| | | # _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, max_num_set_new = None, None, None, None, [] |
| | | new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, max_num_set_new, not_buy_msg = None, None, None, None, [], "" |
| | | if order_begin_pos.mode == OrderBeginPosInfo.MODE_FAST: |
| | | |
| | | threshold_money = order_begin_pos.threshold_money |
| | | new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, threshold_money_new = cls.__sum_buy_num_for_order_fast( |
| | | new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, threshold_money_new, not_buy_msg = cls.__sum_buy_num_for_order_fast( |
| | | code, |
| | | start_process_index, |
| | | compute_end_index, |
| | |
| | | threshold_money = threshold_money_new |
| | | order_begin_pos.threshold_money = threshold_money |
| | | else: |
| | | new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, max_num_set_new = cls.__sum_buy_num_for_order_3( |
| | | new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, max_num_set_new, not_buy_msg = cls.__sum_buy_num_for_order_3( |
| | | code, |
| | | start_process_index, |
| | | compute_end_index, |
| | |
| | | max_num_set=max_num_set_new, mode=order_begin_pos.mode, |
| | | sell_info=order_begin_pos.sell_info, |
| | | threshold_money=threshold_money)) |
| | | # 记录没下单原因 |
| | | async_log_util.info(logger_l2_not_buy_reasons, f"{code}#{not_buy_msg}") |
| | | _start_time = t.time() |
| | | l2_data_log.l2_time_log(code, "__start_compute_buy 结束") |
| | | |
| | |
| | | # 较大单的手数 |
| | | bigger_num = round(5000 / limit_up_price) |
| | | |
| | | not_buy_msg = "" |
| | | for i in range(compute_start_index, compute_end_index + 1): |
| | | data = total_datas[i] |
| | | _val = total_datas[i]["val"] |
| | |
| | | cls.__TradePointManager.delete_buy_point(code) |
| | | if i == compute_end_index: |
| | | # 数据处理完毕 |
| | | return None, buy_nums, buy_count, None, max_buy_num_set |
| | | return None, buy_nums, buy_count, None, max_buy_num_set, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms" |
| | | else: |
| | | # 计算买入信号,不能同一时间开始计算 |
| | | for ii in range(buy_single_index + 1, compute_end_index + 1): |
| | | if total_datas[buy_single_index]["val"]["time"] != total_datas[ii]["val"]["time"]: |
| | | return None, buy_nums, buy_count, ii, max_buy_num_set |
| | | return None, buy_nums, buy_count, ii, max_buy_num_set, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms" |
| | | # 涨停买 |
| | | if L2DataUtil.is_limit_up_price_buy(_val): |
| | | if l2_data_util.is_big_money(_val): |
| | |
| | | max_buy_num_set_count = 0 |
| | | for i1 in max_buy_num_set: |
| | | max_buy_num_set_count += total_datas[i1]["re"] |
| | | # 有撤单信号,且小于阈值 |
| | | if buy_nums >= threshold_num and buy_count >= threshold_count and trigger_buy and max_buy_num_set_count >= big_num_count: |
| | | try: |
| | | info = cls.__trade_log_placr_order_info_dict[code] |
| | | info.set_trade_factor(threshold_money, threshold_count, list(max_buy_num_set)) |
| | | except Exception as e: |
| | | async_log_util.error(logger_l2_error, f"记录交易因子出错:{str(e)}") |
| | | |
| | | return i, buy_nums, buy_count, None, max_buy_num_set |
| | | if buy_nums < threshold_num: |
| | | not_buy_msg = f"【{i}】纯买额不足,{buy_nums}/{threshold_num}" |
| | | continue |
| | | |
| | | if buy_count < threshold_count: |
| | | not_buy_msg = f"【{i}】安全笔数不够,{buy_count}/{threshold_count}" |
| | | continue |
| | | |
| | | if not trigger_buy: |
| | | not_buy_msg = f"【{i}】没有买单触发" |
| | | continue |
| | | |
| | | if max_buy_num_set_count < big_num_count: |
| | | not_buy_msg = f"【{i}】大单数量不足,{max_buy_num_set_count}/{big_num_count}" |
| | | continue |
| | | |
| | | try: |
| | | info = cls.__trade_log_placr_order_info_dict[code] |
| | | info.set_trade_factor(threshold_money, threshold_count, list(max_buy_num_set)) |
| | | except Exception as e: |
| | | async_log_util.error(logger_l2_error, f"记录交易因子出错:{str(e)}") |
| | | |
| | | return i, buy_nums, buy_count, None, max_buy_num_set, "可以下单" |
| | | |
| | | l2_log.buy_debug(code, "尚未获取到买入执行点,起始计算位置:{} 统计纯买手数:{} 目标纯买手数:{} 统计纯买单数:{} 目标纯买单数:{} 大单数量:{} 目标大单数量:{}", |
| | | compute_start_index, |
| | | buy_nums, |
| | | threshold_num, buy_count, threshold_count, max_buy_num_set_count, big_num_count) |
| | | |
| | | return None, buy_nums, buy_count, None, max_buy_num_set |
| | | return None, buy_nums, buy_count, None, max_buy_num_set, not_buy_msg |
| | | |
| | | # 返回(买入执行点, 总手, 总笔数, 从新计算起点, 纯买额阈值) |
| | | # 计算快速买入 |
| | |
| | | trigger_buy = True |
| | | # 间隔最大时间为3s |
| | | max_space_time_ms = 3 * 1000 |
| | | # 不下单的信息 |
| | | not_buy_msg = "" |
| | | for i in range(compute_start_index, compute_end_index + 1): |
| | | data = total_datas[i] |
| | | _val = total_datas[i]["val"] |
| | |
| | | cls.__TradePointManager.delete_buy_point(code) |
| | | if i == compute_end_index: |
| | | # 数据处理完毕 |
| | | return None, buy_nums, buy_count, None, threshold_money |
| | | return None, buy_nums, buy_count, None, threshold_money, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms" |
| | | else: |
| | | # 计算买入信号,不能同一时间开始计算 |
| | | for ii in range(buy_single_index + 1, compute_end_index + 1): |
| | | if total_datas[buy_single_index]["val"]["time"] != total_datas[ii]["val"]["time"]: |
| | | return None, buy_nums, buy_count, ii, threshold_money |
| | | return None, buy_nums, buy_count, ii, threshold_money, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms" |
| | | if L2DataUtil.is_sell(_val): |
| | | threshold_money += _val["num"] * int(float(_val["price"]) * 100) |
| | | threshold_num = round(threshold_money / (limit_up_price * 100)) |
| | |
| | | l2_log.buy_debug(code, "位置-{},总手数:{},目标手数:{}", i, |
| | | buy_nums, threshold_num) |
| | | # 纯买额足够,且笔数大于5笔 |
| | | if buy_nums >= threshold_num and trigger_buy and buy_count >= 5: |
| | | try: |
| | | info = cls.__trade_log_placr_order_info_dict[code] |
| | | info.set_trade_factor(threshold_money, 0, []) |
| | | except Exception as e: |
| | | async_log_util.error(logger_l2_error, f"记录交易因子出错:{str(e)}") |
| | | if buy_nums < threshold_num: |
| | | not_buy_msg = f"【{i}】纯买额不够,{buy_nums}/{threshold_num}" |
| | | continue |
| | | if not trigger_buy: |
| | | not_buy_msg = f"【{i}】没有买单触发" |
| | | continue |
| | | if buy_count < 5: |
| | | not_buy_msg = f"【{i}】安全笔数不足,{buy_count}/{5}" |
| | | continue |
| | | try: |
| | | info = cls.__trade_log_placr_order_info_dict[code] |
| | | info.set_trade_factor(threshold_money, 0, []) |
| | | except Exception as e: |
| | | async_log_util.error(logger_l2_error, f"记录交易因子出错:{str(e)}") |
| | | |
| | | return i, buy_nums, buy_count, None, threshold_money |
| | | return i, buy_nums, buy_count, None, threshold_money, "可以下单" |
| | | |
| | | l2_log.buy_debug(code, "尚未获取到买入执行点(快速买入),起始计算位置:{} 统计纯买手数:{} 目标纯买手数:{} 统计纯买单数:{}", |
| | | compute_start_index, |
| | | buy_nums, |
| | | threshold_num, buy_count) |
| | | |
| | | return None, buy_nums, buy_count, None, threshold_money |
| | | return None, buy_nums, buy_count, None, threshold_money, not_buy_msg |
| | | |
| | | |
| | | def test_trade_record(): |