admin
3 天以前 084d7337165d6d17b77392054c984dbf9916169a
strategy/buying_strategy.py
@@ -8,6 +8,8 @@
# from datetime import time
# from datetime import timedelta
import time
import constant
import utils.tool
from log_module import async_log_util
from log_module.log import logger_kpl_jingxuan_in, logger_common
@@ -18,6 +20,7 @@
from strategy import basic_methods
from strategy import account_management
from strategy import order_methods
from strategy.forbidden_plates_manager import ForbiddenPlatesManager
from strategy.order_methods import TodayBuyCodeManager
from utils import tool, huaxin_util
@@ -218,10 +221,9 @@
                #     print(f"没有在概念缓存列表中找到:{symbol_to_search}。")
                # 声明要检查过滤不可用的概念板块名称常量   【代表着 是否有无概念及跟随概念的可能性(有明显个股独特增长特性的不可跟随,因为概念本身是宽泛的,许多不同概念的个股都有这个概念)】
                check_plate_list = {'无', 'ST摘帽', 'ST板块', '超跌', '次新股', '北交所', '科创板',
                                    '年报增长', '年报预增', '并购重组', '股权转让', '送转填权', '高送转', '壳资源',
                                    '资产管理', '举牌',
                                    '专用设备', '创投'}
                # set(ForbiddenPlatesManager().list_plates() 将GUI上手动添加的拉黑概念也并入其中
                check_plate_list = constant.check_plate_list | set(ForbiddenPlatesManager().list_plates())
                # check_plate_list = constant.check_plate_list
                # 查询当前个股的代码是否在板块强度个股列表中(低吸优选目标)
                strength_list_have_it = False  # 是否有强度赋初值
@@ -247,6 +249,7 @@
                                    async_log_util.info(logger,
                                                        f"单一板块内瞬时拉升数为:{len(values)},分别为===={values}")
                                    # 如果子列表长度大于1且第二个元素包含 当前进入涨幅视界的symbol_code
                                    # 有强度视界
                                    strength_list_have_it = True
                                    strength_plate = correlation_plate_list
                                if stock_list[6] >= 1:
@@ -321,7 +324,7 @@
                                        if tick_growth < 0.5 and (free_market_value <= 100 and current_price <= 10):
                                            logger_info(f"【有概念 有强度 无强拉】瞬时涨幅 < 0.5% !瞬时涨幅:{round(tick_growth, 2)}%")
                                            return
                                        if last_volume_to_growth_ratio > 0.8 and (free_market_value <= 100 and current_price <= 10):
                                        if last_volume_to_growth_ratio > 0.8 and (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} 亿。")
                                            return
                                        if now_time <= datetime.time(9, 30, 5).strftime("%H:%M:%S"):
@@ -351,7 +354,7 @@
                                        # 调用充分交易量函数
                                        sufficient_volume = basic_methods.sufficient_volume(current_volume, k_line_data[0]['volume'], today_growth)
                                        logger_info(
                                            f"【{k_line_data[0]['sec_name']}】当日当时量是否相对涨幅充足?===【{sufficient_volume}】 !当时与昨日成交率占比:{round(current_volume / k_line_data[0]['volume'] / 100, 2)}%,当日当时总成交量:{round(current_volume / 10000, 2)}万,昨日的总成交量{round(k_line_data[0]['volume'] / 10000, 2)}万,当日当时涨幅:{today_growth}%。")
                                            f"【{k_line_data[0]['sec_name']}】当日当时量是否相对涨幅充足?===【{sufficient_volume}】 !当时与昨日成交率占比:{(current_volume / k_line_data[0]['volume'])}%,当日当时总成交量:{round(current_volume / 10000, 2)}万,昨日的总成交量{round(k_line_data[0]['volume'] / 10000, 2)}万,当日当时涨幅:{today_growth}%。")
                                        # 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':
@@ -377,8 +380,7 @@
                                            logger_info(
                                                f"【不利】自由市值小于6亿!不买!! 公司名称:{k_line_data[0]['sec_name']},最新价: {current_price}")
                                            return
                                        if (
                                                free_market_value == 0 or free_market_value == 0.0) and free_market_value > 100 and L2_found_big_order is False:
                                        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}")
                                            return
