| | |
| | | # 设置历史量 |
| | | # max60 60天最大量 |
| | | # yesterday 昨天的量 |
| | | import json |
| | | |
| | | import global_util |
| | | import gpcode_manager |
| | | from db import redis_manager |
| | |
| | | |
| | | |
| | | # 设置历史量 |
| | | def set_histry_volumn(code, max60, yesterday): |
| | | def set_histry_volumn(code, max60, yesterday, max60_day=''): |
| | | redis = __redis_manager.getRedis() |
| | | global_util.max60_volumn[code] = max60 |
| | | global_util.yesterday_volumn[code] = yesterday |
| | | redis.setex("volumn_max60-{}".format(code), tool.get_expire(), max60) |
| | | redis.setex("volumn_max60-{}".format(code), tool.get_expire(), json.dumps((max60,max60_day))) |
| | | redis.setex("volumn_yes-{}".format(code), tool.get_expire(), yesterday) |
| | | |
| | | |
| | |
| | | redis = __redis_manager.getRedis() |
| | | if max60 is None: |
| | | max60 = redis.get("volumn_max60-{}".format(code)) |
| | | if max60: |
| | | max60 = json.loads(max60) |
| | | if yesterday is None: |
| | | yesterday = redis.get("volumn_yes-{}".format(code)) |
| | | return max60, yesterday |
| | |
| | | |
| | | |
| | | # 获取量比(今日量/max(60天最大量,昨日量)) |
| | | def get_volume_rate(code): |
| | | 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("获取量失败") |
| | | return round(int(today) / max(int(max60), int(yesterday)), 2) |
| | | 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))) |
| | | |
| | | |
| | | # 获取量比索引 |
| | |
| | | if keys is not None: |
| | | for k in keys: |
| | | code = k.split("-")[1] |
| | | global_util.max60_volumn[code] = redis.get(k) |
| | | 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: |
| | |
| | | global_util.yesterday_volumn[code] = redis.get(k) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | print(get_histry_volumn("603717")) |