| | |
| | | # 引入历史K线方法模块 |
| | | # 引入瞬时分时行情模块 |
| | | # 引入账户管理模块【进行资金和仓位管理】 |
| | | from strategy import kpl_api, data_cache, check_timer, all_K_line, instant_time_market, account_management, order_methods |
| | | from strategy import kpl_api, data_cache, check_timer, all_K_line, instant_time_market, account_management, \ |
| | | order_methods, local_data_management |
| | | from huaxin_client import l2_market_client |
| | | from log_module import async_log_util |
| | | from trade import huaxin_trade_data_update |
| | |
| | | account_management.position_management() |
| | | # 初始化.实例化缓存中的全局数据 |
| | | data_cache.DataCache() |
| | | # 读取本地K线数据 并更新到data_cache |
| | | |
| | | # 初始化A股所有目标票标的信息 |
| | | data_cache.all_stocks = utils.juejin_api.JueJinApi.get_target_codes() |
| | | # 获取目标标的K线---初始化 |
| | |
| | | |
| | | # 直接调用目标标的指标K线写入本地文件 |
| | | # all_K_line.all_stocks_all_k_line_dict_write() |
| | | local_data_management.read_local_K_line_data() |
| | | # 读取本地个股所属板块数据 并更新到data_cache |
| | | local_data_management.read_local_all_stocks_plate_data() |
| | | |
| | | # 先使用json.load()直接从文件中读取【已经存储在本地的K线指标属性字典】并解析JSON数据 |
| | | if os.path.exists(constant.K_BARS_PATH): |
| | | with open(constant.K_BARS_PATH, 'r', encoding='utf-8') as f: |
| | | data_cache.all_stocks_all_K_line_property_dict = json.load(f) |
| | | print( |
| | | f"data_cache.all_stocks_all_K_line_property_dict的个数==={len(data_cache.all_stocks_all_K_line_property_dict)}") |
| | | # todo 2025-03-25 测试无误即可删除下部注释 |
| | | # # 先使用json.load()直接从文件中读取【已经存储在本地的K线指标属性字典】并解析JSON数据 |
| | | # if os.path.exists(constant.K_BARS_PATH): |
| | | # with open(constant.K_BARS_PATH, 'r', encoding='utf-8') as f: |
| | | # data_cache.all_stocks_all_K_line_property_dict = json.load(f) |
| | | # print( |
| | | # f"data_cache.all_stocks_all_K_line_property_dict的个数==={len(data_cache.all_stocks_all_K_line_property_dict)}") |
| | | |
| | | # # 获取目标标的K线---初始化 |
| | | # all_K_line.main_index_k_line_history.init(data_cache.DataCache().today_date, data_cache.DataCache().next_trading_day, data_cache.DataCache().main_index_stocks) |
| | |
| | | huaxin_trade_data_update.run() |
| | | |
| | | # 等待5s,等其他线程/进程启动完毕 |
| | | time.sleep(5) |
| | | time.sleep(15) |
| | | |
| | | try: |
| | | # 初始化数据 |
| | |
| | | if currentPosition != 0: |
| | | # 当前持仓 |
| | | # print(f"当前持仓=={securityName}") |
| | | if availablePosition != 0 and historyPosFrozen != 0: # 如果 可用资金 和 昨仓冻结 都不等于0 昨日收盘价获取到非0值时(不知名原因导致有些票会获取到0值导致后续公式报错,阻止intraday_growth函数正常运行) |
| | | # 如果 可用仓位等于0 且 昨仓冻结(挂单委托中)等于0 昨日收盘价获取到非0值时(不知名原因导致有些票会获取到0值导致后续公式报错,阻止intraday_growth函数正常运行) |
| | | if availablePosition == 0 and historyPosFrozen == 0: |
| | | # 新增持仓 |
| | | logger.info(f"今日新增持仓==={securityName}") |
| | | data_cache.addition_position_symbols_set.add(securityID) |
| | | else: |
| | | data_cache.available_symbols_set.add(securityID) |
| | | if historyPosFrozen != 0: |
| | | logger.info(f"昨日持仓==={securityName}==挂单中》》挂单数量:{historyPosFrozen}") |
| | | else: |
| | | logger.info(f"昨日持仓==={securityName}===持仓可用:{availablePosition}") |
| | | |
| | | else: |
| | | # 新增持仓 |
| | | logger.info(f"今日新增持仓==={securityName}") |
| | | data_cache.addition_position_symbols_set.add(securityID) |
| | | # todo 自主的计算持仓数量 管用 还是 服务端即时查询同步有用 有待验证 |
| | | logger.info(f"今日可用持仓数量====================================【{len(data_cache.available_symbols_set)}】") |
| | | logger.info( |
| | |
| | | UPDATE_DATA_TIME = datetime.time(18, 31, 00).strftime("%H:%M:%S") # 定义更新数据时间 |
| | | PROGRAM_SLEEP_TIME = datetime.time(23, 00, 00).strftime("%H:%M:%S") # 定义程序休眠时间 |
| | | |
| | | # 读取已经获取到并存储在本地的目标范围的个股的板块概念 |
| | | # 读取JSON文件并解析为字典 |
| | | if os.path.exists(constant.ALL_STOCKS_PLATE_PATH): |
| | | with open(constant.ALL_STOCKS_PLATE_PATH, 'r', |
| | | encoding='utf-8') as f: |
| | | json_data = f.read() |
| | | else: |
| | | json_data = "{}" |
| | | all_stocks_plate_dict = json.loads(json_data) |
| | | logger.info(f"all_stocks_plate_dict的数量={len(all_stocks_plate_dict)}") |
| | | # todo 2025-03-25 后无BUG即可彻底删除下处注释部分 |
| | | # # 读取已经获取到并存储在本地的目标范围的个股的板块概念 |
| | | # # 读取JSON文件并解析为字典 |
| | | # if os.path.exists(constant.ALL_STOCKS_PLATE_PATH): |
| | | # with open(constant.ALL_STOCKS_PLATE_PATH, 'r', |
| | | # encoding='utf-8') as f: |
| | | # json_data = f.read() |
| | | # else: |
| | | # json_data = "{}" |
| | | # all_stocks_plate_dict = json.loads(json_data) |
| | | # logger.info(f"all_stocks_plate_dict的数量={len(all_stocks_plate_dict)}") |
| | | |
| | | # 初始化当日当时最高价 |
| | | high_price = 0 |
| | |
| | | # 初始化实时大盘行情情绪综合强度分时列表 |
| | | time_sharing_market_strong_dirt = {} |
| | | |
| | | # 为K线属性指标字典初始化 |
| | | # 为所有个股的带属性K线 字典初始化 |
| | | all_stocks_all_K_line_property_dict = {} |
| | | # 为指数的带属性K线 字典初始化 |
| | | all_index_k_line_property_dict = {} |
| | | # 声明K线属性中所有涨停类型 |
| | | limit_up_type = ['one_line_limit_up', 'limit_down_then_limit_up', 'limit_up_then_limit_down_then_limit_up', |
| | | 'limit_up'] |
| | |
| | | # 声明K线属性中所有炸板类型 |
| | | frying_plate_type = ['frying_plate', 'first_frying_plate', 'one_line_limit_up_then_frying_plate', |
| | | 'one_line_limit_up_then_frying_plate_then_limit_down', 'not_first_frying_plate'] |
| | | |
| | | # 定义一个当日分时内所有个股的开盘价字典 |
| | | all_stocks_current_open = {} |
| | | # 定义一个当日分时内所有个股的实时最高价和最低价字典 |
| | |
| | | else: |
| | | index_composite_tick_increase = '三大指数:涨跌不一' |
| | | logger.info(f"开盘指数开盘瞬时走势播报:{index_composite_tick_increase}") |
| | | logger.info(f"指数带属性K线数据的昨日是否为空:{data_cache.all_index_k_line_property_dict['000001'][0]}") |
| | | return index_trend_expectation_score |
| | | |
| | | |
| | |
| | | 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()}") |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | # all_index_K_line_dict = get_index_K_line() |
| | |
| | | try: |
| | | if data_cache.position_automatic_management_switch is True: |
| | | now_time = tool.get_now_time_str() |
| | | if data_cache.SERVER_RESTART_TIME < now_time < data_cache.UPDATE_DATA_TIME: |
| | | if data_cache.L1_DATA_START_TIME < now_time < data_cache.UPDATE_DATA_TIME: |
| | | # 获取大盘综合强度分数 |
| | | data_cache.real_time_market_strong = get_market_strong() |
| | | # data_cache.time_sharing_market_strong_dirt = time_sharing_market_strong_dirt.update({now: data_cache.real_time_market_strong}) |
New file |
| | |
| | | import json |
| | | import os |
| | | |
| | | import constant |
| | | from strategy import data_cache |
| | | |
| | | |
| | | from log_module.log import logger_common |
| | | # 获取logger实例 |
| | | logger = logger_common |
| | | |
| | | |
| | | # 读取本地的所有带属性K线数据(所有个股K线及指数线) |
| | | def read_local_K_line_data(): |
| | | # 先使用json.load()直接从文件中读取【已经存储在本地的K线指标属性字典】并解析JSON数据 |
| | | if os.path.exists(constant.K_BARS_PATH): |
| | | with open(constant.K_BARS_PATH, 'r', encoding='utf-8') as f: |
| | | data_cache.all_stocks_all_K_line_property_dict = json.load(f) |
| | | print( |
| | | f"data_cache.all_stocks_all_K_line_property_dict的个数==={len(data_cache.all_stocks_all_K_line_property_dict)}") |
| | | |
| | | # 先使用json.load()直接从文件中读取【已经存储在本地的K线指标属性字典】并解析JSON数据 |
| | | if os.path.exists(constant.INDEX_K_BARS_PATH): |
| | | with open(constant.INDEX_K_BARS_PATH, 'r', encoding='utf-8') as f: |
| | | data_cache.all_index_k_line_property_dict = json.load(f) |
| | | print( |
| | | f"data_cache.all_stocks_all_K_line_property_dict的个数==={len(data_cache.all_index_k_line_property_dict)}") |
| | | |
| | | |
| | | # 读取本地的个股所属概念板块数据 |
| | | def read_local_all_stocks_plate_data(): |
| | | # 读取已经获取到并存储在本地的目标范围的个股的板块概念 |
| | | # 读取JSON文件并解析为字典 |
| | | if os.path.exists(constant.ALL_STOCKS_PLATE_PATH): |
| | | with open(constant.ALL_STOCKS_PLATE_PATH, 'r', |
| | | encoding='utf-8') as f: |
| | | json_data = f.read() |
| | | else: |
| | | json_data = "{}" |
| | | all_stocks_plate_dict = json.loads(json_data) |
| | | logger.info(f"all_stocks_plate_dict的数量={len(all_stocks_plate_dict)}") |
| | |
| | | # 暂停自动买 |
| | | logger.info(f"在交易方法函数处 关闭了 自动买") |
| | | return |
| | | |
| | | if current_price < 3 or current_price > 50: |
| | | # 当前单价超出预设限制 |
| | | logger.info(f"当前标的个股{sec_name}单价超出预设限制!预设值3 < current_price < 50,当前最新价{current_price}") |
| | | return |
| | | price = round(float(current_price), 2) |
| | | volume = (int(buy_order_value / price) // 100) * 100 |
| | | if volume < 100: |