From f4333824e6fc82eb7e6c0ff536f31baf6c7c8df2 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 26 六月 2025 14:21:47 +0800
Subject: [PATCH] L后自然最大撤单率最大80%
---
code_attribute/code_volumn_manager.py | 313 ++++++++++++++++++++++++++++++++++++---------------
1 files changed, 221 insertions(+), 92 deletions(-)
diff --git a/code_attribute/code_volumn_manager.py b/code_attribute/code_volumn_manager.py
index a55a39a..d5164f0 100644
--- a/code_attribute/code_volumn_manager.py
+++ b/code_attribute/code_volumn_manager.py
@@ -7,104 +7,233 @@
# yesterday 鏄ㄥぉ鐨勯噺
import json
+from code_attribute import gpcode_manager, code_nature_analyse
+from db.redis_manager_delegate import RedisUtils
+from log_module import async_log_util
from utils import global_util, tool
-from db import redis_manager
-from logs.log import logger_day_volumn
-
-__redis_manager = redis_manager.RedisManager(0)
+from db import redis_manager_delegate as redis_manager
+from log_module.log import logger_day_volumn
-# 璁剧疆鍘嗗彶閲�
-def set_histry_volumn(code, max60, yesterday, max60_day=''):
- redis = __redis_manager.getRedis()
- global_util.max60_volumn[code] = (max60, max60_day)
- global_util.yesterday_volumn[code] = yesterday
- redis.setex("volumn_max60-{}".format(code), tool.get_expire(), json.dumps((max60, max60_day)))
- redis.setex("volumn_yes-{}".format(code), tool.get_expire(), yesterday)
+class CodeVolumeManager:
+ __db = 0
+ __redis_manager = redis_manager.RedisManager(0)
+ __instance = None
+ __today_volumn_cache = {}
+ __reference_volume_as_money_y_dict = {}
+ __max_volume_in_5days = {}
+ def __new__(cls, *args, **kwargs):
+ if not cls.__instance:
+ cls.__instance = super(CodeVolumeManager, cls).__new__(cls, *args, **kwargs)
+ cls.__load_data()
+ return cls.__instance
-# 鑾峰彇鍘嗗彶閲�
-def get_histry_volumn(code):
- max60 = global_util.max60_volumn.get(code)
- yesterday = global_util.yesterday_volumn.get(code)
- redis = __redis_manager.getRedis()
- if max60 is None:
- max60 = redis.get("volumn_max60-{}".format(code))
+ # 灏嗛噺浠庢暟鎹簱鍔犲叆鍐呭瓨
+ @classmethod
+ def __load_data(cls):
+ redis = cls.__redis_manager.getRedis()
+ try:
+ keys = RedisUtils.keys(redis, "volumn_max60-*", auto_free=False)
+ if keys is not None:
+ for k in keys:
+ code = k.split("-")[1]
+ max60_volumn = RedisUtils.get(redis, k, auto_free=False)
+ if max60_volumn:
+ max60_volumn = json.loads(max60_volumn)
+ global_util.max60_volumn[code] = max60_volumn
+ keys = RedisUtils.keys(redis, "volumn_yes-*", auto_free=False)
+ if keys is not None:
+ for k in keys:
+ code = k.split("-")[1]
+ global_util.yesterday_volumn[code] = RedisUtils.get(redis, k, auto_free=False)
+ keys = RedisUtils.keys(redis, "volumn_max_5days-*", auto_free=False)
+ if keys is not None:
+ for k in keys:
+ code = k.split("-")[1]
+ val = RedisUtils.get(redis, k, auto_free=False)
+ cls.__max_volume_in_5days[code] = int(val)
+ finally:
+ RedisUtils.realse(redis)
+
+ # 璁剧疆鍘嗗彶閲�
+ def set_histry_volumn(self, code, max60, yesterday, max60_day, max60_day_count, max5_volume):
+ redis = self.__redis_manager.getRedis()
+ global_util.max60_volumn[code] = (max60, max60_day, max60_day_count)
+ global_util.yesterday_volumn[code] = yesterday
+ self.__save_max_volume_in_5days(code, max5_volume)
+ try:
+ RedisUtils.setex_async(self.__db, "volumn_max60-{}".format(code), tool.get_expire(),
+ json.dumps((max60, max60_day, max60_day_count)),
+ auto_free=False)
+ RedisUtils.setex_async(self.__db, "volumn_yes-{}".format(code), tool.get_expire(), yesterday,
+ auto_free=False)
+ finally:
+ RedisUtils.realse(redis)
+
+ def __save_max_volume_in_5days(self, code, volume):
+ self.__max_volume_in_5days[code] = volume
+ RedisUtils.setex_async(self.__db, "volumn_max_5days-{}".format(code), tool.get_expire(), volume,
+ auto_free=False)
+
+ def get_max_volume_in_5days(self, code):
+ """
+ 5鏃ユ渶澶ч噺
+ @param code:
+ @return:
+ """
+ return self.__max_volume_in_5days.get(code)
+
+ def get_radical_buy_refer_volume(self, code, limit_up_price):
+ """
+ 鑾峰彇鎵叆鐨勫弬鑰冮噺:
+ 鍙傝�冮灏忎簬3.14浜垮氨鍙�90澶╁弬鑰冮噺
+ 鍚﹀垯灏卞彇鏈�杩�5澶╃殑鍙傝�冮噺
+ @param code:
+ @param limit_up_price:
+ @return:
+ """
+ # 60涓氦鏄撴棩鏈定鍋滃彇
+ k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code)
+ has_limit_up_in_60 = True
+ if k_format and not k_format[13]:
+ has_limit_up_in_60 = False
+ volume = self.get_max_volume_in_5days(code)
+ if volume * limit_up_price >= 3.14e8 and has_limit_up_in_60:
+ return volume
+ return int(self.get_reference_volume_as_money_y(code) * 1e8 / limit_up_price)
+
+ def get_volume_rate_refer_in_5days(self, code, total_sell_volume=0):
+ """
+ 鑾峰彇浠婃棩閲忎笌5鏃ユ渶澶ч噺鐨勫弬鑰冨��
+ @param total_sell_volume: 褰撳墠鎬诲崠閲�
+ @param code:
+ @return: 5鏃ラ噺姣�
+ """
+ max_volume = self.get_max_volume_in_5days(code)
+ if not max_volume:
+ return 0
+ today_volume = self.get_today_volumn(code)
+ return round((today_volume + total_sell_volume) / max_volume, 2)
+
+ # 鑾峰彇鍘嗗彶閲�
+ def get_histry_volumn(self, code):
+ max60 = global_util.max60_volumn.get(code)
+ yesterday = global_util.yesterday_volumn.get(code)
+ redis = self.__redis_manager.getRedis()
+ try:
+ if max60 is None:
+ max60 = RedisUtils.get(redis, "volumn_max60-{}".format(code), auto_free=False)
+ if max60:
+ max60 = json.loads(max60)
+ if yesterday is None:
+ yesterday = RedisUtils.get(redis, "volumn_yes-{}".format(code), auto_free=False)
+ return max60, yesterday
+ finally:
+ RedisUtils.realse(redis)
+
+ # 閲忕殑鍙樺寲澶т繚瀛�
+
+ # 璁剧疆浠婃棩閲�
+ def set_today_volumn(self, code, volumn):
+ async_log_util.info(logger_day_volumn, "code:{} volumn:{}".format(code, volumn))
+ global_util.today_volumn[code] = volumn
+ # 鏈�1000鎵嬬殑鍙樺寲鎵嶄繚瀛�
+ if code in self.__today_volumn_cache and volumn - self.__today_volumn_cache[code] < 100000:
+ return
+ self.__today_volumn_cache[code] = volumn
+ RedisUtils.setex(self.__redis_manager.getRedis(), "volumn_today-{}".format(code), tool.get_expire(), volumn)
+
+ # datas:[(code, volumn)]
+ def set_today_volumns(self, datas):
+ for d in datas:
+ code, volumn = d
+ async_log_util.info(logger_day_volumn, "code:{} volumn:{}".format(code, volumn))
+ global_util.today_volumn[code] = volumn
+ # 鏈�1000鎵嬬殑鍙樺寲鎵嶄繚瀛�
+ if code in self.__today_volumn_cache and volumn - self.__today_volumn_cache[code] < 100000:
+ continue
+ self.__today_volumn_cache[code] = volumn
+ RedisUtils.setex_async(self.__db, "volumn_today-{}".format(code), tool.get_expire(), volumn)
+
+ # 鑾峰彇浠婃棩閲�
+ def get_today_volumn(self, code):
+ _volumn = global_util.today_volumn.get(code)
+ if _volumn is None:
+ _volumn = RedisUtils.get(self.__redis_manager.getRedis(), "volumn_today-{}".format(code))
+ return _volumn
+
+ # 鑾峰彇浠婃棩閲�
+ def get_today_volumn_cache(self, code):
+ return global_util.today_volumn.get(code)
+
+ # 鑾峰彇閲忔瘮锛堜粖鏃ラ噺/max(60澶╂渶澶ч噺,鏄ㄦ棩閲�)锛�
+ # 灏嗘�诲崠閲忚绠楀湪鍐�
+ def get_volume_rate(self, code, total_sell_volume=0, with_info=False):
+ today = self.get_today_volumn(code)
+ max60, yesterday = self.get_histry_volumn(code)
+ if today is None:
+ today = 0
+ if max60 is None or yesterday is None:
+ max60 = [today, '']
+ yesterday = today
+ if max60[0] < 1:
+ max60[0] = 1
+ rate = round((int(today) + total_sell_volume) / max(int(max60[0]), int(yesterday)), 2)
+ if not with_info:
+ return rate
+ return rate, (today, max(int(max60[0]), int(yesterday)))
+
+ # 鑾峰彇閲忓弬鑰冩棩鏈�
+ # 杩斿洖(鍙傝�冮噺鏃ユ湡,璺濅粖鐨勪氦鏄撴棩涓暟)
+ def get_volume_refer_date(self, code):
+ max60, yesterday = self.get_histry_volumn(code)
+ if max60 is None or yesterday is None:
+ raise Exception("鑾峰彇澶辫触")
+ if int(max60[0]) >= int(yesterday):
+ return max60[1], max60[2]
+ else:
+ return "涓婁釜浜ゆ槗鏃�", 0
+
+ # 鑾峰彇閲忔瘮绱㈠紩
+ def get_volume_rate_index(self, volume_rate):
+ rates = [0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6]
+ for index in range(0, len(rates)):
+ if volume_rate <= rates[index]:
+ return index
+ return len(rates) - 1
+
+ # 淇濆瓨浠婃棩閲�
+ def save_today_volumn(self, code, volumn, volumnUnit):
+ _volumn = None
+ if volumnUnit == 0:
+ _volumn = round(float(volumn) * 100000000)
+ elif volumnUnit == 1:
+ _volumn = round(float(volumn) * 10000)
+ elif volumnUnit == 2:
+ _volumn = int(volumn)
+ if _volumn is not None:
+ self.set_today_volumn(code, _volumn * 100)
+
+ def get_reference_volume_as_money_y(self, code):
+ """
+ 杩斿洖鍙傝�冮噺浠婃棩瀵瑰簲鐨勯噾棰濓紙鍗曚綅涓轰嚎锛�
+ @param code:
+ @return:
+ """
+ if code in self.__reference_volume_as_money_y_dict:
+ return self.__reference_volume_as_money_y_dict.get(code)
+ max60, yesterday = self.get_histry_volumn(code)
if max60:
- max60 = json.loads(max60)
- if yesterday is None:
- yesterday = redis.get("volumn_yes-{}".format(code))
- return max60, yesterday
-
-
-# 璁剧疆浠婃棩閲�
-def set_today_volumn(code, volumn):
- logger_day_volumn.info("code:{} volumn:{}".format(code, volumn))
- redis = __redis_manager.getRedis()
- global_util.today_volumn[code] = volumn
- redis.setex("volumn_today-{}".format(code), tool.get_expire(), volumn)
-
-
-# 鑾峰彇浠婃棩閲�
-def get_today_volumn(code):
- _volumn = global_util.today_volumn.get(code)
- redis = __redis_manager.getRedis()
- if _volumn is None:
- _volumn = redis.get("volumn_today-{}".format(code))
- return _volumn
-
-
-# 鑾峰彇閲忔瘮锛堜粖鏃ラ噺/max(60澶╂渶澶ч噺,鏄ㄦ棩閲�)锛�
-def get_volume_rate(code, with_info=False):
- today = get_today_volumn(code)
- max60, yesterday = get_histry_volumn(code)
- if today is None or max60 is None or yesterday is None:
- raise Exception("鑾峰彇閲忓け璐�")
- rate = round(int(today) / max(int(max60[0]), int(yesterday)), 2)
- if not with_info:
- return rate
- return rate, (today, max(int(max60[0]), int(yesterday)))
-
-
-# 鑾峰彇閲忔瘮绱㈠紩
-def get_volume_rate_index(volume_rate):
- rates = [0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6]
- for index in range(0, len(rates)):
- if volume_rate <= rates[index]:
- return index
- return len(rates) - 1
-
-
-# 淇濆瓨浠婃棩閲�
-def save_today_volumn(code, volumn, volumnUnit):
- _volumn = None
- if volumnUnit == 0:
- _volumn = round(float(volumn) * 100000000)
- elif volumnUnit == 1:
- _volumn = round(float(volumn) * 10000)
- elif volumnUnit == 2:
- _volumn = int(volumn)
- if _volumn is not None:
- set_today_volumn(code, _volumn * 100)
-
-
-# 灏嗛噺浠庢暟鎹簱鍔犲叆鍐呭瓨
-def load():
- redis = __redis_manager.getRedis()
- keys = redis.keys("volumn_max60-*")
- if keys is not None:
- for k in keys:
- code = k.split("-")[1]
- max60_volumn = redis.get(k)
- if max60_volumn:
- max60_volumn = json.loads(max60_volumn)
- global_util.max60_volumn[code] = max60_volumn
- keys = redis.keys("volumn_yes-*")
- if keys is not None:
- for k in keys:
- code = k.split("-")[1]
- global_util.yesterday_volumn[code] = redis.get(k)
+ num = max60[0]
+ limit_up_price = gpcode_manager.get_limit_up_price(code)
+ if limit_up_price:
+ money_y = round((num * float(limit_up_price)) / 1e8, 1)
+ self.__reference_volume_as_money_y_dict[code] = money_y
+ return money_y
+ # 榛樿涓�5浜�
+ return 5
if __name__ == "__main__":
- print(get_volume_rate("000059"))
\ No newline at end of file
+ print(CodeVolumeManager().get_volume_rate("000059"))
--
Gitblit v1.8.0