admin
3 天以前 0b0d0e790fec8c7edfdbcab5c31d625e0c2eadd6
添加必要的数据日志
6个文件已修改
2个文件已添加
76 ■■■■ 已修改文件
backtest/__init__.py 补丁 | 查看 | 原始文档 | blame | 历史
backtest/main.py 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
log_module/log.py 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/all_K_line.py 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/buying_strategy.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/data_cache.py 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/kpl_data_manager.py 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/plate_strength_analysis.py 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
backtest/__init__.py
backtest/main.py
New file
@@ -0,0 +1,16 @@
"""
回测
"""
from utils import tool
if __name__ == '__main__':
    now_day = '2025-06-19'
    # 从早上09:25:00回测到11:30:00
    start_time, end_time = '09:25:00', '11:30:00'
    for i in range(0, 60*60*3):
        # 时间驱动
        time_str = tool.trade_time_sub(start_time, 0 - i)
        if time_str > end_time:
            break
        pass
log_module/log.py
@@ -201,6 +201,19 @@
                   filter=lambda record: record["extra"].get("name") == "kpl_open_limit_up",
                   rotation="00:00", compression="zip", enqueue=True)
        logger.add(self.get_path("kpl", "kpl_code_plates"),
                   filter=lambda record: record["extra"].get("name") == "kpl_code_plates",
                   rotation="00:00", compression="zip", enqueue=True)
        # K线日志
        logger.add(self.get_path("kbars", "k_bars"),
                   filter=lambda record: record["extra"].get("name") == "k_bars",
                   rotation="00:00", compression="zip", enqueue=True)
        # 目标票
        logger.add(self.get_path("codes", "target_codes"),
                   filter=lambda record: record["extra"].get("name") == "target_codes",
                   rotation="00:00", compression="zip", enqueue=True)
        # 看盘日志
        logger.add(self.get_path("kp", "kp_msg"),
                   filter=lambda record: record["extra"].get("name") == "kp_msg",
@@ -323,6 +336,10 @@
                   filter=lambda record: record["extra"].get("name") == "stock_of_markets_plate",
                   rotation="00:00", compression="zip", enqueue=True)
        logger.add(self.get_path("kpl", "stock_of_markets_plate_simple"),
                   filter=lambda record: record["extra"].get("name") == "stock_of_markets_plate_simple",
                   rotation="00:00", compression="zip", enqueue=True)
    def get_path(self, dir_name, log_name):
        path_str = "{}/{}/gp/{}/{}".format(constant.get_path_prefix(), constant.LOG_DIR, dir_name,
                                           log_name) + ".{time:YYYY-MM-DD}.log"
@@ -420,6 +437,13 @@
logger_kp_msg = __mylogger.get_logger("kp_msg")
logger_kpl_code_plates = __mylogger.get_logger("kpl_code_plates")
logger_k_bars = __mylogger.get_logger("k_bars")
logger_target_codes = __mylogger.get_logger("target_codes")
logger_redis_debug = __mylogger.get_logger("redis_debug")
logger_profile = __mylogger.get_logger("profile")
@@ -451,6 +475,7 @@
logger_kpl_market_sift_plate = __mylogger.get_logger("kpl_market_sift_plate")
logger_Overall_market_strength_score = __mylogger.get_logger("Overall_market_strength_score")
logger_stock_of_markets_plate = __mylogger.get_logger("stock_of_markets_plate")
logger_stock_of_markets_plate_simple = __mylogger.get_logger("stock_of_markets_plate_simple")
logger_common = __mylogger.get_logger("common")
strategy/all_K_line.py
@@ -11,7 +11,8 @@
import json
import constant
from log_module.log import logger_common
from log_module import async_log_util
from log_module.log import logger_common, logger_k_bars
from strategy import data_cache
# 引入基础算法模块
@@ -378,6 +379,7 @@
        # 将转换后的JSON字符串写入文件
        with open(constant.K_BARS_PATH, 'w', encoding='utf-8') as f:
            f.write(json_data)
        async_log_util.info(logger_k_bars, json_data)
    except Exception as error:
        print(f"An error occurred while converting the data to JSON: {error}")
    logger.info(f"标的个股历史k线写完了!{tool.get_now_time_str()}")
