From 8ddc7f5ecc67c0bb424954a86b75ec7444080ba2 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期三, 29 三月 2023 18:02:50 +0800
Subject: [PATCH] 首板买入策略分值优化

---
 l2/l2_data_manager_new.py |   50 +++++++++++++++++++++++++++++++-------------------
 1 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index c938ed2..25164f1 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -23,7 +23,8 @@
 from l2.l2_data_manager import L2DataException, TradePointManager
 from l2.l2_data_util import local_today_datas, L2DataUtil, load_l2_data, local_today_num_operate_map, local_latest_datas
 import l2.l2_data_util
-from log import logger_l2_trade, logger_l2_trade_cancel, logger_l2_trade_buy, logger_l2_process, logger_l2_error,logger_buy_score
+from log import logger_l2_trade, logger_l2_trade_cancel, logger_l2_trade_buy, logger_l2_process, logger_l2_error, \
+    logger_buy_score
 
 # TODO l2鏁版嵁绠$悊
 from trade.trade_data_manager import CodeActualPriceProcessor
@@ -161,6 +162,7 @@
     __thsBuy1VolumnManager = trade_queue_manager.THSBuy1VolumnManager()
     __buyL2SafeCountManager = safe_count_manager.BuyL2SafeCountManager()
     __l2PlaceOrderParamsManagerDict = {}
+    __last_buy_single_dict = {}
 
     @classmethod
     # 鏁版嵁澶勭悊鍏ュ彛
@@ -235,7 +237,7 @@
             limit_up_time = limit_up_time_manager.get_limit_up_time(code)
             if limit_up_time is None:
                 limit_up_time = tool.get_now_time_str()