@@ -386,12 +388,13 @@
                                            logger_info(
                                                f"【不利】当日成交量小于昨日成交量的{ratios}倍!不买!!公司名称:{k_line_data[0]['sec_name']},当日当时总成交量:{current_volume},最新价: {current_price}")
                                            return
                                        data_cache.willing_buy_list.append(k_line_data[0]['sec_name'])
                                        logger_info(f"当前有意购买:{k_line_data[0]['sec_name']},有意购买列表:{data_cache.willing_buy_list}")
                                        willing_buy_times = basic_methods.count_willing_buy_times(k_line_data[0]['sec_name'])
                                        if data_cache.have_plate_buy_times >= 1 and willing_buy_times < 2:
                                            logger_info(
                                                f"【不利】有概念买入已经 1 次,且进入有意购买列表次数<2,不买了!!公司名称:{k_line_data[0]['sec_name']},")
                                        data_cache.willing_buy_list.append(k_line_data[0]['sec_name'])
                                        logger_info(f"当前有意购买:{k_line_data[0]['sec_name']},有意购买列表:{data_cache.willing_buy_list}")
                                                f"【不利因素】有概念买入已经 1 次,且进入有意购买列表次数<2,不买了!!公司名称:{k_line_data[0]['sec_name']},")
                                        #     return
                                        if len(intersection_plate) > 0:
                                            logger_info(
                                                f"【不利】同概念只买一次,不买了,公司名称:{k_line_data[0]['sec_name']},重复相交概念==={intersection_plate}")
@@ -418,6 +421,16 @@
                                                                         get_order_money(),
                                                                         k_line_data[0]['sec_name'],
                                                                         current_price)
                                        # 传给GUI显示
                                        purchased_stock_details = {
                                            "name": k_line_data[0]['sec_name'],
                                            "policy_name": "有概念有强度策略分支",
                                            "plate_name": list(limit_up_plate_included),
                                            "buy_time_trading_volume_ratio": (
                                                        current_volume / k_line_data[0]['volume']),
                                        }
                                        data_cache.purchased_stocks_details_list.append(purchased_stock_details)
                                        logger_info(f"已成交股票详情列表:{data_cache.purchased_stocks_details_list} ")
                                        # 检测持仓代码集合中有无下单个股,才认为交易成功
                                        if symbol_code not in data_cache.position_symbols_set:
                                            logger_info(
@@ -429,7 +442,6 @@
                                            data_cache.bought_plate.extend(limit_up_plate_included_list)
                                            logger_info(
                                                f"【{k_line_data[0]['sec_name']}】交易成功!持仓集合:{data_cache.position_symbols_set}")
                                    # 有概念无强度视界
                                    if strength_list_have_it is False:
                                        logger_info(
@@ -476,9 +488,9 @@
                                                logger_info(f"【不利】昨日跌停!不买!!")
                                                return
                                            # 调用充分交易量函数
                                            sufficient_volume = basic_methods.sufficient_volume(current_volume,k_line_data[0]['volume'],today_growth)
                                            sufficient_volume = basic_methods.sufficient_volume(current_volume, k_line_data[0]['volume'], today_growth)
                                            logger_info(
                                                f"【{k_line_data[0]['sec_name']}】当日当时量是否相对涨幅充足?===【{sufficient_volume}】 !当时与昨日成交率占比:{round(current_volume / k_line_data[0]['volume'] / 100, 2)}%,当日当时总成交量:{round(current_volume / 10000, 2)}万,昨日的总成交量{round(k_line_data[0]['volume'] / 10000, 2)}万,当日当时涨幅:{today_growth}%。")
                                                f"【{k_line_data[0]['sec_name']}】当日当时量是否相对涨幅充足?===【{sufficient_volume}】 !当时与昨日成交率占比:{(current_volume / k_line_data[0]['volume'])}%,当日当时总成交量:{round(current_volume / 10000, 2)}万,昨日的总成交量{round(k_line_data[0]['volume'] / 10000, 2)}万,当日当时涨幅:{today_growth}%。")
                                            if k_line_data[0]['attribute'] == 'up_down' and k_line_data[0]['today_volume_shape'] == 'increases_down':
                                                logger_info(f"【不利】昨日高开低走 且 放量下跌,不买!!")
                                                return
@@ -506,8 +518,7 @@
                                                logger_info(
                                                    f"【不利】自由市值小于6亿!不买!! 公司名称:{k_line_data[0]['sec_name']},最新价: {current_price}")
                                                return
                                            if (
                                                    free_market_value == 0 or free_market_value == 0.0) and free_market_value > 100 and L2_found_big_order is False:
                                            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}")
                                                return
