admin
2025-04-03 afa67819ac4c995cb0dbe0cba16c73ddaae3bcb6
不是目标代码不处理
5个文件已修改
139 ■■■■ 已修改文件
strategy/account_management.py 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/buying_strategy.py 100 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/data_cache.py 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/kpl_api.py 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/order_methods.py 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/account_management.py
@@ -60,8 +60,9 @@
            # print(f" 当前代码 = {i['symbol']}  持仓均价 = {i['vwap']}    持仓手数=={i['volume']}   可用金额=={i['available_now']} ")
            if currentPosition != 0:
                # 当前持仓
                # print(f"当前持仓=={securityName}")
                # 当前持仓 持仓代码集合
                data_cache.position_symbols_set.add(securityID)
                logger.info(f"当前持仓=={securityName}")
                # 如果 可用仓位等于0 且 昨仓冻结(挂单委托中)等于0  昨日收盘价获取到非0值时(不知名原因导致有些票会获取到0值导致后续公式报错,阻止intraday_growth函数正常运行)
                if availablePosition == 0 and historyPosFrozen == 0:
                    # 新增持仓
@@ -74,8 +75,8 @@
                    if availablePosition != 0:
                        logger.info(f"昨日持仓==={securityName}  持仓可用:{availablePosition}")
        # todo 自主的计算持仓数量 管用 还是 服务端即时查询同步有用 有待验证
        # 及时查询持仓字典数据有用,整理持仓集合也有用。整理持仓集合就是仓位管理的一部分功能。
        logger.info(f"今日持仓集合====================================【{data_cache.position_symbols_set}】")
        logger.info(f"今日可用持仓数量====================================【{len(data_cache.available_symbols_set)}】")
        logger.info(
            f"今日新增持仓数量====================================【{len(data_cache.addition_position_symbols_set)}】")
        logger.info(f"今日新增持仓数量====================================【{len(data_cache.addition_position_symbols_set)}】")
strategy/buying_strategy.py
@@ -338,19 +338,15 @@
                                                                             current_price)
                                            # 查看一下该股有无大单
                                            L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                            # 检测持仓信息中有无下单个股且有该个股的当前持仓,只有当前持仓数量不为0时,才认为交易成功
                                            for i in data_cache.account_positions_dict:
                                                # print(i)
                                                if i['securityID'] == symbol_code:
                                                    # print(i['currentPosition'])
                                                    if i['currentPosition'] == 0:
                                                        logger.info(f"【{i['securityName']}】交易失败~")
                                                    else:
                                                        # 将有概念买入次数自加1
                                                        data_cache.have_plate_buy_times += 1
                                                        # 将买入个股的当时概念添加到全局变量中存储
                                                        data_cache.bought_plate.extend(limit_up_plate_included_list)
                                                        logger.info(f"【{i['securityName']}】交易成功!")
                                            # 检测持仓代码集合中有无下单个股,才认为交易成功
                                            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}")
@@ -435,20 +431,17 @@
                                                # data_cache.bought_plate.extend(limit_up_plate_included_list)
                                                # # 查看一下该股有无大单
                                                L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                                # 检测持仓信息中有无下单个股且有该个股的当前持仓,只有当前持仓数量不为0时,才认为交易成功
                                                for i in data_cache.account_positions_dict:
                                                    # print(i)
                                                    if i['securityID'] == symbol_code:
                                                        # print(i['currentPosition'])
                                                        if i['currentPosition'] == 0:
                                                            logger.info(f"【{i['securityName']}】交易失败~")
                                                        else:
                                                            # 将有概念买入次数自加1
                                                            data_cache.have_plate_buy_times += 1
                                                            # 将买入个股的当时概念添加到全局变量中存储
                                                            data_cache.bought_plate.extend(limit_up_plate_included_list)
                                                            logger.info(f"【{i['securityName']}】交易成功!")
                                                # 检测持仓代码集合中有无下单个股,才认为交易成功
                                                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}")
                                '''
                                无概念 有强度视界
                                '''
@@ -535,19 +528,17 @@
                                                    # data_cache.bought_plate.extend(strength_plate)
                                                    # 查看一下该股有无大单
                                                    L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                                    # 检测持仓信息中有无下单个股且有该个股的当前持仓,只有当前持仓数量不为0时,才认为交易成功
                                                    for i in data_cache.account_positions_dict:
                                                        # print(i)
                                                        if i['securityID'] == symbol_code:
                                                            # print(i['currentPosition'])
                                                            if i['currentPosition'] == 0:
                                                                logger.info(f"【{i['securityName']}】交易失败~")
                                                            else:
                                                                # 将有概念买入次数自加1
                                                                data_cache.have_strength_buy_times += 1
                                                                # 将买入个股的当时概念添加到全局变量中存储
                                                                data_cache.bought_plate.extend(strength_plate)
                                                                logger.info(f"【{i['securityName']}】交易成功!")
                                                    # 检测持仓代码集合中有无下单个股,才认为交易成功
                                                    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}")
                                '''
                                无概念无强度 有小量换大涨幅度视界
                                '''
