Administrator
2024-02-05 8c7f84cbd0afde7600b0c67a8032fa19c57d8c41
code_attribute/code_volumn_manager.py
@@ -7,22 +7,26 @@
# yesterday 昨天的量
import json
from db.redis_manager import RedisUtils
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 db import redis_manager_delegate as redis_manager
from log_module.log import logger_day_volumn
__db = 0
__redis_manager = redis_manager.RedisManager(0)
# 设置历史量
def set_histry_volumn(code, max60, yesterday, max60_day=''):
def set_histry_volumn(code, max60, yesterday, max60_day, max60_day_count):
    redis = __redis_manager.getRedis()
    global_util.max60_volumn[code] = (max60, max60_day)
    global_util.max60_volumn[code] = (max60, max60_day,max60_day_count)
    global_util.yesterday_volumn[code] = yesterday
    try:
        RedisUtils.setex(redis, "volumn_max60-{}".format(code), tool.get_expire(), json.dumps((max60, max60_day)), auto_free=False)
        RedisUtils.setex(redis, "volumn_yes-{}".format(code), tool.get_expire(), yesterday, auto_free=False)
        RedisUtils.setex_async(0, "volumn_max60-{}".format(code), tool.get_expire(),
                               json.dumps((max60, max60_day, max60_day_count)),
                               auto_free=False)
        RedisUtils.setex_async(0, "volumn_yes-{}".format(code), tool.get_expire(), yesterday, auto_free=False)
    finally:
        RedisUtils.realse(redis)
@@ -51,13 +55,26 @@
# 设置今日量
def set_today_volumn(code, volumn):
    logger_day_volumn.info("code:{} volumn:{}".format(code, volumn))
    async_log_util.info(logger_day_volumn, "code:{} volumn:{}".format(code, volumn))
    global_util.today_volumn[code] = volumn
    # 有1000手的变化才保存
    if code in __today_volumn_cache and volumn - __today_volumn_cache[code] < 100000:
        return
    __today_volumn_cache[code] = volumn
    RedisUtils.setex( __redis_manager.getRedis(), "volumn_today-{}".format(code), tool.get_expire(), volumn)
    RedisUtils.setex(__redis_manager.getRedis(), "volumn_today-{}".format(code), tool.get_expire(), volumn)
# datas:[(code, volumn)]
def set_today_volumns(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 __today_volumn_cache and volumn - __today_volumn_cache[code] < 100000:
            continue
        __today_volumn_cache[code] = volumn
        RedisUtils.setex_async(__db, "volumn_today-{}".format(code), tool.get_expire(), volumn)
# 获取今日量
@@ -69,17 +86,30 @@
# 获取量比(今日量/max(60天最大量,昨日量))
def get_volume_rate(code, with_info=False):
# 将总卖量计算在内
def get_volume_rate(code, total_sell_volume=0, 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)
    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(code):
    max60, yesterday = 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(volume_rate):
    rates = [0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6]