From 6f324f1471a5e28188e9f4206b46cbafdf09d04c Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期一, 16 一月 2023 17:58:31 +0800
Subject: [PATCH] 增加图像识别接口,禁止下单策略优化

---
 l2_data_manager_new.py |   88 ++++++++++++++++++++------------------------
 1 files changed, 40 insertions(+), 48 deletions(-)

diff --git a/l2_data_manager_new.py b/l2_data_manager_new.py
index 279b9c5..8a55c4f 100644
--- a/l2_data_manager_new.py
+++ b/l2_data_manager_new.py
@@ -211,7 +211,7 @@
     @classmethod
     def process_add_datas(cls, code, add_datas, capture_timestamp, __start_time):
         if len(add_datas) > 0:
-            now_time_str = datetime.datetime.now().strftime("%H:%M:%S")
+            now_time_str = tool.get_now_time_str()
             # 鎷兼帴鏁版嵁
             local_today_datas[code].extend(add_datas)
             l2_data_util.load_num_operate_map(l2_data_manager.local_today_num_operate_map, code, add_datas)
@@ -301,7 +301,7 @@
         if end_index < start_index:
             return
         # 鑾峰彇涔板叆淇″彿璧峰鐐�
-        buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos(
+        buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set = cls.__get_order_begin_pos(
             code)
 
         # 鎾ゅ崟璁$畻,鍙湅涔�1
@@ -390,7 +390,7 @@
                 trade_data_manager.placeordercountmanager.place_order(code)
                 # 鑾峰彇涔板叆浣嶇疆淇℃伅
                 try:
-                    buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos(
+                    buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set = cls.__get_order_begin_pos(
                         code)
                     SecondAverageBigNumComputer.place_order_success(code, buy_single_index, buy_exec_index)
                     AverageBigNumComputer.place_order_success(code, buy_single_index, buy_exec_index)
@@ -450,13 +450,14 @@
         # if abs(float(buy1_price) - float(limit_up_price)) >= 0.01:
         #     return False, "涔�1浠蜂笉涓烘定鍋滀环锛屼拱1浠�-{} 娑ㄥ仠浠�-{}".format(buy1_price, limit_up_price)
         # 浠庝拱鍏ヤ俊鍙疯捣濮嬬偣鍒板綋鍓嶆暟鎹湯灏剧殑绾拱鎵嬫暟涓庡綋鍓嶇殑鍗�1鍋氭瘮杈冿紝濡傛灉姣斿崠1灏忓垯涓嶈兘涔板叆
+        total_datas = local_today_datas[code]
         try:
             sell1_time, sell1_price, sell1_volumn = cls.__ths_l2_trade_queue_manager.get_sell1_info(code)
             cls.buy_debug(code, "鍗�1淇℃伅涓猴細({},{},{})", sell1_time, sell1_price, sell1_volumn)
             if sell1_time is not None and sell1_volumn > 0:
                 # 鑾峰彇鎵ц浣嶄俊鎭�
-                total_datas = local_today_datas[code]
-                buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos(
+
+                buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set = cls.__get_order_begin_pos(
                     code)
                 buy_nums = num
                 for i in range(buy_exec_index + 1, total_datas[-1]["index"] + 1):
@@ -491,23 +492,25 @@
         codes_index = industry_codes_sort.sort_codes(codes, code)
         if codes_index is not None and codes_index.get(code) is not None and codes_index.get(code) > 1:
             # 褰撹�佸ぇ鑰佷簩褰撳墠娌℃定鍋�
-
             return False, "鍚屼竴鏉垮潡涓�佷笁,鑰佸洓,...涓嶈兘涔�"
 
-        if cls.__codeActualPriceProcessor.is_under_water(code):
+        if cls.__codeActualPriceProcessor.is_under_water(code,total_datas[-1]["val"]["time"]):
             # 姘翠笅鎹炰笖鏉垮潡涓殑绁ㄥ皬浜�16涓嶈兘涔�
-            if global_util.industry_hot_num.get(industry) is not None and global_util.industry_hot_num.get(
-                    industry) <= 16:
-                return False, "姘翠笅鎹�,鏉垮潡涓殑绁ㄥ皬浜�2鍙�,涓簕}".format(global_util.industry_hot_num.get(industry))
-
+            # if global_util.industry_hot_num.get(industry) is not None and global_util.industry_hot_num.get(
+            #         industry) <= 16:
+            #     return False, "姘翠笅鎹�,鏉垮潡涓殑绁ㄥ皬浜�2鍙�,涓簕}".format(global_util.industry_hot_num.get(industry))
+            # 姘翠笅鎹炶嚜鐢辨祦閫氬競鍊煎ぇ浜庤�佸ぇ鐨勪笉瑕佷拱
             if codes_index.get(code) != 0:
-                return False, "姘翠笅鎹�,涓嶆槸鑰佸ぇ锛屾槸鑰亄}".format(codes_index.get(code))
+                # 鑾峰彇鑰佸ぇ鐨勫競鍊�
+                for c in codes_index:
+                    if codes_index.get(c) == 0 and global_util.zyltgb_map.get(code) > global_util.zyltgb_map.get(c):
+                        return False, "姘翠笅鎹烇紝涓嶆槸鑰佸ぇ锛屼笖鑷敱娴侀�氬競鍊煎ぇ浜庤�佸ぇ"
 
         # 13:30鍚庢定鍋滐紝鏈澘鍧椾腑娑ㄥ仠绁ㄦ暟<29涓嶈兘涔�
-        if limit_up_time is not None:
-            if int(limit_up_time.replace(":", "")) >= 133000 and global_util.industry_hot_num.get(industry) is not None:
-                if global_util.industry_hot_num.get(industry) < 16:
-                    return False, "13:30鍚庢定鍋滐紝鏈澘鍧椾腑娑ㄥ仠绁ㄦ暟<16涓嶈兘涔�"
+        # if limit_up_time is not None:
+        #     if int(limit_up_time.replace(":", "")) >= 133000 and global_util.industry_hot_num.get(industry) is not None:
+        #         if global_util.industry_hot_num.get(industry) < 16:
+        #             return False, "13:30鍚庢定鍋滐紝鏈澘鍧椾腑娑ㄥ仠绁ㄦ暟<16涓嶈兘涔�"
 
         if codes_index.get(code) is not None and codes_index.get(code) == 1:
             # 濡傛灉鑰佸ぇ宸茬粡涔版垚鍔熶簡, 鑰佷簩灏变笉闇�瑕佷拱浜�
@@ -561,11 +564,11 @@
         # 鏄惁鏄氦鏄撻槦鍒楄Е鍙�
         if source == "trade_queue":
             # 浜ゆ槗闃熷垪瑙﹀彂鐨勯渶瑕佷笅鍗曞悗5s
-            buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos(
+            buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set = cls.__get_order_begin_pos(
                 code)
             total_datas = local_today_datas[code]
             if buy_exec_index is not None and buy_exec_index > 0:
-                now_time_str = datetime.datetime.now().strftime("%H:%M:%S")
+                now_time_str = tool.get_now_time_str()
                 if tool.trade_time_sub(now_time_str, total_datas[buy_exec_index]["val"]["time"]) < 5:
                     return False
 
@@ -607,7 +610,7 @@
         _start_time = round(t.time() * 1000)
         total_datas = local_today_datas[code]
         # 鑾峰彇涔板叆淇″彿璁$畻璧峰浣嶇疆
-        buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos(
+        buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set = cls.__get_order_begin_pos(
             code)
 
         # 鏄惁涓烘柊鑾峰彇鍒扮殑浣嶇疆
@@ -643,16 +646,7 @@
 
         threshold_money, msg = cls.__get_threshmoney(code)
         # 涔板叆绾拱棰濈粺璁�
-        compute_index, buy_nums, buy_count, rebegin_buy_pos, max_num_index_new = cls.__sum_buy_num_for_order_3(code,
-                                                                                                               max(
-                                                                                                                   buy_single_index,
-                                                                                                                   compute_start_index),
-                                                                                                               compute_end_index,
-                                                                                                               num,
-                                                                                                               count,
-                                                                                                               threshold_money,
-                                                                                                               buy_single_index,
-                                                                                                               max_num_index)
+        compute_index, buy_nums, buy_count, rebegin_buy_pos, max_num_set_new = cls.__sum_buy_num_for_order_3(code, max(buy_single_index,compute_start_index),compute_end_index,num,count,threshold_money,buy_single_index,max_num_set)
         _start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "绾拱棰濈粺璁℃椂闂�")
 
         cls.debug(code, "m鍊�-{} m鍊煎洜瀛�-{}", threshold_money, msg)
@@ -669,7 +663,7 @@
                       total_datas[compute_index])
             # 璁板綍涔板叆淇″彿浣嶇疆
             cls.__save_order_begin_data(code, buy_single_index, compute_index, compute_index, buy_nums, buy_count,
-                                        max_num_index_new)
+                                        max_num_set_new)
             # 濡傛灉鏄粖澶╃涓�娆℃湁涓嬪崟鎵ц淇″彿锛屾定鍋滄椂闂达紙涔板叆鎵ц浣嶆椂闂达級
             limit_up_time_manager.save_limit_up_time(code, total_datas[compute_index]["val"]["time"])
             # 铏氭嫙涓嬪崟
@@ -714,7 +708,7 @@
             # 鏈揪鍒颁笅鍗曟潯浠讹紝淇濆瓨绾拱棰濓紝璁剧疆绾拱棰�
             # 璁板綍涔板叆淇″彿浣嶇疆
             cls.__save_order_begin_data(code, buy_single_index, -1, compute_end_index, buy_nums, buy_count,
-                                        max_num_index_new)
+                                        max_num_set_new)
             print("淇濆瓨澶у崟鏃堕棿", round((t.time() - _start_time) * 1000))
             _start_time = t.time()
         pass
@@ -722,15 +716,15 @@
     # 鑾峰彇涓嬪崟璧峰淇″彿
     @classmethod
     def __get_order_begin_pos(cls, code):
-        buy_single_index, buy_exec_index, compute_index, num, count, max_num_index = l2_data_manager.TradePointManager.get_buy_compute_start_data(
+        buy_single_index, buy_exec_index, compute_index, num, count, max_num_set = l2_data_manager.TradePointManager.get_buy_compute_start_data(
             code)
-        return buy_single_index, buy_exec_index, compute_index, num, count, max_num_index
+        return buy_single_index, buy_exec_index, compute_index, num, count, max_num_set
 
     # 淇濆瓨涓嬪崟璧峰淇″彿
     @classmethod
-    def __save_order_begin_data(self, code, buy_single_index, buy_exec_index, compute_index, num, count, max_num_index):
+    def __save_order_begin_data(self, code, buy_single_index, buy_exec_index, compute_index, num, count, max_num_set):
         TradePointManager.set_buy_compute_start_data(code, buy_single_index, buy_exec_index, compute_index, num, count,
-                                                     max_num_index)
+                                                     max_num_set)
 
     # 璁$畻涓嬪崟璧峰淇″彿
     # compute_data_count 鐢ㄤ簬璁$畻鐨刲2鏁版嵁鏁伴噺
@@ -803,7 +797,7 @@
     # 缁熻涔板叆鍑�涔伴噺锛屼笉璁$畻鍦ㄤ拱鍏ヤ俊鍙蜂箣鍓嶇殑涔版挙鍗�
     @classmethod
     def __sum_buy_num_for_order_3(cls, code, compute_start_index, compute_end_index, origin_num, origin_count,
-                                  threshold_money, buy_single_index, max_num_index):
+                                  threshold_money, buy_single_index, max_num_set):
         def get_threshold_count():
             count = threshold_count - sub_threshold_count
             if count < 3:
@@ -856,9 +850,7 @@
         max_space_time = pow(3, place_order_count + 1) - 1
         # 鏈�澶т拱閲�
         max_buy_num = 0
-        max_buy_num_index = max_num_index
-        if max_num_index > -1:
-            max_buy_num = int(total_datas[max_num_index]["val"]["num"])
+        max_buy_num_set = set(max_num_set)
         for i in range(compute_start_index, compute_end_index + 1):
             data = total_datas[i]
             _val = total_datas[i]["val"]
@@ -868,20 +860,18 @@
                 TradePointManager.delete_buy_point(code)
                 if i == compute_end_index:
                     # 鏁版嵁澶勭悊瀹屾瘯
-                    return None, buy_nums, buy_count, None, max_buy_num_index
+                    return None, buy_nums, buy_count, None, max_buy_num_set
                 else:
                     # 璁$畻涔板叆淇″彿锛屼笉鑳藉悓涓�鏃堕棿寮�濮嬭绠�
                     for ii in range(buy_single_index + 1, compute_end_index + 1):
                         if total_datas[buy_single_index]["val"]["time"] != total_datas[ii]["val"]["time"]:
-                            return None, buy_nums, buy_count, ii, max_buy_num_index
+                            return None, buy_nums, buy_count, ii, max_buy_num_set
             # 娑ㄥ仠涔�
             if L2DataUtil.is_limit_up_price_buy(_val):
                 if cls.__is_big_money(limit_up_price, _val):
                     sub_threshold_count += int(total_datas[i]["re"])
+                    max_buy_num_set.add(i)
                 if round(int(_val["num"]) * float(_val["price"])) >= 5900:
-                    if int(_val["num"]) > max_buy_num:
-                        max_buy_num = int(_val["num"])
-                        max_buy_num_index = i
                     trigger_buy = True
                     # 鍙粺璁�59涓囦互涓婄殑閲戦
                     buy_nums += int(_val["num"]) * int(total_datas[i]["re"])
@@ -922,16 +912,15 @@
             cls.buy_debug(code, "浣嶇疆-{}锛屾�绘墜鏁帮細{}锛岀洰鏍囨墜鏁帮細{}", i,
                           buy_nums, threshold_num)
             # 鏈夋挙鍗曚俊鍙凤紝涓斿皬浜庨槇鍊�
-            if buy_nums >= threshold_num and buy_count >= get_threshold_count() and trigger_buy and max_buy_num_index > -1 and cls.__is_big_money(
-                    limit_up_price, total_datas[max_buy_num_index]["val"]):
-                return i, buy_nums, buy_count, None, max_buy_num_index
+            if buy_nums >= threshold_num and buy_count >= get_threshold_count() and trigger_buy and len(max_buy_num_set)>1:
+                return i, buy_nums, buy_count, None, max_buy_num_set
 
         cls.buy_debug(code, "灏氭湭鑾峰彇鍒颁拱鍏ユ墽琛岀偣锛岃捣濮嬭绠椾綅缃細{} 缁熻绾拱鎵嬫暟锛歿} 鐩爣绾拱鎵嬫暟锛歿}  缁熻绾拱鍗曟暟锛歿} 鐩爣绾拱鍗曟暟锛歿} 澶у崟鏁伴噺锛歿}",
                       compute_start_index,
                       buy_nums,
                       threshold_num, buy_count, get_threshold_count(), sub_threshold_count)
 
-        return None, buy_nums, buy_count, None, max_buy_num_index
+        return None, buy_nums, buy_count, None, max_buy_num_set
 
     @classmethod
     def test(cls):
@@ -2078,6 +2067,9 @@
         total_data = local_today_datas[code]
         latest_index = total_data[-1]["index"]
         end_index = total_data[-1]["index"]
+        if end_index >= 434:
+            print("娴嬭瘯")
+
         start_index = buy_exec_index
         if tool.trade_time_sub(total_data[end_index]["val"]["time"], total_data[buy_exec_index]["val"]["time"]) < 3:
             return

--
Gitblit v1.8.0