From 6e71fbcb119e7068ba35380edaa5cc66e7c71f1b Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 27 十月 2022 16:21:05 +0800
Subject: [PATCH] 交易体系完善

---
 juejin.py |   57 ++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/juejin.py b/juejin.py
index 20379aa..8322d89 100644
--- a/juejin.py
+++ b/juejin.py
@@ -13,12 +13,15 @@
 import gm.api as gmapi
 
 import big_money_num_manager
+import client_manager
 import code_volumn_manager
-import data_process
+import constant
+import global_data_loader
 import global_util
 import gpcode_manager
 import threading
 
+import l2_trade_util
 import server
 import tool
 
@@ -28,12 +31,14 @@
 
 import trade_gui
 from l2_code_operate import L2CodeOperate
-from l2_data_manager import L2LimitUpMoneyStatisticUtil
+from l2_data_manager import L2LimitUpMoneyStatisticUtil, L2DataUtil
 from log import logger_juejin_tick, logger_system
+from trade_data_manager import CodeActualPriceProcessor
 from trade_queue_manager import JueJinBuy1VolumnManager
 
-redisManager = redis_manager.RedisManager()
+redisManager = redis_manager.RedisManager(0)
 __jueJinBuy1VolumnManager = JueJinBuy1VolumnManager()
+__actualPriceProcessor = CodeActualPriceProcessor()
 
 
 # 璁剧疆璐︽埛淇℃伅
@@ -54,11 +59,11 @@
 
 def init_data():
     # 杞藉叆琛屼笟鑲$エ浠g爜
-    global_util.load_industry()
+    global_data_loader.load_industry()
     # 杞藉叆浠g爜鑷敱娴侀�氬競鍊�
-    global_util.load_zyltgb()
+    global_data_loader.load_zyltgb()
     # 杞藉叆閲�
-    global_util.load_volumn()
+    global_data_loader.load_volumn()
 
 
 # 姣忔棩鍒濆鍖�
@@ -67,7 +72,7 @@
     logger_system.info("姣忔棩鍒濆鍖�")
 
     # 浠婃棩瀹炴椂娑ㄥ仠
-    global_util.add_limit_up_codes([], True)
+    global_data_loader.add_limit_up_codes([], True)
     # 涓昏鑾峰彇鏀剁洏浠�
     get_latest_info(None)
     # 鑾峰彇60澶╂渶澶ч噺涓庢槰鏃ラ噺
@@ -87,7 +92,7 @@
     global_util.limit_up_time.clear()
     init_data()
     # 鍒濆鍖栧悓鑺遍『涓荤珯
-    l2_clients = data_process.getValidL2Clients()
+    l2_clients = client_manager.getValidL2Clients()
     for client in l2_clients:
         server.repair_ths_main_site(client)
 
@@ -187,7 +192,7 @@
     start2 = 60 * 60 * 12 + 50 * 60
     end2 = 60 * 60 * 15 + 5 * 60
     # TODO 娴嬭瘯
-    if (start1 < relative_timestamp < end1 or start2 < relative_timestamp < end2) or global_util.TEST:
+    if (start1 < relative_timestamp < end1 or start2 < relative_timestamp < end2) or constant.TEST:
         symbol = tick['symbol']
         price = tick['price']
         # print(symbol,price)
@@ -197,11 +202,12 @@
 
         # 淇濆瓨鏈�鏂颁环
         symbol = symbol.split(".")[1]
+        JueJinManager.add_listen_code(symbol)
         time_ = tick["created_at"].strftime("%H:%M:%S")
-        data_=(symbol,time_,tick["quotes"][0]["bid_v"], tick["quotes"][0]["bid_p"])
+        data_ = (symbol, time_, tick["quotes"][0]["bid_v"], tick["quotes"][0]["bid_p"])
         logger_juejin_tick.info("涔�1閲� {},{},{},{}", data_[1], data_[0], data_[2],
                                 data_[3])
-        need_sync = __jueJinBuy1VolumnManager.save(data_[0], data_[1], data_[2],data_[3])
+        need_sync = __jueJinBuy1VolumnManager.save(data_[0], data_[1], data_[2], data_[3])
         if need_sync:
             # 鍚屾鏁版嵁
             L2LimitUpMoneyStatisticUtil.verify_num(data_[0], data_[2], data_[1])
@@ -259,6 +265,16 @@
                 else:
                     # 鏆傚瓨娑ㄥ箙涓鸿礋鐨勪唬鐮�
                     _delete_list.append((rate, code))
+                try:
+                    __actualPriceProcessor.process_rate(code, rate, now_str)
+                except Exception as e:
+                    logging.exception(e)
+
+                try:
+                    __actualPriceProcessor.save_current_price(code, price, gpcode_manager.get_limit_up_price_by_preprice(pricePre) == tool.to_price(decimal.Decimal(d["price"])))
+                except Exception as e:
+                    logging.exception(e)
+
         # 鎺掑簭
         new_code_list = sorted(_code_list, key=lambda e: e.__getitem__(0), reverse=True)
         # 棰勫~鍏呬笅鍗曚唬鐮�
@@ -273,7 +289,7 @@
             logging.exception(e)
             pass
 
-        client_ids = data_process.getValidL2Clients()
+        client_ids = client_manager.getValidL2Clients()
         # 鏈�澶氬~鍏呯殑浠g爜鏁伴噺
         max_count = len(client_ids) * 8
         if max_count == 0:
@@ -300,7 +316,11 @@
         # 澧炲姞搴旇澧炲姞鐨勪唬鐮�
         for code in add_code_list:
             if not gpcode_manager.is_listen(code):
-                L2CodeOperate.get_instance().add_operate(1, code, "鐜颁环鍙樺寲")
+                if not l2_trade_util.is_in_forbidden_trade_codes(code):
+                    L2CodeOperate.get_instance().add_operate(1, code, "鐜颁环鍙樺寲")
+            else:
+                if l2_trade_util.is_in_forbidden_trade_codes(code):
+                    L2CodeOperate.get_instance().add_operate(0, code, "鐜颁环鍙樺寲")
 
         print(add_code_list, del_list)
 
@@ -382,6 +402,17 @@
     def stop(self):
         gmapi.stop()
 
+    @classmethod
+    def add_listen_code(cls, code):
+        redis = redisManager.getRedis()
+        redis.setex("juejin_listen_code-{}".format(code), 20, "1")
+
+    @classmethod
+    def get_listen_codes_lenth(cls):
+        redis = redisManager.getRedis()
+        keys = redis.keys("juejin_listen_code-*")
+        return len(keys)
+
 
 def trade(code, volume):
     account_id, s_id, token = getAccountInfo()

--
Gitblit v1.8.0