From 8c7f84cbd0afde7600b0c67a8032fa19c57d8c41 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 05 二月 2024 11:18:33 +0800 Subject: [PATCH] L撤快速成交触发撤单修改 --- code_attribute/code_volumn_manager.py | 113 ++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 80 insertions(+), 33 deletions(-) diff --git a/code_attribute/code_volumn_manager.py b/code_attribute/code_volumn_manager.py index 247ac10..45d9510 100644 --- a/code_attribute/code_volumn_manager.py +++ b/code_attribute/code_volumn_manager.py @@ -7,20 +7,28 @@ # yesterday 鏄ㄥぉ鐨勯噺 import json +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 - redis.setex("volumn_max60-{}".format(code), tool.get_expire(), json.dumps((max60, max60_day))) - redis.setex("volumn_yes-{}".format(code), tool.get_expire(), yesterday) + try: + 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) # 鑾峰彇鍘嗗彶閲� @@ -28,42 +36,78 @@ 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)) - if max60: - max60 = json.loads(max60) - if yesterday is None: - yesterday = redis.get("volumn_yes-{}".format(code)) - return max60, yesterday + 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) + +__today_volumn_cache = {} + + +# 閲忕殑鍙樺寲澶т繚瀛� # 璁剧疆浠婃棩閲� def set_today_volumn(code, volumn): - logger_day_volumn.info("code:{} volumn:{}".format(code, volumn)) - redis = __redis_manager.getRedis() + async_log_util.info(logger_day_volumn, "code:{} volumn:{}".format(code, volumn)) global_util.today_volumn[code] = volumn - redis.setex("volumn_today-{}".format(code), tool.get_expire(), 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) + + +# 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) # 鑾峰彇浠婃棩閲� 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)) + _volumn = RedisUtils.get(__redis_manager.getRedis(), "volumn_today-{}".format(code)) return _volumn # 鑾峰彇閲忔瘮锛堜粖鏃ラ噺/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 # 鑾峰彇閲忔瘮绱㈠紩 @@ -91,20 +135,23 @@ # 灏嗛噺浠庢暟鎹簱鍔犲叆鍐呭瓨 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) + 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) + finally: + RedisUtils.realse(redis) if __name__ == "__main__": - print(get_volume_rate("000059")) \ No newline at end of file + print(get_volume_rate("000059")) -- Gitblit v1.8.0