-            score = first_code_score_manager.get_score(code, volume_rate, limit_up_time,True)
+            score = first_code_score_manager.get_score(code, volume_rate, limit_up_time, True)
             cls.__l2PlaceOrderParamsManagerDict[code] = l2_trade_factor.L2PlaceOrderParamsManager(code, is_first_code,
                                                                                                   volume_rate,
                                                                                                   volume_rate_index,
@@ -449,7 +451,7 @@
     @classmethod
     def __buy(cls, code, capture_timestamp, last_data, last_data_index, is_first_code):
         __start_time = tool.get_now_timestamp()
-        can, need_clear_data, reason = False,False,""
+        can, need_clear_data, reason = False, False, ""
         if not is_first_code:
             can, need_clear_data, reason = cls.__can_buy(code)
         else:
@@ -522,16 +524,18 @@
     @classmethod
     def __can_buy(cls, code):
         __start_time = t.time()
-            # 涔嬪墠鐨勪唬鐮�
-            # 棣栨澘浠g爜涓斿皻鏈定鍋滆繃鐨勪笉鑳戒笅鍗�
-            # is_limited_up = gpcode_manager.FirstCodeManager.is_limited_up(code)
-            # if not is_limited_up:
-            #     gpcode_manager.FirstCodeManager.add_limited_up_record([code])
-            #     place_order_count = trade_data_manager.placeordercountmanager.get_place_order_count(
-            #         code)
-            #     if place_order_count == 0:
-            #         trade_data_manager.placeordercountmanager.place_order(code)
-            #     return False, True, "棣栨澘浠g爜锛屼笖灏氭湭娑ㄥ仠杩�"
+        if not trade_manager.TradeStateManager.is_can_buy():
+            return False, True, f"浠婃棩宸茬姝氦鏄�"
+        # 涔嬪墠鐨勪唬鐮�
+        # 棣栨澘浠g爜涓斿皻鏈定鍋滆繃鐨勪笉鑳戒笅鍗�
+        # is_limited_up = gpcode_manager.FirstCodeManager.is_limited_up(code)
+        # if not is_limited_up:
+        #     gpcode_manager.FirstCodeManager.add_limited_up_record([code])
+        #     place_order_count = trade_data_manager.placeordercountmanager.get_place_order_count(
+        #         code)
+        #     if place_order_count == 0:
+        #         trade_data_manager.placeordercountmanager.place_order(code)
+        #     return False, True, "棣栨澘浠g爜锛屼笖灏氭湭娑ㄥ仠杩�"
 
         try:
             # 涔�1浠锋牸蹇呴』涓烘定鍋滀环鎵嶈兘涔�
@@ -575,12 +579,11 @@
             if volumn_rate >= 1.3:
                 return False, False, "鏈�澶ч噺姣旇秴杩�1.3涓嶈兘涔�"
 
-
             limit_up_time = limit_up_time_manager.get_limit_up_time(code)
             if limit_up_time is not None:
                 limit_up_time_seconds = l2.l2_data_util.L2DataUtil.get_time_as_second(
                     limit_up_time)
-                if  limit_up_time_seconds >= l2.l2_data_util.L2DataUtil.get_time_as_second(
+                if limit_up_time_seconds >= l2.l2_data_util.L2DataUtil.get_time_as_second(
                         "13:00:00"):
                     return False, False, "浜屾澘涓嬪崍娑ㄥ仠鐨勪笉鑳戒拱锛屾定鍋滄椂闂翠负{}".format(limit_up_time)
                 if limit_up_time_seconds >= l2.l2_data_util.L2DataUtil.get_time_as_second("14:55:00"):
@@ -648,6 +651,8 @@
 
     @classmethod
     def __can_buy_first(cls, code):
+        if not trade_manager.TradeStateManager.is_can_buy():
+            return False, True, f"浠婃棩宸茬姝氦鏄�"
 
         if not gpcode_manager.WantBuyCodesManager.is_in(code):
             # 鏌ョ湅鍒嗘暟绛夌骇
@@ -655,8 +660,8 @@
             score = cls.__l2PlaceOrderParamsManagerDict[code].score
             if score_index < 0:
                 return False, True, f"鍒嗗�硷細{score}鏈揪鍒伴渶瑕佷拱鍏ョ殑鍒嗘暟绾�"
-            # if -1 < score_index < 3:
-            #     return True, False, f"鍒嗗�硷細{score}杈惧埌涓诲姩涔板叆鐨勫垎鏁扮嚎锛屼拱鍏ョ瓑绾э細f{score_index}"
+            # if -1 < score_index < 3 and (0.499 <= cls.volume_rate_info[code][0] <= 0.949):
+            #     return True, False, f"鍒嗗�硷細{score}杈惧埌涓诲姩涔板叆鐨勫垎鏁扮嚎涓旈噺瓒冲锛屼拱鍏ョ瓑绾э細f{score_index},閲忔瘮锛歿cls.volume_rate_info[code][0]}"
             is_limited_up = gpcode_manager.FirstCodeManager.is_limited_up(code)
             gpcode_manager.FirstCodeManager.add_limited_up_record([code])
             if not code_price_manager.Buy1PriceManager.is_can_buy(code):
@@ -739,8 +744,14 @@
             has_single, _index = cls.__compute_order_begin_pos(code, max(
                 (compute_start_index - continue_count - 1) if new_add else compute_start_index, 0), continue_count,
                                                                compute_end_index)
+            # 濡傛灉涔板叆淇″彿涓庝笂娆$殑涔板叆淇″彿涓�鏍峰氨涓嶈兘绠楁柊鐨勪俊鍙�
+            if cls.__last_buy_single_dict.get(code) == _index:
+                has_single = None
+                _index = None
+
             buy_single_index = _index
             if has_single:
+                cls.__last_buy_single_dict[code] = buy_single_index
                 new_get_single = True
                 num = 0
                 count = 0
@@ -791,8 +802,9 @@
             return
 
         if compute_index is not None:
-            l2_log.debug(code, "鑾峰彇鍒颁拱鍏ユ墽琛屼綅缃細{} m鍊硷細{} 绾拱鎵嬫暟锛歿} 绾拱鍗曟暟锛歿} 鏁版嵁锛歿} ,閲忔瘮:{} ", compute_index, threshold_money, buy_nums,
-                         buy_count, total_datas[compute_index],cls.volume_rate_info[code][0])
+            l2_log.debug(code, "鑾峰彇鍒颁拱鍏ユ墽琛屼綅缃細{} m鍊硷細{} 绾拱鎵嬫暟锛歿} 绾拱鍗曟暟锛歿} 鏁版嵁锛歿} ,閲忔瘮:{} ", compute_index, threshold_money,
+                         buy_nums,
+                         buy_count, total_datas[compute_index], cls.volume_rate_info[code][0])
 
             f1 = dask.delayed(cls.__save_order_begin_data)(code, buy_single_index, compute_index, compute_index,
                                                            buy_nums, buy_count, max_num_set_new,

--
Gitblit v1.8.0