From d0fd153d07f9bd41cf0a30ddce30402eaef83da3 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期二, 14 十一月 2023 09:26:46 +0800 Subject: [PATCH] A类/B类一键切换 --- code_attribute/code_nature_analyse.py | 61 +++++++++++++++++++++++++++++- 1 files changed, 59 insertions(+), 2 deletions(-) diff --git a/code_attribute/code_nature_analyse.py b/code_attribute/code_nature_analyse.py index d63d23b..89a63b3 100644 --- a/code_attribute/code_nature_analyse.py +++ b/code_attribute/code_nature_analyse.py @@ -5,6 +5,8 @@ # 鏄惁鏈夋定鍋� import copy import json +import random +import time from code_attribute import gpcode_manager @@ -117,6 +119,51 @@ RedisUtils.delete_async(self.__db, k) +# 娑ㄥ箙杩囬珮鐨勭エ绠$悊 +class HighIncreaseCodeManager: + __db = 0 + __instance = None + __redis_manager = redis_manager.RedisManager(0) + __high_increase_codes = set() + + def __new__(cls, *args, **kwargs): + if not cls.__instance: + cls.__instance = super(HighIncreaseCodeManager, cls).__new__(cls, *args, **kwargs) + cls.__load_datas() + return cls.__instance + + @classmethod + def __load_datas(cls): + __redis = cls.__get_redis() + try: + cls.__high_increase_codes = RedisUtils.smembers(__redis, "high_increase_codes") + finally: + RedisUtils.realse(__redis) + + @classmethod + def __get_redis(cls): + return cls.__redis_manager.getRedis() + + def add_code(self, code): + if self.__high_increase_codes is None: + self.__high_increase_codes = set() + self.__high_increase_codes.add(code) + RedisUtils.sadd_async(self.__db, "high_increase_codes", code) + RedisUtils.expire_async(self.__db, "high_increase_codes", tool.get_expire()) + + def is_in(self, code): + return code in self.__high_increase_codes + + # 鍔犺浇鍏ㄩ儴 + def list_all(self): + return self.__high_increase_codes + + def clear(self): + if self.__high_increase_codes: + self.__high_increase_codes.clear() + RedisUtils.delete_async(self.__db, "high_increase_codes") + + # 璁剧疆鍘嗗彶K绾� def set_record_datas(code, limit_up_price, record_datas): k_format = get_k_format(float(limit_up_price), record_datas) @@ -188,14 +235,19 @@ datas = datas[-10:] limit_ups = [] limit_up_count = 0 + max_price = datas[0]["high"] for data in datas: limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(data["pre_close"])) date = data['bob'].strftime("%Y-%m-%d") + if data["high"] > max_price: + max_price = data["high"] if abs(limit_up_price - data["high"]) < 0.01: limit_ups.append((date, True)) limit_up_count += 1 else: limit_ups.append((date, False)) + # 涓嬮檷骞呭害 + limit_down_rate = round((max_price - datas[-1]["close"]) / max_price, 3) if limit_up_count < 3: return False @@ -208,8 +260,10 @@ for t in temp_datas: if t[1]: t_count += 1 - if t_count >= 3: + if t_count >= 3 and limit_down_rate < 0.15: + # 闄嶅箙灏忎簬20% return True + return False @@ -484,4 +538,7 @@ if __name__ == "__main__": - print(CodeNatureRecordManager.get_k_format("603717")) + HighIncreaseCodeManager().add_code("000333") + print(HighIncreaseCodeManager().is_in("000333")) + print(HighIncreaseCodeManager().is_in("000222")) + -- Gitblit v1.8.0