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/history_k_data_util.py | 64 ++++++++++++++----------------- 1 files changed, 29 insertions(+), 35 deletions(-) diff --git a/third_data/history_k_data_util.py b/third_data/history_k_data_util.py index cac3680..7f014eb 100644 --- a/third_data/history_k_data_util.py +++ b/third_data/history_k_data_util.py @@ -8,10 +8,10 @@ import requests import constant -from db.redis_manager import RedisUtils -from utils import tool -from db import redis_manager -import gm.api as gmapi +from db.redis_manager_delegate import RedisUtils +from utils import tool, middle_api_protocol +from db import redis_manager_delegate as redis_manager +# import gm.api as gmapi class JueJinHttpApi: @@ -25,25 +25,32 @@ return datetime.datetime.fromisoformat(val) return val - url = f'{cls.__BASE_URL}{path_str}' - # 鍙戦�丳OST璇锋眰 - response = requests.post(url, json=data_json) - result = response.text - resultJson = json.loads(result) - if resultJson['code'] == 0: - data = resultJson['data'] - if type(data) == list: - for d in data: + DELEGATE = True + fdata = None + if DELEGATE: + fdata = middle_api_protocol.load_juejin(path_str, data_json) + fdata = middle_api_protocol.request(fdata) + else: + url = f'{cls.__BASE_URL}{path_str}' + # 鍙戦�丳OST璇锋眰 + response = requests.post(url, json=data_json) + result = response.text + resultJson = json.loads(result) + if resultJson['code'] == 0: + fdata = resultJson['data'] + if fdata: + if type(fdata) == list: + for d in fdata: if type(d) != dict: continue for k in d: d[k] = deformat_date(d[k]) - elif type(data) == dict: - for k in data: - data[k] = deformat_date(data[k]) - return data - - return None + elif type(fdata) == dict: + for k in fdata: + fdata[k] = deformat_date(fdata[k]) + return fdata + else: + return None @classmethod def get_instruments(cls, symbols, fields): @@ -87,12 +94,11 @@ redis = cls.__redisManager.getRedis() try: account_id = RedisUtils.get(redis, "juejin-account-id", auto_free=False) - strategy_id =RedisUtils.get(redis, "juejin-strategy-id", auto_free=False) + strategy_id = RedisUtils.get(redis, "juejin-strategy-id", auto_free=False) token = RedisUtils.get(redis, "juejin-token", auto_free=False) return account_id, strategy_id, token finally: - redis.connection_pool.disconnect() - + RedisUtils.realse(redis) @classmethod def get_juejin_code_list_with_prefix(cls, codes): @@ -269,16 +275,4 @@ if __name__ == "__main__": constant.JUEJIN_LOCAL_API = False - list_ = JueJinApi.get_exchanges_codes(["SHSE","SZSE"]) - fdatas = [] - for d in list_: - if d["sec_id"].find("60") != 0 and d["sec_id"].find("00") != 0: - continue - if d["sec_level"] != 1: - continue - if d["pre_close"] * 1.1 > 40: - continue - if (d["listed_date"] + datetime.timedelta(days=100)).timestamp() > datetime.datetime.now().timestamp(): - continue - fdatas.append(d) - print(len(fdatas)) + print(HistoryKDatasUtils.get_lowest_price_rate("000725", 30)) -- Gitblit v1.8.0