strategy/buying_strategy.py
@@ -317,13 +317,11 @@
                                        f"【有概念】(涨停列表中包含自身概念 且 不是唯一包含概念不可用) !最新价: {current_price},,当日当时涨幅:{today_growth}%。")
                                    # 有概念有强度视界
                                    if strength_list_have_it is True:
                                        logger_info(
                                            f"【有概念 有强度】出现在板块强度大于2的列表中 瞬时量幅比:{round(last_volume_to_growth_ratio, 2)}%,当日当时涨幅:{today_growth}%。")
                                        logger_info(f"【有概念 有强度】出现在板块强度大于2的列表中 瞬时量幅比:{round(last_volume_to_growth_ratio, 2)}%,当日当时涨幅:{today_growth}%。")
                                        # if tick_growth >= 0.8:
                                        #     logger_info(
                                        #         f"【有概念 有强度 有强拉】瞬时涨幅 > 0.8% !瞬时涨幅:{round(tick_growth, 2)}%")
                                        if last_volume_to_growth_ratio > 0.8 and (
                                                free_market_value < 40 and current_price < 20):
                                        if last_volume_to_growth_ratio > 0.8 and (free_market_value <= 100 and current_price <= 10):
                                            logger_info(
                                                f"【不利】瞬时量幅比> 0.8 且 (小自由市值<40亿 或 最新价小于20元 )!,瞬时量幅比:{round(last_volume_to_growth_ratio, 2)}%,自由市值:{free_market_value} 亿。")
                                            return
@@ -353,8 +351,7 @@
                                            return
                                        # elif k_line_data[0]['attribute'] == 'up_down' and k_line_data[0]['today_volume_shape'] == 'increases_down':
                                        #     logger_info(f"【不利】昨日高开低走 且 放量下跌,不买!!")
                                        if k_line_data[0]['attribute'] == 'down_down' and k_line_data[0][
                                            'today_volume_shape'] == 'increases_down':
                                        if k_line_data[0]['attribute'] == 'down_down' and k_line_data[0]['today_volume_shape'] == 'increases_down':
                                            logger_info(f"【不利】昨日低开低走 且 放量下跌,不买!!")
                                            return
                                        if throwing_pressure_position[0] is True:
@@ -401,7 +398,7 @@
                                        logger_info(
                                            f"************************************************【有概念有强度指标下单】************************************************")
                                        logger_info(
                                            f"最新价: {current_price}, 当日最高价:{current_high},瞬时涨幅: {tick_growth:.2f}%,当日当时涨幅:{today_growth}%,公司名称:{k_line_data[0]['sec_name']},当前时间:{current_created_at},低于水位线:{deep_low:.2f},交易量今日与昨日的比例{round(current_volume / k_line_data[0]['volume'], 2)}")
                                            f"最新价: {current_price}, 当日最高价:{current_high},瞬时涨幅: {tick_growth:.2f}%,瞬时量幅比:{last_volume_to_growth_ratio:.2f}%,当日当时涨幅:{today_growth}%,公司名称:{k_line_data[0]['sec_name']},当前时间:{current_created_at},低于水位线:{deep_low:.2f},交易量今日与昨日的比例{round(current_volume / k_line_data[0]['volume'], 2)}")
                                        logger_info(
                                            f"大盘综合强度分数:{data_cache.real_time_market_strong},理想交易行情分数==={data_cache.ideal_trading_market_score}分,设想的下单金额:{get_order_money()}")
                                        # 调用下单方法下单
