Administrator
2024-10-12 aacc6148dd43a9cffbff9a23a273a55b64bf3d8c
utils/init_data_util.py
@@ -2,6 +2,7 @@
import decimal
from code_attribute import gpcode_manager
from log_module.log import logger_debug
from third_data.history_k_data_util import HistoryKDatasUtils
from utils import tool
@@ -12,6 +13,7 @@
def re_set_price_pres(codes, force=False):
    # 通过历史数据缓存获取
    result = HistoryKDatasUtils.get_gp_latest_info(codes)
    for item in result:
        symbol = item['symbol']
@@ -20,17 +22,49 @@
        gpcode_manager.CodePrePriceManager.set_price_pre(symbol, pre_close, force)
# 获取近90天的最大量与最近的量
# 获取最近一次涨停/涨停下一个交易日的最大值
def get_volumns_by_code(code, count=60) -> object:
def get_volumns_by_code(code, count=60):
    datas = HistoryKDatasUtils.get_history_tick_n(code, count, "open,high,low,close,volume,pre_close,bob,amount")
    if not datas:
        return None
    # 计算
    datas.sort(key=lambda x: x["bob"], reverse=True)
    return datas
def parse_max_volume(code, datas, is_new_or_near_top=False):
    result = __parse_max_volume(code, datas, is_new_or_near_top)
    refer_index = result[3]
    # 计算最低价
    refer_price = datas[refer_index]["high"]
    min_price = float(refer_price)
    for i in range(0, refer_index + 1):
        if min_price > datas[i]["low"]:
            min_price = datas[i]["low"]
    if (refer_price - min_price) / refer_price < 0.4:
        return result
    # 超跌
    new_datas = []
    for i in range(0, refer_index):
        # 获取涨幅
        item = datas[i]
        rate = (item["low"] - item["pre_close"]) / item["pre_close"]
        new_datas.append((i, rate))
    new_datas.sort(key=lambda x: x[1])
    refer_index = new_datas[0][0]
    # 获取当前天和后一天较大量
    if refer_index > 0:
        if datas[refer_index - 1]["volume"] > datas[refer_index]["volume"]:
            refer_index -= 1
    return datas[refer_index]["volume"], datas[refer_index]["volume"], datas[refer_index]['bob'].strftime(
        "%Y-%m-%d"), refer_index
# 返回:(60天最大量,昨日量,量参考日期,参考量据今交易日数)
def parse_max_volume(datas, is_new_or_near_top=False):
def __parse_max_volume(code, datas, is_new_or_near_top=False):
    max_volume = 0
    max_volume_date = None
    max_volume_index = None
@@ -42,7 +76,7 @@
            if i >= len(datas):
                break
            item = datas[i]
            limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"]))
            limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(code, item["pre_close"]))
            if abs(limit_up_price - item["high"]) < 0.001:
                latest_limit_up_index = i
                break
@@ -76,9 +110,9 @@
                max_volume = volume
                max_volume_date = item['bob']
            # 是否有涨停
            limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"]))
            limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(code, item["pre_close"]))
            # 不看超过60天的涨停
            if abs(limit_up_price - item["high"]) < 0.01 and i <= 59:
            if abs(limit_up_price - item["high"]) < 0.001 and i <= 59:
                # 涨停
                next_volume = 0
                if i > 0: