admin
2025-03-24 02166225b34a7ec2c41dc8eda77c431465b8d9dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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)}")