@@ -645,19 +636,18 @@
                                                    # data_cache.bought_plate.append(k_line_data[0]['sec_name'])
                                                    # 查看一下该股有无大单
                                                    L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                                    # 检测持仓信息中有无下单个股且有该个股的当前持仓,只有当前持仓数量不为0时,才认为交易成功
                                                    for i in data_cache.account_positions_dict:
                                                        # print(i)
                                                        if i['securityID'] == symbol_code:
                                                            # print(i['currentPosition'])
                                                            if i['currentPosition'] == 0:
                                                                logger.info(f"【{i['securityName']}】交易失败~")
                                                            else:
                                                                # 将有概念买入次数自加1
                                                                data_cache.have_small_turn_large_buy_times += 1
                                                                # 将买入个股的当时概念添加到全局变量中存储
                                                                data_cache.bought_plate.extend(k_line_data[0]['sec_name'])
                                                                logger.info(f"【{i['securityName']}】交易成功!")
                                                    # 检测持仓代码集合中有无下单个股,才认为交易成功
                                                    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_small_turn_large_buy_times += 1
                                                        # 将买入个股的当时概念添加到全局变量中存储
                                                        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}")
                                '''
                                昨日涨停视界,今日连板预期盯视界
                                '''
@@ -673,9 +663,7 @@
                                            logger.info(f"昨日首板涨停,当日中等以上高开 {today_open_growth}% !")
                                            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:
                                                    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 len(data_cache.addition_position_symbols_set) >= 3:
strategy/data_cache.py
@@ -199,6 +199,7 @@
usefulMoney = 0
# 为当前账户全部【持仓信息】创建列表
account_positions_dict = {}
# 下面三个集合是为了分类整理持仓字典数据,将各类持仓情况的数据整理为需要的集合
# 为持仓代码创建一个初始集合
position_symbols_set = set()
# 为当日可用持仓代码创建一个初始集合
strategy/kpl_api.py
@@ -12,7 +12,7 @@
import constant
from log_module import async_log_util
from log_module.log import logger_common, logger_kpl_jingxuan_in, logger_Overall_market_strength_score, \
    logger_stock_of_markets_plate
    logger_stock_of_markets_plate, logger_debug
# import requests
from strategy import data_cache
from strategy import basic_methods
@@ -328,6 +328,7 @@
                callback(its_stock_power)
                # print(f"精选板块拉升个股更新===={its_stock_power}")
        except Exception as e:
            logger_debug.exception(e)
            logger.error(f"开盘啦板块强度线程报错An error occurred: {e}")
        finally:
            time.sleep(2)
strategy/order_methods.py
@@ -25,9 +25,9 @@
        # 暂停自动买
        logger.info(f"在交易方法函数处 关闭了 自动买")
        return
    if current_price < 3 or current_price > 50:
    if current_price < 3 or current_price > 30:
        # 当前单价超出预设限制
        logger.info(f"当前标的个股{sec_name}单价超出预设限制!预设值3 < current_price < 50,当前最新价{current_price}")
        logger.info(f"当前标的个股{sec_name}单价超出预设限制!预设值3 < current_price < 30,当前最新价{current_price}")
        return
    price = round(float(current_price), 2)
    volume = (int(buy_order_value / price) // 100) * 100
@@ -52,15 +52,21 @@
        account_management.finance_management()
        logger.info(f"更新的资金数据data_cache.account_finance_dict=={data_cache.account_finance_dict}")
        if symbol[-6:] in data_cache.account_positions_dict:
            logger.info(f"该股已经持仓==》{sec_name}")
            pass
        # 因为上面的更新持仓数据函数会计算 今日新增持仓数量,所以如果再手动新增持仓数据会重复计算【考虑到持仓函数有可能会有延迟,这也可能是同时运行一段时间没有出现BUG的原因,先暂时保留以下这段代码,只是注释】
        # # 买票后添加 持仓代码集合
        # data_cache.position_symbols_set.add(symbol)
        # # 买票后添加 今日新增持仓代码集合
        # data_cache.addition_position_symbols_set.add(symbol)
        # logger.info(f"当前持仓数量:::{len(data_cache.position_symbols_set)}")
        # logger.info(f"今日新增持仓数量:::{len(data_cache.addition_position_symbols_set)}")
        # todo 当前为测试阶段的冗余打印
        # 检测持仓信息中有无下单个股且有该个股的当前持仓,只有当前持仓数量不为0时,才认为交易成功
        for i in data_cache.account_positions_dict:
            # print(i)
            if i['securityID'] == symbol[-6:]:
                # print(i['currentPosition'])
                if i['currentPosition'] == 0:
                    logger.info(f"【{i['securityName']}】交易失败~")
                else:
                    # 买票后添加 持仓代码集合
                    data_cache.position_symbols_set.add(symbol)
                    logger.info(f"【{i['securityName']}】交易成功!")
# 下单买入函数(按可用资金的一定比例,在涨停价买)【按金额买 高级版】