strategy/buying_strategy.py
@@ -879,7 +879,7 @@
                # 以下部分主要计算整体的花费时间
                # 将current_created_at转换为datetime对象,这里假设是今天的日期
                # 注意:这里使用了datetime.now()来获取当前日期,但你可以根据需要调整
                created_at = datetime.datetime.strptime(tool.get_now_date_str() + " " + current_created_at,
                created_at = datetime.datetime.strptime(data_cache.DataCache().today_date + " " + current_created_at,
                                                        "%Y-%m-%d %H:%M:%S").timestamp()
                # print(f"created_at===={created_at}")
                # print(f"created_at type===={type(created_at)}")
strategy/data_cache.py
@@ -11,7 +11,8 @@
import constant
# 引入掘金API
import utils.juejin_api
from log_module.log import logger_common
from log_module import async_log_util
from log_module.log import logger_common, logger_target_codes
# from logging_config import get_logger
from utils import tool, hx_qc_value_util
@@ -65,7 +66,7 @@
        # 获取A股市场(包含沪深两市)的股票列表跳过停牌,跳过ST    上交所 SHSE.600000   深交所 SZSE.000000    target = ['SHSE.603839', 'SZSE.002855']
        self.all_stocks = utils.juejin_api.JueJinApi.get_target_codes()
        # self.all_stocks = [{'sec_level': 1, 'symbol': 'SZSE.301633','pre_close': 78.72000122070312, 'is_suspended': 0, 'sec_name': '港迪技术', 'listed_date': datetime.datetime(2024, 11, 7, 0, 0,tzinfo=datetime.timezone(datetime.timedelta(seconds=28800))), 'sec_type': 1, 'sec_id': '301633'}]
        async_log_util.info(logger_target_codes, f"{ self.all_stocks}")
        # self.all_stocks = self.all_stocks[:10]
        # 缓存代码的名称
        self.code_name_dict = {x['symbol']: x['sec_name'] for x in self.all_stocks}
strategy/kpl_data_manager.py
@@ -1,5 +1,6 @@
from log_module import log_export, async_log_util
from log_module.log import logger_stock_of_markets_plate, logger_debug, logger_kpl_market_sift_plate
from log_module.log import logger_stock_of_markets_plate, logger_debug, logger_kpl_market_sift_plate, \
    logger_stock_of_markets_plate_simple
from utils import tool
@@ -71,11 +72,18 @@
    def add_log(self, in_plates_info, plate_codes_info):
        oringin_data = (tool.get_now_time_str(), in_plates_info, plate_codes_info)
        async_log_util.info(logger_stock_of_markets_plate, f"{(oringin_data[1], oringin_data[2])}")
        plate_codes_simple_info = {plate: [(s[1], s[0], s[6], s[9], s[4], s[2], s[40]) for s in oringin_data[2][plate]] for plate in oringin_data[2]}
        async_log_util.info(logger_stock_of_markets_plate_simple, f"{(oringin_data[1], plate_codes_simple_info)}")
    def get_filter_log_datas(self):
        return self.__filter_log_datas
if __name__ == '__main__':
    KPLMarketsSiftPlateLogManager().load_data()
    # KPLMarketsSiftPlateLogManager().load_data()
    # KPLMarketStockHeatLogManager()
    with open("D:/text.txt", encoding='utf-8', mode='r') as f:
        line = f.readline()
        res = eval(line)
        KPLMarketStockHeatLogManager().add_log(res[0], res[1])
        print(res)
strategy/plate_strength_analysis.py
@@ -4,8 +4,10 @@
import time
import dask
import constant
from log_module import async_log_util
from log_module.log import logger_common, logger_kpl_jingxuan_in, logger_debug, logger_kpl_market_sift_plate
from log_module.log import logger_common, logger_kpl_jingxuan_in, logger_debug, logger_kpl_market_sift_plate, \
    logger_kpl_limit_up, logger_kpl_code_plates
from strategy import kpl_api, data_cache, basic_methods
from strategy.kpl_data_manager import KPLMarketStockHeatLogManager
from utils import tool, hx_qc_value_util
@@ -75,6 +77,8 @@
        return log_data
    # 定义一个时间段,在这个时间段内才会执行下面的代码,主要就是把强度数据作为日志打印存储下来。
    now_time = tool.get_now_time_str()
    if '11:30:10' < now_time < '12:59:50':
        return
    data = (kpl_api.getMarketJingXuanRealRankingInfo())
    market_sift_plate = json.loads(data)
    # print(f"market_sift_plate 数 ======{len(market_sift_plate['list'])}")
@@ -140,7 +144,7 @@
    # 设定当前时间点
    now_time = tool.get_now_time_str()
    # print(f"now_time===={now_time}")
    if data_cache.SERVER_RESTART_TIME < now_time < data_cache.UPDATE_DATA_TIME:
    if data_cache.OPEN_BIDDING_TIME < now_time < data_cache.CLOSING_TIME:
        # print(f"在时间内使用--------------------------")
        # 获取涨停信息列表
        limit_up_info = kpl_api.get_limit_up_info()
@@ -159,6 +163,8 @@
        # most_common_element, most_common_count = counter.most_common(1)[0]
        # # 打印出现次数最多的元素
        # print(f"主线概念:{most_common_element},出现了 {most_common_count} 次")
        async_log_util.info(logger_kpl_limit_up, f"{limit_up_info}")
        return limit_up_block_names
@@ -455,6 +461,8 @@
    # 写入文件
    with open(constant.ALL_STOCKS_PLATE_PATH, 'w', encoding='utf-8') as f:
        f.write(json_data)
    # 记录到日志
    async_log_util.info(logger_kpl_code_plates, json_data)
    now_time = datetime.datetime.now()  # 获取本机时间
    logger_common.info(f"写入所有个股板块文件完成!::{now_time}")