| | |
| | | import json |
| | | |
| | | import constant |
| | | from log_module.log import logger_common |
| | | # 引入掘金API |
| | | # import utils.juejin_api |
| | | # import kpl_api |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_common, logger_k_bars |
| | | from strategy import data_cache |
| | | |
| | | # 引入基础算法模块 |
| | |
| | | results = [] |
| | | dates_list = [] |
| | | # 查询交易标的基本信息并赋值 |
| | | sec_name = data_cache.DataCache().code_name_dict.get(symbol) |
| | | sec_name = data_cache.DataCache().code_name_dict.get(symbol, "default_name") |
| | | # print(f"K_line_sec_name=={sec_name}") |
| | | # 将获取到的公司名称直接 生成字典放到 K线的第一个序列中 |
| | | it_K_line[0]['sec_name'] = sec_name |
| | |
| | | # 最高位据昨日较远 且 昨收价距历史最高价差距较小(小于5%,涨幅5%是左右是最容易把低吸骗进去的日内涨幅) 且 整体涨跌幅度较大 【当前二度突破近前高风险】 |
| | | # 【双成药业 2024-11-08 这样的二次近前高,实际数值为1.4646...,为安全起见还是设置为1.5】 |
| | | if (2 < historical_high_price_index < 15 and len(it_K_line) >= 90) and ( |
| | | historical_high_price / round(it_K_line[0]['close'], 2) < 1.5) and ( |
| | | historical_high_price > historical_low_price * 1.8): |
| | | historical_high_price / round(it_K_line[0]['close'], 2) < 1.2) and ( |
| | | historical_high_price > historical_low_price * 2): |
| | | it_K_line[0]['risk_position'] = 'recent_second_break_near_high_position_risk' |
| | | # 昨日就是最高位 且 整体涨跌幅度较大 【当前高位风险】 |
| | | if (historical_high_price_index < 2 and len(it_K_line) >= 90) and ( |
| | |
| | | current_count = 0 |
| | | start = None |
| | | # 确保不会出现除以零的报错 |
| | | if current_yesterday_volume == 0: |
| | | current_yesterday_volume = 1 |
| | | if current_yesterday_volume != 0: |
| | | if round(current_today_volume / current_yesterday_volume, 2) > 1.1: |
| | | # print(f"i=={i} {it_K_line[i]['bob']} {round(current_today_volume/current_yesterday_volume,2)} 【放量】") |
| | | if current_today_growth > 0: |
| | |
| | | else: |
| | | it_K_line[i]['today_volume_shape'] = 'decreases_balance' |
| | | # print(f"i=={i} {it_K_line[i]['bob']} 【缩量平收】") |
| | | else: |
| | | # print(f"i=={i} {it_K_line[i]['bob']} {round(current_today_volume/current_yesterday_volume,2)} 【平量】") |
| | | if current_today_growth > 0: |
| | | it_K_line[i]['today_volume_shape'] = 'remained_up' |
| | | # print(f"i=={i} {it_K_line[i]['bob']} 【平量上涨】") |
| | | elif current_today_growth < 0: |
| | | it_K_line[i]['today_volume_shape'] = 'remained_down' |
| | | # print(f"i=={i} {it_K_line[i]['bob']} 【平量下跌】") |
| | | else: |
| | | it_K_line[i]['today_volume_shape'] = 'remained_balance' |
| | | # print(f"i=={i} {it_K_line[i]['bob']} 【平量平收】") |
| | | # print(f"i=={i} {it_K_line[i]['bob']} {round(current_today_volume/current_yesterday_volume,2)} 【平量】") |
| | | if current_today_growth > 0: |
| | | it_K_line[i]['today_volume_shape'] = 'remained_up' |
| | | # print(f"i=={i} {it_K_line[i]['bob']} 【平量上涨】") |
| | | elif current_today_growth < 0: |
| | | it_K_line[i]['today_volume_shape'] = 'remained_down' |
| | | # print(f"i=={i} {it_K_line[i]['bob']} 【平量下跌】") |
| | | else: |
| | | it_K_line[i]['today_volume_shape'] = 'remained_balance' |
| | | # print(f"i=={i} {it_K_line[i]['bob']} 【平量平收】") |
| | | else: |
| | | logger.info(f"{symbol} 的 昨日成交量 为 0,报错!!") |
| | | |
| | | if current_open - previous_close > 0: |
| | | # print(f"i=={i} {it_K_line[i]['bob']} 成交总量:{today_volume},,,成交总金额:{today_amount}") |
| | |
| | | # 将转换后的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()}") |
| | | |
| | | |
| | | # 写入主要指数的90天K线 |
| | | def main_index_k_line_dict_write(): |
| | | main_index_base_K_line_dict = main_index_k_line_history.k_line_history_90day() |
| | | # 初始化所有个股的指标K线列表 |
| | | main_index_k_line_property_dict = {} |
| | | for i in data_cache.DataCache().main_index_stocks: |
| | | # print(f"i==========={i}") |
| | | i_k_line = main_index_base_K_line_dict[i] # 获取i的K线 |
| | | i_k_line_copy = copy.deepcopy(i_k_line) # 深拷贝i的K线 |
| | | # it_K_line_reversed = list(reversed(i_k_line_copy)) # 开盘啦获取的数据需要反转i的K线 |
| | | it_K_line_reversed = list(i_k_line_copy) # 小辉端的数据不需要反转i的K线 |
| | | if not it_K_line_reversed: |
| | | continue |
| | | k_line_history.get_property_limit_mark(it_K_line_reversed, i) # 给标的的K线更新指标属性 把股票代码同时传给要调用的函数 |
| | | index_k_line_property_dict = {i: it_K_line_reversed} # 添加 更新极限指标属性的K线 字典 |
| | | # print(f"index_k_line_property_dict===={index_k_line_property_dict}") |
| | | main_index_base_K_line_dict.update(index_k_line_property_dict) |
| | | |
| | | # 构造时间格式datetime转化为字符串,以便将K线属性指标转化为json格式写入本地文件 |
| | | def convert_datetime(obj): |
| | | if isinstance(obj, datetime.datetime): |
| | | return obj.strftime('%Y-%m-%d %H:%M:%S') # 转换为字符串 |
| | | elif isinstance(obj, dict): |
| | | return {k: convert_datetime(v) for k, v in obj.items()} # 递归处理字典 |
| | | elif isinstance(obj, list): |
| | | return [convert_datetime(element) for element in obj] # 递归处理列表 |
| | | # 可以添加其他类型的处理逻辑 |
| | | else: |
| | | # 对于未知类型,你可以选择保留原样、跳过或引发异常 |
| | | # 这里我们选择保留原样 |
| | | return obj |
| | | |
| | | try: |
| | | json_data = json.dumps(convert_datetime(main_index_k_line_property_dict), ensure_ascii=False, indent=4) |
| | | # 将转换后的JSON字符串写入文件 |
| | | with open(constant.K_BARS_PATH, 'w', encoding='utf-8') as f: |
| | | f.write(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()}") |
| | | |
| | | |
| | | |
| | | # 用开盘啦数据检测昨日的K线中涨停属性是否有误(盘尾 集合竞价 炸开一个卖一档,但涨幅未变的) |
| | |
| | | while True: |
| | | try: |
| | | # 声明赋值实时时间 |
| | | now_time = data_cache.now_time |
| | | now_time = tool.get_now_time_str() |
| | | |
| | | # print(f"now_time==={now_time}") |
| | | # if now_time > data_cache.AFTER_CLOSING_TIME and data_cache.execution is False: |
| | | # # if now_time > data_cache.AFTER_CLOSING_TIME: |
| | | # data_cache.execution = True |
| | | # # 整理当日涨停信息并写入本地管理好本地数据 |
| | | # kpl_api.get_arrange_limit_up_info() |
| | | # plate_strength_analysis.get_arrange_limit_up_info() |
| | | # logger.info(f"整理当日涨停信息 已经运行完成") |
| | | # # # 获取所有个股的板块概念并写入文件【耗时较长应该放在 核心主线程 和 仓位管理 后面】 |
| | | # kpl_api.get_all_stocks_plate_dict(data_cache.min_stocks) |
| | | # plate_strength_analysis.get_all_stocks_plate_dict(data_cache.min_stocks) |
| | | # # logger.info(f"获取所有个股的板块概念 已经运行完成") |
| | | |
| | | # 构造一个循环检测K线子带你中所有个股代码下的日期是不是和某日一致的,如果不一致则返回False |