From ba52d7ac92a36f413eacaa686f8535e859664ec6 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 28 八月 2023 09:45:11 +0800 Subject: [PATCH] bug修改 --- third_data/data_server.py | 488 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 471 insertions(+), 17 deletions(-) diff --git a/third_data/data_server.py b/third_data/data_server.py index 6e1d7f8..24bb2de 100644 --- a/third_data/data_server.py +++ b/third_data/data_server.py @@ -1,32 +1,470 @@ -import base64 +import http import json -import logging import socketserver import time from http.server import BaseHTTPRequestHandler -import cv2 +import dask -import tool -from l2 import code_price_manager -from third_data import kpl_util, kpl_data_manager -from third_data.kpl_data_manager import KPLDataManager -from third_data.kpl_util import KPLDataType +from utils import global_util, tool +from code_attribute import gpcode_manager +from log_module import log, log_analyse, log_export +from l2 import code_price_manager, l2_data_util +from l2.cancel_buy_strategy import HourCancelBigNumComputer +from output.limit_up_data_filter import IgnoreCodeManager +from third_data import kpl_util, kpl_data_manager, kpl_api +from third_data.code_plate_key_manager import RealTimeKplMarketData, KPLPlateForbiddenManager +from third_data.history_k_data_util import HistoryKDatasUtils +from third_data.kpl_data_manager import KPLDataManager, KPLLimitUpDataRecordManager, \ + KPLCodeLimitUpReasonManager +from third_data.kpl_util import KPLDataType, KPLPlatManager import urllib.parse as urlparse +from urllib.parse import parse_qs +from output import code_info_output, limit_up_data_filter, output_util, kp_client_msg_manager -from trade import bidding_money_manager +from trade import bidding_money_manager, trade_manager +from trade.l2_trade_util import BlackListCodeManager class DataServer(BaseHTTPRequestHandler): ocr_temp_data = {} __kplDataManager = KPLDataManager() + __IgnoreCodeManager = IgnoreCodeManager() + __KPLPlatManager = KPLPlatManager() + __KPLCodeLimitUpReasonManager = KPLCodeLimitUpReasonManager() + __KPLPlateForbiddenManager = KPLPlateForbiddenManager() + # 鍘嗗彶鏉垮潡 + __history_plates_dict = {} + # 鏉垮潡 + __blocks_dict = {} + # 绮鹃��,琛屼笟鏁版嵁缂撳瓨 + __jingxuan_cache_dict = {} + __industry_cache_dict = {} + + + def __get_limit_up_list(self): + # 缁熻鐩墠涓烘鐨勪唬鐮佹定鍋滄暟閲忥紙鍒嗘定鍋滃師鍥狅級 + total_datas = KPLLimitUpDataRecordManager.total_datas + if not total_datas: + KPLLimitUpDataRecordManager.load_total_datas() + total_datas = KPLLimitUpDataRecordManager.total_datas + # 閫氳繃娑ㄥ仠鏃堕棿鎺掑簭 + total_datas = list(total_datas) + + # 缁熻娑ㄥ仠鍘熷洜 + limit_up_reason_dict = {} + for d in total_datas: + if d[2] not in limit_up_reason_dict: + limit_up_reason_dict[d[2]] = [] + limit_up_reason_dict[d[2]].append(d) + for k in limit_up_reason_dict: + limit_up_reason_dict[k].sort(key=lambda x: int(x[5])) + # 缁熻鎯充拱鍗曟暟閲� + want_codes = gpcode_manager.WantBuyCodesManager().list_code_cache() + limit_up_reason_want_count_dict = {} + for d in total_datas: + if d[2] not in limit_up_reason_want_count_dict: + limit_up_reason_want_count_dict[d[2]] = 0 + if d[3] in want_codes: + limit_up_reason_want_count_dict[d[2]] += 1 + # (鏉垮潡鍚嶇О锛屾定鍋滀唬鐮佹暟閲忥紝鎯充拱鍗曟暟閲�,娑ㄥ仠鏃堕棿) + limit_up_reason_statistic_info = [ + (k, len(limit_up_reason_dict[k]), limit_up_reason_want_count_dict.get(k), limit_up_reason_dict[k][0][5]) for + k in + limit_up_reason_dict] + limit_up_reason_statistic_info.sort(key=lambda x: int(x[3])) + + codes_set = set([d[3] for d in total_datas]) + # 鍒ゆ柇鏄緳鍑狅紝鍒ゆ柇鏄惁娑ㄥ仠锛屽垽鏂槸鍚︾偢鏉匡紝鍔犺浇鍒嗘暟 + rank_dict = limit_up_data_filter.get_limit_up_time_rank_dict(total_datas) + limit_up_dict, limit_up_codes, open_limit_up_codes = limit_up_data_filter.get_limit_up_info(codes_set) + score_dict = limit_up_data_filter.get_codes_scores_dict(codes_set) + fresult = [] + ignore_codes = self.__IgnoreCodeManager.list_ignore_codes("1") + + total_datas.sort(key=lambda x: int(x[5])) + total_datas.reverse() + + # 鑾峰彇娑ㄥ仠鍘熷洜鍙樺寲璁板綍 + reason_changes = log_export.load_kpl_reason_changes() + reason_changes.reverse() + reason_changes_dict = {} + for r in reason_changes: + if r[0] not in reason_changes_dict: + reason_changes_dict[r[0]] = r[1] + # 缁熻鏈�杩戜笅鍗曞姩浣滃弽棣� + order_reasons_dict = log_analyse.get_cant_order_reasons_dict() + kpl_can_buy_reasons_dict = log_analyse.get_kpl_can_buy_reasons_dict() + + for d in total_datas: + code = d[3] + # (浠g爜, 鍚嶇О, 娑ㄥ仠鐘舵��(0 - 鏃犵姸鎬� 1-娑ㄥ仠 2-鐐告澘), 榫欏嚑, 棣栨澘, 鍒嗗��, 娑ㄥ仠鏃堕棿, 鍘熷洜, 鐩稿悓鍘熷洜浠g爜鏁伴噺, 鑷敱娴侀��, 娑ㄥ仠鍘熷洜鏄惁鍙樺寲,娑ㄥ仠鍘熷洜鐨勬祦鍏ュ噣棰�,涓嬪崟绠�浠�) + limit_up_state = 0 + if code in limit_up_dict: + if limit_up_dict[code][0]: + limit_up_state = 1 + elif limit_up_dict[code][1]: + limit_up_state = 2 + score = "" + if code in score_dict: + score = score_dict[code] + if code in ignore_codes: + continue + + # 娑ㄥ仠鍘熷洜鐨勫噣娴佸叆閲戦 + reason = d[2] + reason_money = '' + if reason in self.__jingxuan_cache_dict: + reason_money = output_util.money_desc(self.__jingxuan_cache_dict[reason][3]) + elif reason in self.__industry_cache_dict: + reason_money = output_util.money_desc(self.__industry_cache_dict[reason][3]) + + # 鍖归厤涓嬪崟鍙嶉 + order_desc = '' + order_reason = order_reasons_dict.get(code) + kpl_can_buy_reason = kpl_can_buy_reasons_dict.get(code) + if order_reason and kpl_can_buy_reason: + if int(order_reason[0].replace(":", "").replace(".", "")) > int( + kpl_can_buy_reason[0].replace(":", "").replace(".", "")): + order_desc = f"涓嶏細{order_reason[1]}" + else: + order_desc = f"涔帮細{kpl_can_buy_reason[1]}" + elif order_reason: + order_desc = f"涓嶏細{order_reason[1]}" + elif kpl_can_buy_reason: + order_desc = f"涔帮細{kpl_can_buy_reason[1]}" + + fresult.append((code, d[4], limit_up_state, f"榫檣rank_dict.get(code)}", d[12], score, + output_util.time_format(int(d[5])), d[2], d[10], output_util.money_desc(d[13]), + reason_changes_dict.get(code), reason_money, order_desc)) + response_data = json.dumps({"code": 0, "data": {"limit_up_count": len(limit_up_codes), + "open_limit_up_count": len(open_limit_up_codes), + "limit_up_reason_statistic": limit_up_reason_statistic_info, + "limit_up_codes": fresult}}) + return response_data + + def __get_plate_info(self, ps_dict): + + @dask.delayed + def kpl_getStockIDPlate(code_): + temp_data = kpl_api.getStockIDPlate(code_) + return temp_data + + @dask.delayed + def kpl_getSonPlate(plate_code_): + if not plate_code: + return None + temp_data = kpl_api.getSonPlate(plate_code_) + return temp_data + + @dask.delayed + def kpl_getCodesByPlate(plate_code_): + if not plate_code: + return None + temp_data = kpl_api.getCodesByPlate(plate_code_) + return temp_data + + @dask.delayed + def request_data(f1_, f2_): + temp_data = f1_, f2_ + return temp_data + + # 鑾峰彇鏉垮潡鐨勪唬鐮� + fresult = {} + code = ps_dict["code"] + code_info = KPLLimitUpDataRecordManager.list_by_code(code, tool.get_now_date_str())[0] + hot_block_name = code_info[2] + plate_code = self.__KPLPlatManager.get_plat(hot_block_name) + f1 = kpl_getStockIDPlate(code) + # f2 = kpl_getSonPlate(plate_code) + f3 = kpl_getCodesByPlate(plate_code) + dask_result = request_data(f1, f3) + plate_info, codes_by_plate_info = dask_result.compute() + + if plate_info: + plate_info.sort(key=lambda x: x[2]) + plate_info.reverse() + fresult["plate"] = plate_info + + # 鑾峰彇浠g爜鐨勫巻鍙叉定鍋滄暟鎹�,(娑ㄥ仠鍘熷洜,鏃ユ湡,鏉垮潡) + fresult["code_records"] = KPLLimitUpDataRecordManager.get_latest_infos(code, 4, False)[:2] + # 鑾峰彇浠婃棩鏁版嵁 + fresult["today"] = (code_info[2], code_info[1], code_info[6]) + fresult["industry"] = global_util.code_industry_map.get(code) + if plate_code: + # 鑾峰彇寮哄害 + # datas = son_plate_info + # # (浠g爜,鍚嶇О,寮哄害) + # temp = kpl_util.parseSonPlat(datas) + # temp.sort(key=lambda x: x[2]) + # temp.reverse() + # fresult["plat_strength"] = temp + + # 鑾峰彇娑ㄥ仠鍘熷洜涓嬮潰鐨勫垪琛� + datas = codes_by_plate_info + # (浠g爜,鍚嶇О,鐜颁环,娑ㄥ箙,鑷敱娴侀��,鍑犳澘锛岄緳鍑狅紝涓诲姏鍑�棰�,300w鍑�棰�,鏈烘瀯澧炰粨) + temps = kpl_util.parsePlateCodes(datas) + # --鏁版嵁鍑嗗寮�濮�-- + codes_set = set([d[0] for d in temps]) + limit_up_dict, limit_up_codes, open_limit_up_codes = limit_up_data_filter.get_limit_up_info(codes_set) + score_dict = limit_up_data_filter.get_codes_scores_dict(codes_set) + want_codes = gpcode_manager.WantBuyCodesManager().list_code_cache() + black_codes = BlackListCodeManager().list_codes() + total_datas = KPLLimitUpDataRecordManager.total_datas + code_info_dict = {} + for val in total_datas: + code_info_dict[val[3]] = val + + # --鏁版嵁鍑嗗缁撴潫-- + + ignore_codes = self.__IgnoreCodeManager.list_ignore_codes("2") + # 鏈�缁堢粨鏋滐細(浠g爜,鍚嶇О,娑ㄥ仠鐘舵��(0-鏃犵姸鎬� 1-娑ㄥ仠 2-鐐告澘),榫欏嚑,棣栨澘,鍒嗗��,娑ㄥ仠鏃堕棿,鍘熷洜,鐩稿悓鍘熷洜浠g爜鏁伴噺,鑷敱娴侀��,娑ㄥ仠鍘熷洜鏄惁鍙樺寲,娑ㄥ箙,鐜颁环,榛戝悕鍗�,鎯充拱鍗�,涓诲姏鍑�鍊�,300w,) + codes_info_list = [] + for t in temps: + code = t[0] + limit_up_state = 0 + if code in limit_up_dict: + if limit_up_dict[code][0]: + limit_up_state = 1 + elif limit_up_dict[code][1]: + limit_up_state = 2 + score = "" + if code in score_dict: + score = score_dict[code] + + limit_up_time = '' + if code in code_info_dict: + limit_up_time = output_util.time_format(code_info_dict[code][5]) + final_code_info = {"code_info": ( + t[0], t[1], limit_up_state, t[6], t[5], score, limit_up_time, + code_info[2], code_info[10], output_util.money_desc(t[4]), 0, t[3], t[2], + "榛戝悕鍗�" if code in black_codes else "", "鎯充拱鍗�" if code in want_codes else "", + output_util.money_desc(t[7]), output_util.money_desc(t[8]), output_util.money_desc(t[9]))} + if code in code_info_dict: + final_code_info["today"] = ( + code_info_dict[code][2], code_info_dict[code][1], code_info_dict[code][6]) + # 鍔犺浇鍘嗗彶 + if code in self.__history_plates_dict: + final_code_info["code_records"] = self.__history_plates_dict[code][1] + # 鍔犺浇鏉垮潡 + if code in self.__blocks_dict: + final_code_info["plate"] = self.__blocks_dict[code][1] + + # 鑾峰彇浜岀骇琛屼笟 + final_code_info["industry"] = global_util.code_industry_map.get(code) + + if code not in ignore_codes: + codes_info_list.append(final_code_info) + fresult["code_list_info"] = codes_info_list + response_data = json.dumps({"code": 0, "data": fresult}) + return response_data def do_GET(self): path = self.path + url = urlparse.urlparse(path) + response_data = "" + if url.path == "/get_kpl_data": + best_feng_kou = self.__kplDataManager.get_data(kpl_util.KPLDataType.BEST_FENG_KOU) + if not best_feng_kou: + best_feng_kou = [] + best_feng_kou = best_feng_kou[:22] + feng_kou = self.__kplDataManager.get_data(kpl_util.KPLDataType.FENG_KOU) + if not feng_kou: + feng_kou = [] + feng_kou = feng_kou[:22] + industry_rank = self.__kplDataManager.get_data(kpl_util.KPLDataType.INDUSTRY_RANK) + if not industry_rank: + industry_rank = [] + industry_rank = industry_rank[:22] + feng_xiang = self.__kplDataManager.get_data(kpl_util.KPLDataType.FENG_XIANG) + if not feng_xiang: + feng_xiang = [] + feng_xiang = feng_xiang[:22] + response_data = json.dumps({"code": 0, "data": {"best_feng_kou": best_feng_kou, "feng_kou": feng_kou, + "industry_rank": industry_rank, "feng_xiang": feng_xiang}}) + elif url.path == "/get_score_info": + start_time = time.time() + ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) + code = ps_dict['code'] + name = ps_dict.get('name') + + data = code_info_output.get_output_params(code, self.__jingxuan_cache_dict, self.__industry_cache_dict) + if data["code_name"].find("None") > -1 and name: + data["code_name"] = f"{name} {code}" + + self.__history_plates_dict[code] = (time.time(), data["kpl_code_info"]["code_records"]) + if "plate" in data["kpl_code_info"]: + self.__blocks_dict[code] = (time.time(), data["kpl_code_info"]["plate"]) + + response_data = json.dumps({"code": 0, "data": data}) + print("get_score_info 鑰楁椂锛�", time.time() - start_time) + + # 鑾峰彇璇勫垎淇℃伅 + pass + elif url.path == "/kpl/get_limit_up_list": + response_data = self.__get_limit_up_list() + + elif url.path == "/kpl/get_plate_info": + ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) + response_data = self.__get_plate_info(ps_dict) + + elif url.path == "/kpl/get_market_data": + # 鑾峰彇鏉垮潡淇℃伅 + ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) + type_ = int(ps_dict['type']) + result = [] + if type_ == 0: + # 琛屼笟锛屼富鍔涘噣棰濆�掑簭 + result = kpl_api.getMarketIndustryRealRankingInfo(True) + result = kpl_util.parseMarketIndustry(result) + elif type_ == 1: + # 琛屼笟锛屼富鍔涘噣棰濋『搴� + result = kpl_api.getMarketIndustryRealRankingInfo(False) + result = kpl_util.parseMarketIndustry(result) + elif type_ == 2: + # 绮鹃�夛紝涓诲姏鍑�棰濆�掑簭 + result = kpl_api.getMarketJingXuanRealRankingInfo(True) + result = kpl_util.parseMarketJingXuan(result) + elif type_ == 3: + # 绮鹃�夛紝涓诲姏鍑�棰濋『搴� + result = kpl_api.getMarketJingXuanRealRankingInfo(False) + result = kpl_util.parseMarketJingXuan(result) + forbidden_plates = self.__KPLPlateForbiddenManager.list_all() + fresult = [] + for d in result: + if type_ == 2 or type_ == 3: + self.__jingxuan_cache_dict[d[1]] = d + elif type_ == 0 or type_ == 1: + self.__industry_cache_dict[d[1]] = d + d = list(d) + d.append(1 if d[1] in forbidden_plates else 0) + fresult.append(d) + response_data = json.dumps({"code": 0, "data": fresult}) + elif url.path == "/kpl/add_ignore_code": + ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) + code = ps_dict['code'] + type_ = ps_dict['type'] + self.__IgnoreCodeManager.ignore_code(type_, code) + response_data = json.dumps({"code": 0}) + elif url.path == "/kpl/forbidden_plate": + ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) + plate = ps_dict["plate"] + # 鍔犲叆绂佹 + self.__KPLPlateForbiddenManager.save_plate(plate) + response_data = json.dumps({"code": 0}) + elif url.path == "/kpl/get_plate_codes": + # 鑾峰彇娑ㄥ仠鍘熷洜涓嬮潰鐨勪唬鐮� + ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) + plate = ps_dict["plate"] + # 鑾峰彇鏉垮潡涓嬬殑浠g爜 + # 缁熻鐩墠涓烘鐨勪唬鐮佹定鍋滄暟閲忥紙鍒嗘定鍋滃師鍥狅級 + now_limit_up_codes_info = self.__kplDataManager.get_data(KPLDataType.LIMIT_UP) + now_limit_up_codes = set([d[0] for d in now_limit_up_codes_info]) + # 鑾峰彇鍘嗗彶娑ㄥ仠 + record_limit_up_datas = KPLLimitUpDataRecordManager.total_datas + if not record_limit_up_datas: + KPLLimitUpDataRecordManager.load_total_datas() + record_limit_up_datas = KPLLimitUpDataRecordManager.total_datas + + codes_info = [] + for d in record_limit_up_datas: + if d[2] != plate: + continue + # 浠g爜,鍚嶇О,娑ㄥ仠鏃堕棿,鏄惁鐐告澘,鏄惁鎯充拱,鏄惁宸茬粡涓嬭繃鍗� + codes_info.append( + [d[3], d[4], tool.to_time_str(int(d[5])), 1 if d[3] not in now_limit_up_codes else 0, 0, 0]) + codes_info.sort(key=lambda x: x[2]) + # 鏌ヨ鏄惁涓烘兂涔板崟 + want_codes = gpcode_manager.WantBuyCodesManager().list_code_cache() + for code_info in codes_info: + code_info[4] = 1 if code_info[0] in want_codes else 0 + # 鑾峰彇浠g爜鐘舵�� + if trade_manager.CodesTradeStateManager().get_trade_state_cache(code_info[0]) != trade_manager.TRADE_STATE_NOT_TRADE: + code_info[5] = 1 + + response_data = json.dumps({"code": 0, "data": codes_info}) + elif url.path == "/get_h_cancel_data": + ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) + code = ps_dict["code"] + if code: + total_datas = l2_data_util.local_today_datas.get(code) + if total_datas is None: + l2_data_util.load_l2_data(code) + total_datas = l2_data_util.local_today_datas.get(code) + + trade_state = trade_manager.CodesTradeStateManager().get_trade_state_cache(code) + if trade_state == trade_manager.TRADE_STATE_BUY_PLACE_ORDER or trade_state == trade_manager.TRADE_STATE_BUY_DELEGATED or trade_state == trade_manager.TRADE_STATE_BUY_SUCCESS: + hcancel_datas_dict, cancel_indexes_set = HourCancelBigNumComputer().get_watch_index_dict(code) + # 鏍规嵁鏃ュ織璇诲彇瀹炴椂鐨勮绠楁暟鎹� + h_cancel_latest_compute_info = log_export.get_h_cancel_compute_info(code) + if hcancel_datas_dict: + temp_list = [(k, hcancel_datas_dict[k][0]) for k in hcancel_datas_dict] + canceled_indexs = set([int(k.split("-")[0]) for k in cancel_indexes_set]) + temp_list.sort(key=lambda x: x[0]) + fdata = { + "computed_info": list( + h_cancel_latest_compute_info) if h_cancel_latest_compute_info else None, + "datas": []} + for i in range(0, len(temp_list)): + temp = temp_list[i] + val = total_datas[temp[0]]["val"] + canceled = temp[0] in canceled_indexs + fdata["datas"].append( + (val["time"], val["num"], + code_info_output.money_desc(val["num"] * float(val["price"]) * 100), + (1 if canceled else 0))) + response_data = json.dumps({"code": 0, "data": fdata}) + else: + response_data = json.dumps({"code": 1, "msg": "鏃燞鎾ゆ暟鎹�"}) + else: + response_data = json.dumps({"code": 1, "msg": "鏃燞鎾ゆ暟鎹�"}) + else: + response_data = json.dumps({"code": 1, "msg": "璇蜂笂浼燾ode"}) + + elif url.path == "/get_last_trade_day_reasons": + # 鑾峰彇涓婁釜浜ゆ槗鏃ョ殑鐩稿悓娑ㄥ仠鍘熷洜鐨勪唬鐮佷俊鎭� + ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) + code = ps_dict["code"] + day = HistoryKDatasUtils.get_previous_trading_date(tool.get_now_date_str()) + # 鑾峰彇娑ㄥ仠鏁版嵁 + + # 鑾峰彇浠g爜鐨勫師鍥� + reasons = kpl_data_manager.KPLLimitUpDataRecordManager.list_by_code(code, day) + if reasons: + reasons = list(reasons) + reasons.sort(key=lambda x: x[9]) + reason = reasons[-1][2] + datas = self.__kplDataManager.get_from_file(kpl_util.KPLDataType.LIMIT_UP, day) + # (浠g爜,鍚嶇О,棣栨娑ㄥ仠鏃堕棿,鏈�杩戞定鍋滄椂闂�,鍑犳澘,娑ㄥ仠鍘熷洜,鏉垮潡,瀹為檯娴侀��,涓诲姏鍑�棰�,娑ㄥ仠鍘熷洜浠g爜,娑ㄥ仠鍘熷洜浠g爜鏁伴噺) + result_list = [] + if datas: + for d in datas: + if d[5] == reason and d[0] != code: + # (浠g爜,鍚嶇О) + result_list.append((d[0], d[1])) + response_data = json.dumps({"code": 0, "data": {"reason": reason, "data": result_list}}) + else: + response_data = json.dumps({"code": 1, "msg": "鏄ㄦ棩鏈定鍋�"}) + + elif url.path == "/pull_kp_client_msg": + # 鎷夊彇瀹㈡埛绔秷鎭� + ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()]) + client = ps_dict["client"] + msg = kp_client_msg_manager.read_msg(client) + if msg: + response_data = json.dumps({"code": 0, "data": msg}) + else: + response_data = json.dumps({"code": 1, "msg": "鏆傛棤娑堟伅"}) + elif url.path == "/list_kp_client_msg": + msg_list = kp_client_msg_manager.list_msg_from_local() + msg_list.reverse() + msg_list = [f"{msg.split('|')[0]}{msg.split('|')[-1].split('-')[1].strip()}" for msg in msg_list] + response_data = json.dumps({"code": 0, "data": msg_list}) + self.send_response(200) # 鍙戠粰璇锋眰瀹㈡埛绔殑鍝嶅簲鏁版嵁 self.send_header('Content-type', 'application/json') self.end_headers() - self.wfile.write("".encode()) + self.wfile.write(response_data.encode()) def do_POST(self): path = self.path @@ -39,9 +477,9 @@ def __process_kpl_data(self, data): type_ = data["type"] - print("寮�鐩樺暒type:",type_) + print("寮�鐩樺暒type:", type_) if type_ == KPLDataType.BIDDING.value: - result_list = kpl_util.parseDaBanData(data["data"], kpl_util.DABAN_TYPE_LIMIT_UP) + result_list = kpl_util.parseDaBanData(data["data"], kpl_util.DABAN_TYPE_BIDDING) # 绔炰环鍙栧墠20 if result_list: result_list.sort(key=lambda x: x[2]) @@ -49,7 +487,7 @@ result_list = result_list[:20] bs = [] for d in result_list: - bs.append((d[0], f"{d[2] // 10000 }涓�")) + bs.append((d[0], f"{d[2] // 10000}涓�")) bidding_money_manager.set_bidding_money(bs[:10]) self.__kplDataManager.save_data(type_, result_list) @@ -61,9 +499,9 @@ code = d[0] if code.find("00") == 0 or code.find("60") == 0: limit_up_time = time.strftime("%H:%M:%S", time.localtime(d[2])) - code_price_manager.Buy1PriceManager.set_limit_up_time(code, limit_up_time) + code_price_manager.Buy1PriceManager().set_limit_up_time(code, limit_up_time) self.__kplDataManager.save_data(type_, result_list) - kpl_data_manager.KPLLimitUpDataRecordManager.save_record(tool.get_now_date_str(),result_list) + kpl_data_manager.KPLLimitUpDataRecordManager.save_record(tool.get_now_date_str(), result_list) elif type_ == KPLDataType.OPEN_LIMIT_UP.value: result_list = kpl_util.parseDaBanData(data["data"], kpl_util.DABAN_TYPE_OPEN_LIMIT_UP) if result_list: @@ -94,9 +532,16 @@ self.__kplDataManager.save_data(type_, result_list) elif type_ == KPLDataType.INDUSTRY_RANK.value: result_list = kpl_util.parseIndustryRank(data["data"]) - # 淇濆瓨椋庡悜鏁版嵁 + # 淇濆瓨琛屼笟鏁版嵁 if result_list: self.__kplDataManager.save_data(type_, result_list) + RealTimeKplMarketData.set_top_5_industry(result_list) + elif type_ == KPLDataType.JINGXUAN_RANK.value: + result_list = kpl_util.parseMarketJingXuan(data["data"]) + # 淇濆瓨绮鹃�夋暟鎹� + if result_list: + self.__kplDataManager.save_data(type_, result_list) + RealTimeKplMarketData.set_top_5_reasons(result_list) return json.dumps({"code": 0}) def __send_response(self, data): @@ -115,9 +560,18 @@ return params +class ThreadedHTTPServer(socketserver.ThreadingMixIn, http.server.HTTPServer): + pass + + def run(addr, port): + # 杩愯鐪嬬洏娑堟伅閲囬泦 + # kp_client_msg_manager.run_capture() + kpl_data_manager.run_pull_task() + handler = DataServer - httpd = socketserver.TCPServer((addr, port), handler) + # httpd = socketserver.TCPServer((addr, port), handler) + httpd = ThreadedHTTPServer((addr, port), handler) print("HTTP server is at: http://%s:%d/" % (addr, port)) httpd.serve_forever() -- Gitblit v1.8.0