From 20a70116b236a49d68659b451fea0a9f645a0835 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期一, 07 八月 2023 10:39:34 +0800
Subject: [PATCH] redis批量提交数据

---
 trade/trade_data_manager.py |   43 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/trade/trade_data_manager.py b/trade/trade_data_manager.py
index 9ab4daa..96c62c1 100644
--- a/trade/trade_data_manager.py
+++ b/trade/trade_data_manager.py
@@ -67,7 +67,7 @@
     # 鑾峰彇涔板叆鐐逛俊鎭�
     @classmethod
     def get_buy_position_info(cls, code):
-        val_str = RedisUtils.get( cls.redisManager.getRedis(), "buy_position_info-{}".format(code))
+        val_str = RedisUtils.get(cls.redisManager.getRedis(), "buy_position_info-{}".format(code))
         if val_str is None:
             return None, None, None, None
         else:
@@ -77,7 +77,7 @@
     # 鍒犻櫎涔板叆鐐逛俊鎭�
     @classmethod
     def remove_buy_position_info(cls, code):
-        RedisUtils.delete( cls.redisManager.getRedis(), "buy_position_info-{}".format(code))
+        RedisUtils.delete(cls.redisManager.getRedis(), "buy_position_info-{}".format(code))
 
     # 璁剧疆涔板叆纭鐐逛俊鎭�
     @classmethod
@@ -236,6 +236,19 @@
         key = "code_current_rate-{}".format(code)
         RedisUtils.setex(self.__get_redis(), key, tool.get_expire(), rate)
 
+    # 鎵归噺淇濆瓨
+    def __save_current_rates(self, datas):
+        # 鍙樺寲涔嬪悗鎵嶄細鎸佷箙鍖�
+        pipe = self.__get_redis().pipeline()
+        for d in datas:
+            if self.__code_current_rate_latest.get(d[0]) == d[1]:
+                continue
+            self.__code_current_rate_latest[d[0]] = d[1]
+            tool.CodeDataCacheUtil.set_cache(self.__code_current_rate_cache, d[0], d[1])
+            key = "code_current_rate-{}".format(d[0])
+            RedisUtils.setex(pipe, key, tool.get_expire(), d[1])
+        pipe.execute()
+
     # 鑾峰彇褰撳墠娑ㄥ箙
     def __get_current_rate(self, code):
         key = "code_current_rate-{}".format(code)
@@ -274,6 +287,32 @@
             if self.__get_last_down_price_time_cache(code) is None:
                 self.__save_down_price_time(code, time_str)
 
+    # datas:[(浠g爜,姣斾緥)]
+    def process_rates(self, datas, time_str):
+        # 9鐐瑰崐涔嬪墠鐨勬暟鎹笉澶勭悊
+        if int(time_str.replace(":", "")) < int("093000"):
+            return
+        # 淇濆瓨鐩墠鐨勪唬鐮佹定骞�
+        self.__save_current_rates(datas)
+
+        # now_str = tool.get_now_time_str()
+        for d in datas:
+            code, rate = d[0], d[1]
+            if rate >= 0:
+                down_start_time = self.__get_last_down_price_time_cache(code)
+                if down_start_time is None:
+                    continue
+                else:
+                    # 绱澧炲姞鏃堕棿
+                    time_second = tool.trade_time_sub(time_str, down_start_time)
+                    self.__increment_down_price_time(code, time_second)
+                    # 鍒犻櫎璧峰鏃堕棿
+                    self.__remove_down_price_time(code)
+            else:
+                # 璁板綍寮�濮嬪��
+                if self.__get_last_down_price_time_cache(code) is None:
+                    self.__save_down_price_time(code, time_str)
+
     # 淇濆瓨鐜颁环
     def save_current_price(self, code, price, is_limit_up):
         global_util.cuurent_prices[code] = (price, is_limit_up, round(time.time()))

--
Gitblit v1.8.0