@@ -530,6 +541,17 @@
                                                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)}")
                                            # 传给GUI显示
                                            purchased_stock_details = {
                                                "name": k_line_data[0]['sec_name'],
                                                "policy_name": "有概念无强度策略分支",
                                                "plate_name": list(limit_up_plate_included),
                                                "buy_time_trading_volume_ratio": (
                                                        current_volume / k_line_data[0]['volume']),
                                            }
                                            data_cache.purchased_stocks_details_list.append(purchased_stock_details)
                                            logger_info(
                                                f"已成交股票详情列表:{data_cache.purchased_stocks_details_list} ")
                                            # 检测持仓代码集合中有无下单个股,才认为交易成功
                                            if symbol_code not in data_cache.position_symbols_set:
                                                logger_info(
@@ -541,12 +563,13 @@
                                                data_cache.bought_plate.extend(limit_up_plate_included_list)
                                                logger_info(
                                                    f"【{k_line_data[0]['sec_name']}】交易成功!持仓集合:{data_cache.position_symbols_set}")
                                '''
                                无概念 有强度视界
                                '''
                                if len(limit_up_plate_included) == 0 or limit_up_plate_included.issubset(
                                        check_plate_list) is True:
                                    # logger_info(f"【无概念】")
                                    # logger_info(f"【无概念 或 概念在屏蔽概念组中】")
                                    if strength_list_have_it is True:
                                        logger_info(
                                            f"【{k_line_data[0]['sec_name']}】--------------------------------------------------------------------------------------------------------[有强度视界]")
@@ -558,7 +581,7 @@
                                        intersection_plate = bought_plate_set.intersection(strength_plate_set)
                                        if len(intersection_plate) > 0:
                                            logger_info(f"重复相交强度==={intersection_plate}")
                                        if last_volume_to_growth_ratio < 1:
                                        if last_volume_to_growth_ratio < 0.8:
                                            logger_info(
                                                f"【有强度 有小量换大涨幅】瞬时量幅比< 1 !瞬时量幅比:{round(last_volume_to_growth_ratio, 2)}%,最新价: {current_price},瞬时涨幅:{round(tick_growth, 2)}%,当日当时涨幅:{today_growth}%,当前时间:{current_created_at}。")
                                            if tick_growth >= 1 and today_growth >= 1:
@@ -587,7 +610,7 @@
                                                # 调用充分交易量函数
                                                sufficient_volume = basic_methods.sufficient_volume(current_volume, k_line_data[0]['volume'], today_growth)
                                                logger_info(
                                                    f"【{k_line_data[0]['sec_name']}】当日当时量是否相对涨幅充足?===【{sufficient_volume}】 !当时与昨日成交率占比:{round(current_volume / k_line_data[0]['volume'] / 100, 2)}%,当日当时总成交量:{round(current_volume / 10000, 2)}万,昨日的总成交量{round(k_line_data[0]['volume'] / 10000, 2)}万,当日当时涨幅:{today_growth}%。")
                                                    f"【{k_line_data[0]['sec_name']}】当日当时量是否相对涨幅充足?===【{sufficient_volume}】 !当时与昨日成交率占比:{(current_volume / k_line_data[0]['volume'])}%,当日当时总成交量:{round(current_volume / 10000, 2)}万,昨日的总成交量{round(k_line_data[0]['volume'] / 10000, 2)}万,当日当时涨幅:{today_growth}%。")
                                                # if k_line_data[0]['attribute'] == 'up_down' and k_line_data[0]['today_volume_shape'] == 'increases_down':
                                                #     logger_info(
                                                #         f"【不利】昨日高开低走 且 放量下跌,不买!!")
@@ -618,7 +641,7 @@
                                                #     logger_info(
                                                #         f"【不利】有强度的板块中没有发现领涨次数!不买!! 公司名称:{k_line_data[0]['sec_name']},最新价: {current_price}")
                                                #     return
                                                if (free_market_value == 0 or free_market_value == 0.0) and free_market_value > 100 and L2_found_big_order is False:
                                                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}")
                                                    return
@@ -644,6 +667,18 @@
                                                                                 get_order_money(),
                                                                                 k_line_data[0]['sec_name'],
                                                                                 current_price)
                                                # 传给GUI显示
                                                purchased_stock_details = {
                                                    "name": k_line_data[0]['sec_name'],
                                                    "policy_name": "无概念有强度策略分支",
                                                    "plate_name": list(strength_plate),
                                                    "buy_time_trading_volume_ratio": (
                                                            current_volume / k_line_data[0]['volume']),
                                                }
                                                data_cache.purchased_stocks_details_list.append(
                                                    purchased_stock_details)
                                                logger_info(
                                                    f"已成交股票详情列表:{data_cache.purchased_stocks_details_list} ")
                                                # 检测持仓代码集合中有无下单个股,才认为交易成功
                                                if symbol_code not in data_cache.position_symbols_set:
                                                    logger_info(
@@ -655,6 +690,7 @@
                                                    data_cache.bought_plate.extend(strength_plate)
                                                    logger_info(
                                                        f"【{k_line_data[0]['sec_name']}】交易成功!持仓集合:{data_cache.position_symbols_set}")
                                '''
                                无概念无强度 有小量换大涨幅度视界
                                '''