New file |
| | |
| | | """ |
| | | 回测 |
| | | """ |
| | | 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 |
| | | |
| | |
| | | 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", |
| | |
| | | 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" |
| | |
| | | |
| | | 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") |
| | |
| | | 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") |
| | | |
| | |
| | | # 开盘啦的涨停概念的回调函数 |
| | | def kpl_limit_up_process(datas): |
| | | # print(f"回调成功==={datas}") |
| | | now_time = tool.get_now_time_str() |
| | | if datas is not None and len(datas) > 0: |
| | | data_cache.limit_up_block_names = datas |
| | | if data_cache.CLOSING_TIME < now_time < data_cache.AFTER_CLOSING_TIME: |
| | | logger_common.info(f"收盘涨停概念列表更新==={now_time}=={datas}") |
| | | else: |
| | | data_cache.limit_up_block_names = [] |
| | | |
| | |
| | | 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 |
| | | |
| | | # 引入基础算法模块 |
| | |
| | | # 将转换后的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()}") |
| | |
| | | # 充分交易量公式 用于计算日内涨幅段理论的安全交易量值 |
| | | def sufficient_volume(current_volume, yesterday_volume, today_growth): |
| | | if today_growth > 0 and round(current_volume / yesterday_volume, 2) >= 0.01: |
| | | if current_volume > yesterday_volume * (today_growth/10) * 0.4: |
| | | if current_volume > yesterday_volume * (today_growth/10) * 0.5: |
| | | return True |
| | | else: |
| | | return False |
| | |
| | | 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: |
| | |
| | | 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( |
| | |
| | | data_cache.bought_plate.extend(limit_up_plate_included_list) |
| | | logger_info( |
| | | f"【{k_line_data[0]['sec_name']}】交易成功!持仓集合:{data_cache.position_symbols_set}") |
| | | # 传给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 strength_list_have_it is False: |
| | | 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)}") |
| | | # 传给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( |
| | |
| | | data_cache.bought_plate.extend(limit_up_plate_included_list) |
| | | logger_info( |
| | | f"【{k_line_data[0]['sec_name']}】交易成功!持仓集合:{data_cache.position_symbols_set}") |
| | | # 传给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} ") |
| | | |
| | | ''' |
| | | 无概念 有强度视界 |
| | | ''' |
| | |
| | | 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( |
| | |
| | | data_cache.bought_plate.extend(strength_plate) |
| | | logger_info( |
| | | f"【{k_line_data[0]['sec_name']}】交易成功!持仓集合:{data_cache.position_symbols_set}") |
| | | # 传给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} ") |
| | | |
| | | ''' |
| | | 无概念无强度 有小量换大涨幅度视界 |
| | | ''' |
| | |
| | | # 以下部分主要计算整体的花费时间 |
| | | # 将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)}") |
| | |
| | | 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 |
| | | |
| | |
| | | # 获取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} |
| | |
| | | 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 |
| | | |
| | | |
| | |
| | | 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) |
| | |
| | | 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 |
| | |
| | | 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'])}") |
| | |
| | | # 设定当前时间点 |
| | | 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() |
| | |
| | | # 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 |
| | | |
| | | |
| | |
| | | # 写入文件 |
| | | 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}") |
| | | |