@@ -432,83 +429,102 @@
                                                    free_market_value < 40 and current_price < 20):
                                                logger_info(
                                                    f"【不利】瞬时量幅比> 0.8 且 (小自由市值<40亿 或 最新价小于20元 )!,瞬时量幅比:{round(last_volume_to_growth_ratio, 2)}%,自由市值:{free_market_value} 亿。")
                                            elif now_time <= datetime.time(9, 30, 5).strftime("%H:%M:%S"):
                                                return
                                            if now_time <= datetime.time(9, 30, 5).strftime("%H:%M:%S"):
                                                logger_info(
                                                    f"【不利】早盘第一个tick,瞬时涨幅计算恐有误,不买!瞬时量幅比:{round(last_volume_to_growth_ratio, 2)}%,瞬时涨幅: {tick_growth:.2f}%,当日当时涨幅:{today_growth}%。")
                                            elif now_time <= datetime.time(9, 35, 00).strftime("%H:%M:%S"):
                                                return
                                            if now_time <= datetime.time(9, 35, 00).strftime("%H:%M:%S"):
                                                logger_info(
                                                    f"【不利】早盘前5分钟,不做有概念无强度试验,不买!瞬时量幅比:{round(last_volume_to_growth_ratio, 2)}%,瞬时涨幅: {tick_growth:.2f}%,当日当时涨幅:{today_growth}%。")
                                            elif today_growth < 3:
                                                return
                                            if today_growth < 3:
                                                logger_info(
                                                    f"【不利】当日当时涨幅小于3%,信心不足,不太可能有强度,不买!瞬时量幅比:{round(last_volume_to_growth_ratio, 2)}%,瞬时涨幅: {tick_growth:.2f}%,当日当时涨幅:{today_growth}%。")
                                            elif limit_up_day < 1 and tick_growth < 1:
                                                return
                                            if limit_up_day < 1 and tick_growth < 1:
                                                logger_info(
                                                    f"【不利】冷票 且 瞬时涨幅小于 1 !不买!!,瞬时量幅比:{round(last_volume_to_growth_ratio, 2)}%,90天内涨停天数:{limit_up_day}")
                                                return
                                            # for d in k_line_data[1:3] 只检查k_line_data中的第二个和第三个元素
                                            elif limit_up_day > 6 and any(
                                            if limit_up_day > 6 and any(
                                                    'attribute' in d and d['attribute'] in data_cache.limit_up_type
                                                    for d in k_line_data[1:3]) and current_volume <= k_line_data[0][
                                                'volume'] * 1.5:
                                                logger_info(
                                                    f"【不利】过于显著票 且 上日或上上涨停板 当日量还不足昨日量的1.5倍!不买!! 今日当时成交量为昨日等比量的{round(current_volume / k_line_data[0]['volume'], 2)}倍,最新价: {current_price},,90天内涨停天数:{limit_up_day}")
                                            elif k_line_data[0]['attribute'] in data_cache.frying_plate_type:
                                                return
                                            if k_line_data[0]['attribute'] in data_cache.frying_plate_type:
                                                logger_info(f"【不利】昨日炸板!不买!!")
                                            elif k_line_data[0]['attribute'] in data_cache.limit_up_type:
                                                return
                                            if k_line_data[0]['attribute'] in data_cache.limit_up_type:
                                                logger_info(f"【不利】昨日涨停!不买!!")
                                            elif k_line_data[0]['attribute'] in data_cache.limit_down_type:
                                                return
                                            if k_line_data[0]['attribute'] in data_cache.limit_down_type:
                                                logger_info(f"【不利】昨日跌停!不买!!")
                                            # elif k_line_data[0]['attribute'] == 'up_down' and k_line_data[0]['today_volume_shape'] == 'increases_down':
                                            #     logger_info(f"【不利】昨日高开低走 且 放量下跌,不买!!")
                                            elif k_line_data[0]['attribute'] == 'down_down' and k_line_data[0][
                                                return
                                            if k_line_data[0]['attribute'] == 'up_down' and k_line_data[0]['today_volume_shape'] == 'increases_down':
                                                logger_info(f"【不利】昨日高开低走 且 放量下跌,不买!!")
                                                return
                                            if k_line_data[0]['attribute'] == 'down_down' and k_line_data[0][
                                                'today_volume_shape'] == 'increases_down':
                                                logger_info(f"【不利】昨日低开低走 且 放量下跌,不买!!")
                                            elif throwing_pressure_position[0] is True:
                                                return
                                            if throwing_pressure_position[0] is True:
                                                # 最近涨停日期:{k_line_data[limit_up_day_min_index]['bob']} ,
                                                logger_info(
                                                    f"【不利】接近涨停大抛压价位 近7日涨停过票 且 当前价和今日涨停价  且 当日量还不足涨停次日量的1.5倍!且 次日最高价小于涨停最高价的1.02倍 不买!! 今日当时成交量为昨日等比量的{round(current_volume / k_line_data[0]['volume'], 2)}倍,90天内涨停天数:{limit_up_day}")
                                            elif throwing_pressure_position[1] is True:
                                                return
                                            if throwing_pressure_position[1] is True:
                                                # 最近涨停日期:{k_line_data[frying_plate_day_min_index]['bob']} ,炸板次日量{round(k_line_data[frying_plate_day_min_index - 1]['volume'], 2)},
                                                logger_info(
                                                    f"【不利】接近炸板大抛压价位 近7日炸板过票 且 当前价和今日涨停价  且 当日量还不足涨停次日量的1.5倍!且 次日最高价小于炸板最高价的1.02倍 不买!! ,90天内涨停天数:{limit_up_day}")
                                            elif throwing_pressure_position[2] is True:
                                                return
                                            if throwing_pressure_position[2] is True:
                                                # 最近涨停日期:{k_line_data[limit_down_day_min_index]['bob']} ,
                                                logger_info(
                                                    f"【不利】接近跌停大抛压价位[跌停日的最高价或最低价] 近7日跌停过票 且 当前价和今日涨停价  且当日量还不足昨日量的1.5倍!不买!!今日当时成交量为昨日等比量的{round(current_volume / k_line_data[0]['volume'], 2)}倍,90天内涨停天数:{limit_up_day}")
                                            elif (
                                                return
                                            if (
                                                    free_market_value == 0 or free_market_value == 0.0) and free_market_value < 6:
                                                logger_info(
                                                    f"【不利】自由市值小于6亿!不买!! 公司名称:{k_line_data[0]['sec_name']},最新价: {current_price}")
                                            elif (
                                                return
                                            if (
                                                    free_market_value == 0 or free_market_value == 0.0) and free_market_value > 100 and L2_found_big_order is False:
                                                logger_info(
                                                    f"【不利】自由市值大于100亿,且未发现大单!不买!! 公司名称:{k_line_data[0]['sec_name']},最新价: {current_price}")
                                            elif len(intersection_plate) > 0:
                                                return
                                            if len(intersection_plate) > 0:
                                                logger_info(
                                                    f"【不利】同概念只买一次,不买了,公司名称:{k_line_data[0]['sec_name']},重复相交概念==={intersection_plate}")
                                            elif data_cache.have_plate_buy_times >= 1:
                                                return
                                            if data_cache.have_plate_buy_times >= 1:
                                                logger_info(
                                                    f"【不利】有概念无强度买入已经1次了!不买了!!公司名称:{k_line_data[0]['sec_name']},")
                                            elif len(data_cache.addition_position_symbols_set) >= 4:
                                                return
                                            if len(data_cache.addition_position_symbols_set) >= 4:
                                                logger_info(
                                                    f"【不利】当日已经买了3只票!不买了!!公司名称:{k_line_data[0]['sec_name']},")
                                            elif now_time < data_cache.OPENING_TIME or now_time > data_cache.NOON_MARKET_TIME:
                                                return
                                            if now_time < data_cache.OPENING_TIME or now_time > data_cache.NOON_MARKET_TIME:
                                                logger_info(f"【不利】不在9:30-13:05时间内!不买!!")
                                                return
                                            logger_info(
                                                f"************************************************【有概念无强度指标下单】************************************************")
                                            logger_info(
                                                f"最新价: {current_price}, 当日最高价:{current_high},瞬时涨幅: {tick_growth:.2f}%,瞬时量幅比:{last_volume_to_growth_ratio:.2f}%,当日当时涨幅:{today_growth}%,公司名称:{k_line_data[0]['sec_name']},当前时间:{current_created_at},低于水位线:{deep_low:.2f},交易量今日与昨日的比例{round(current_volume / k_line_data[0]['volume'], 2)}")
                                            # 检测持仓代码集合中有无下单个股,才认为交易成功
                                            if symbol_code not in data_cache.position_symbols_set:
                                                logger_info(
                                                    f"【{k_line_data[0]['sec_name']}】交易失败~持仓集合:{data_cache.position_symbols_set}")
                                            else:
                                                # 将有概念买入次数自加1
                                                data_cache.have_plate_buy_times += 1
                                                # 将买入个股的当时概念添加到全局变量中存储
                                                data_cache.bought_plate.extend(limit_up_plate_included_list)
                                                logger_info(
                                                    f"************************************************【有概念无强度指标下单】************************************************")
                                                logger_info(
                                                    f"最新价: {current_price}, 当日最高价:{current_high},瞬时涨幅: {tick_growth:.2f}%,当日当时涨幅:{today_growth}%,公司名称:{k_line_data[0]['sec_name']},当前时间:{current_created_at},低于水位线:{deep_low:.2f},交易量今日与昨日的比例{round(current_volume / k_line_data[0]['volume'], 2)}")
                                                # 检测持仓代码集合中有无下单个股,才认为交易成功
                                                if symbol_code not in data_cache.position_symbols_set:
                                                    logger_info(
                                                        f"【{k_line_data[0]['sec_name']}】交易失败~持仓集合:{data_cache.position_symbols_set}")
                                                else:
                                                    # 将有概念买入次数自加1
                                                    data_cache.have_plate_buy_times += 1
                                                    # 将买入个股的当时概念添加到全局变量中存储
                                                    data_cache.bought_plate.extend(limit_up_plate_included_list)
                                                    logger_info(
                                                        f"【{k_line_data[0]['sec_name']}】交易成功!持仓集合:{data_cache.position_symbols_set}")
                                                    f"【{k_line_data[0]['sec_name']}】交易成功!持仓集合:{data_cache.position_symbols_set}")
                                '''
                                无概念 有强度视界
                                '''
@@ -535,80 +551,90 @@
                                                if limit_up_day < 1:
                                                    logger_info(
                                                        f"【不利】冷票 !不买!!,瞬时量幅比:{round(last_volume_to_growth_ratio, 2)}%,90天内涨停天数:{limit_up_day}")
                                                    return
                                                # for d in k_line_data[1:3] 只检查k_line_data中的第二个和第三个元素
                                                elif limit_up_day > 6 and any(
                                                if limit_up_day > 6 and any(
                                                        'attribute' in d and d['attribute'] in data_cache.limit_up_type
                                                        for d in k_line_data[1:3]) and current_volume <= k_line_data[0][
                                                    'volume'] * 1.5:
                                                        for d in k_line_data[1:3]) and current_volume <= k_line_data[0]['volume'] * 1.5:
                                                    logger_info(
                                                        f"【不利】过于显著票 且 上日或上上涨停板 当日量还不足昨日量的1.5倍!不买!! 今日当时成交量为昨日等比量的{round(current_volume / k_line_data[0]['volume'], 2)}倍,90天内涨停天数:{limit_up_day}")
                                                elif k_line_data[0]['attribute'] in data_cache.frying_plate_type:
                                                    return
                                                if k_line_data[0]['attribute'] in data_cache.frying_plate_type:
                                                    logger_info(f"【不利】昨日炸板!不买!!")
                                                elif k_line_data[0]['attribute'] in data_cache.limit_up_type:
                                                    return
                                                if k_line_data[0]['attribute'] in data_cache.limit_up_type:
                                                    logger_info(f"【不利】昨日涨停!不买!!")
                                                elif k_line_data[0]['attribute'] in data_cache.limit_down_type:
                                                    return
                                                if k_line_data[0]['attribute'] in data_cache.limit_down_type:
                                                    logger_info(f"【不利】昨日跌停!不买!!")
                                                # elif k_line_data[0]['attribute'] == 'up_down' and k_line_data[0]['today_volume_shape'] == 'increases_down':
                                                    return
                                                # if k_line_data[0]['attribute'] == 'up_down' and k_line_data[0]['today_volume_shape'] == 'increases_down':
                                                #     logger_info(
                                                #         f"【不利】昨日高开低走 且 放量下跌,不买!!")
                                                elif k_line_data[0]['attribute'] == 'down_down' and k_line_data[0][
                                                    'today_volume_shape'] == 'increases_down':
                                                    logger_info(
                                                        f"【不利】昨日低开低走 且 放量下跌,不买!!")
                                                elif throwing_pressure_position[0] is True:
                                                #     return
                                                if k_line_data[0]['attribute'] == 'down_down' and k_line_data[0]['today_volume_shape'] == 'increases_down':
                                                    logger_info(f"【不利】昨日低开低走 且 放量下跌,不买!!")
                                                    return
                                                if throwing_pressure_position[0] is True:
                                                    # 最近涨停日期:{k_line_data[limit_up_day_min_index]['bob']} ,
                                                    logger_info(
                                                        f"【不利】接近涨停大抛压价位 近7日涨停过票 且 当前价和今日涨停价 且 当日量还不足涨停次日量的1.5倍!且 次日最高价小于涨停最高价的1.02倍 不买!! 今日当时成交量为昨日等比量的{round(current_volume / k_line_data[0]['volume'], 2)}倍,90天内涨停天数:{limit_up_day}")
                                                elif throwing_pressure_position[1] is True:
                                                    return
                                                if throwing_pressure_position[1] is True:
                                                    # 最近涨停日期:{k_line_data[frying_plate_day_min_index]['bob']} ,炸板次日量{round(k_line_data[frying_plate_day_min_index - 1]['volume'], 2)},
                                                    logger_info(
                                                        f"【不利】接近炸板大抛压价位 近7日炸板过票 且 当前价和今日涨停价 且 当日量还不足涨停次日量的1.5倍!且 次日最高价小于炸板最高价的1.02倍 不买!!90天内涨停天数:{limit_up_day}")
                                                elif throwing_pressure_position[2] is True:
                                                    return
                                                if throwing_pressure_position[2] is True:
                                                    # 最近涨停日期:{k_line_data[limit_down_day_min_index]['bob']} ,
                                                    logger_info(
                                                        f"【不利】接近跌停大抛压价位[跌停日的最高价或最低价] 近7日跌停过票 且 当前价和今日涨停价 且当日量还不足昨日量的1.5倍!不买!!今日当时成交量为昨日等比量的{round(current_volume / k_line_data[0]['volume'], 2)}倍,,90天内涨停天数:{limit_up_day}")
                                                elif (
                                                        free_market_value == 0 or free_market_value == 0.0) and free_market_value < 6:
                                                    return
                                                if (free_market_value == 0 or free_market_value == 0.0) and free_market_value < 6:
                                                    logger_info(
                                                        f"【不利】自由市值小于6亿!不买!! 公司名称:{k_line_data[0]['sec_name']},最新价: {current_price}")
                                                elif have_leading_increase is False:
                                                    return
                                                if have_leading_increase is False:
                                                    logger_info(
                                                        f"【不利】有强度的板块中没有发现领涨次数!不买!! 公司名称:{k_line_data[0]['sec_name']},最新价: {current_price}")
                                                elif (
                                                        free_market_value == 0 or free_market_value == 0.0) and free_market_value > 100 and L2_found_big_order is False:
                                                    return
                                                if (free_market_value == 0 or free_market_value == 0.0) and free_market_value > 100 and L2_found_big_order is False:
                                                    logger_info(
                                                        f"【不利】自由市值大于100亿,且未发现大单!不买!! 公司名称:{k_line_data[0]['sec_name']},最新价: {current_price}")
                                                elif data_cache.have_strength_buy_times >= 1:
                                                    return
                                                if data_cache.have_strength_buy_times >= 1:
                                                    logger_info(
                                                        f"【不利】有强度买入 1 次了!不买了!!公司名称:{k_line_data[0]['sec_name']},")
                                                elif len(TodayBuyCodeManager().get_buy_codes()) >= 3:
                                                    return
                                                if len(TodayBuyCodeManager().get_buy_codes()) >= 3:
                                                    logger_info(
                                                        f"【不利】当日已经买了3只票!不买了!!公司名称:{k_line_data[0]['sec_name']},")
                                                elif now_time < data_cache.OPENING_TIME or now_time > data_cache.NOON_MARKET_TIME:
                                                    return
                                                if now_time < data_cache.OPENING_TIME or now_time > data_cache.NOON_MARKET_TIME:
                                                    logger_info(f"【不利】不在9:30-13:05时间内!不买!!")
                                                    return
                                                logger_info(
                                                    f"************************************************【有强度有强拉指标下单】************************************************")
                                                logger_info(
                                                    f"最新价: {current_price}, 当日最高价:{current_high},瞬时涨幅: {tick_growth:.2f}%,瞬时量幅比:{last_volume_to_growth_ratio:.2f}%,当日当时涨幅:{today_growth}%,公司名称:{k_line_data[0]['sec_name']},当前时间:{current_created_at},低于水位线:{deep_low:.2f},交易量今日与昨日的比例{round(current_volume / k_line_data[0]['volume'], 2)}")  # 输出当前价格和3秒涨幅信息
                                                logger_info(
                                                    f"大盘综合强度分数:{data_cache.real_time_market_strong},理想交易行情分数==={data_cache.ideal_trading_market_score}分,设想的下单金额:{get_order_money()}")
                                                # 调用下单方法下单
                                                order_methods.buy_order_by_value(symbol,
                                                                                 get_order_money(),
                                                                                 k_line_data[0]['sec_name'],
                                                                                 current_price)
                                                # 检测持仓代码集合中有无下单个股,才认为交易成功
                                                if symbol_code not in data_cache.position_symbols_set:
                                                    logger_info(
                                                        f"【{k_line_data[0]['sec_name']}】交易失败~持仓集合:{data_cache.position_symbols_set}")
                                                else:
                                                    # 将有概念买入次数自加1
                                                    data_cache.have_strength_buy_times += 1
                                                    # 将买入个股的当时概念添加到全局变量中存储
                                                    data_cache.bought_plate.extend(strength_plate)
                                                    logger_info(
                                                        f"************************************************【有强度有强拉指标下单】************************************************")
                                                    logger_info(
                                                        f"最新价: {current_price}, 当日最高价:{current_high},瞬时涨幅: {tick_growth:.2f}%,当日当时涨幅:{today_growth}%,公司名称:{k_line_data[0]['sec_name']},当前时间:{current_created_at},低于水位线:{deep_low:.2f},交易量今日与昨日的比例{round(current_volume / k_line_data[0]['volume'], 2)}")  # 输出当前价格和3秒涨幅信息
                                                    logger_info(
                                                        f"大盘综合强度分数:{data_cache.real_time_market_strong},理想交易行情分数==={data_cache.ideal_trading_market_score}分,设想的下单金额:{get_order_money()}")
                                                    # 调用下单方法下单
                                                    order_methods.buy_order_by_value(symbol,
                                                                                     get_order_money(),
                                                                                     k_line_data[0]['sec_name'],
                                                                                     current_price)
                                                    # 检测持仓代码集合中有无下单个股,才认为交易成功
                                                    if symbol_code not in data_cache.position_symbols_set:
                                                        logger_info(
                                                            f"【{k_line_data[0]['sec_name']}】交易失败~持仓集合:{data_cache.position_symbols_set}")
                                                    else:
                                                        # 将有概念买入次数自加1
                                                        data_cache.have_strength_buy_times += 1
                                                        # 将买入个股的当时概念添加到全局变量中存储
                                                        data_cache.bought_plate.extend(strength_plate)
                                                        logger_info(
                                                            f"【{k_line_data[0]['sec_name']}】交易成功!持仓集合:{data_cache.position_symbols_set}")
                                                        f"【{k_line_data[0]['sec_name']}】交易成功!持仓集合:{data_cache.position_symbols_set}")
                                '''
                                无概念无强度 有小量换大涨幅度视界
                                '''
@@ -709,7 +735,6 @@
                                                        data_cache.bought_plate.extend(k_line_data[0]['sec_name'])
                                                        logger_info(
                                                            f"【{k_line_data[0]['sec_name']}】交易成功!持仓集合:{data_cache.position_symbols_set}")
                                '''
                                昨日涨停视界,今日连板预期盯视界
                                '''