Administrator
2023-12-27 00e0f3113d462669837c3eba174d8b5d978f5126
输出api修改
2个文件已修改
62 ■■■■ 已修改文件
third_data/data_server.py 53 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/history_k_data_util.py 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/data_server.py
@@ -7,9 +7,9 @@
from http.server import BaseHTTPRequestHandler
import dask
from code_attribute.gpcode_manager import BlackListCodeManager
from code_attribute.gpcode_manager import BlackListCodeManager, CodePrePriceManager
from log_module.log import logger_system, logger_debug, logger_kpl_limit_up
from utils import global_util, tool, data_export_util
from utils import global_util, tool, data_export_util, init_data_util
from code_attribute import gpcode_manager
from log_module import log, log_analyse, log_export
from l2 import code_price_manager, l2_data_util, l2_data_manager_new, cancel_buy_strategy, transaction_progress
@@ -49,6 +49,8 @@
    __industry_cache_dict = {}
    __latest_limit_up_codes_set = set()
    __data_process_thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=10)
    # 代码的涨幅
    __code_limit_rate_dict = {}
    # 禁用日志输出
    def log_message(self, format, *args):
@@ -515,6 +517,26 @@
                response_data = json.dumps({"code": 1, "msg": "请上传code"})
        elif url.path == "/get_last_trade_day_reasons":
            # 计算平均涨幅
            def get_limit_rate_list(codes):
                if not codes:
                    return []
                need_request_codes = set()
                if tool.trade_time_sub(tool.get_now_time_str(), "09:30:00") < 0:
                    need_request_codes |= set(codes)
                else:
                    now_time = time.time()
                    for c in codes:
                        if c not in self.__code_limit_rate_dict:
                            need_request_codes.add(c)
                        elif now_time - self.__code_limit_rate_dict[c][1] >  60:
                            need_request_codes.add(c)
                if need_request_codes:
                    _limit_rate_list = HistoryKDatasUtils.get_codes_limit_rate(list(need_request_codes))
                    for d in _limit_rate_list:
                        self.__code_limit_rate_dict[d[0]] = (d[1], time.time())
                return [(c_, self.__code_limit_rate_dict[c_][0]) for c_ in codes]
            # 获取上个交易日的相同涨停原因的代码信息
            ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()])
            code = ps_dict["code"]
@@ -535,18 +557,36 @@
                datas = self.__kplDataManager.get_from_file_cache(kpl_util.KPLDataType.LIMIT_UP, day)
                # (代码,名称,首次涨停时间,最近涨停时间,几板,涨停原因,板块,实际流通,主力净额,涨停原因代码,涨停原因代码数量)
                yesterday_result_list = []
                percent_rate = 0
                if datas:
                    yesterday_codes = set()
                    for d in datas:
                        if d[5] == reason and d[0] != code:
                            # (代码,名称)
                            yesterday_result_list.append((d[0], d[1]))
                        if d[5] == reason:
                            yesterday_codes.add(d[0])
                    # 获取涨幅
                    limit_rate_list = get_limit_rate_list(yesterday_codes)
                    limit_rate_dict = {}
                    if limit_rate_list:
                        total_rate = 0
                        for d in limit_rate_list:
                            limit_rate_dict[d[0]] = d[1]
                            total_rate += d[1]
                        percent_rate = round(total_rate / len(limit_rate_list), 2)
                    for d in datas:
                        if d[5] == reason:
                            yesterday_codes.add(d[0])
                            if d[0] != code:
                                # (代码,名称, 涨幅)
                                yesterday_result_list.append((d[0], d[1], limit_rate_dict.get(d[0])))
                current_limit_up_list = kpl_data_manager.KPLLimitUpDataRecordManager.latest_origin_datas
                current_result_list = []
                if current_limit_up_list:
                    for c in current_limit_up_list:
                        if c[5] == reason and c[0] != code:
                            current_result_list.append((c[0], c[1]))
                response_data = json.dumps({"code": 0, "data": {"reason": reason,
                response_data = json.dumps({"code": 0, "data": {"reason": reason, "reason_rate": percent_rate,
                                                                "data": {"yesterday": yesterday_result_list,
                                                                         "current": current_result_list}}})
            else:
@@ -638,6 +678,7 @@
                                logger_debug.exception(e)
                kpl_data_manager.KPLLimitUpDataRecordManager.save_record(tool.get_now_date_str(), result_list_)
                self.__kplDataManager.save_data(type_, result_list_)
        # 将"概念"二字替换掉
        data = json.loads(json.dumps(data).replace("概念", ""))
        type_ = data["type"]
third_data/history_k_data_util.py
@@ -307,10 +307,5 @@
if __name__ == "__main__":
    constant.JUEJIN_LOCAL_API = False
    print(tool.get_now_time_str())
    print(HistoryKDatasUtils.get_latest_trading_date(5))
    print(tool.get_now_time_str())
    print(HistoryKDatasUtils.get_latest_trading_date(5))
    print(tool.get_now_time_str())
    print(HistoryKDatasUtils.get_latest_trading_date(5))
    results = HistoryKDatasUtils.get_codes_limit_rate(list({"000422", "600610"}))
    print(results)