From 7bfdbe969da0b3a132d805cd15e9e83e7f2a8f8a Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期日, 25 六月 2023 11:12:26 +0800
Subject: [PATCH] 将掘金接口抽象出单独的类

---
 trade/l2_trade_factor.py |  127 +++++++++++++++++++++++-------------------
 1 files changed, 70 insertions(+), 57 deletions(-)

diff --git a/trade/l2_trade_factor.py b/trade/l2_trade_factor.py
index 49200e4..e4d4933 100644
--- a/trade/l2_trade_factor.py
+++ b/trade/l2_trade_factor.py
@@ -22,15 +22,18 @@
     def get_buy_rank_desc(self):
         continue_count = self.get_begin_continue_buy_count()
         time_range = self.get_time_range()
+        m = self.get_m_val()[0]
+        m = m//10000
+
         desc = ""
         if self.buy_rank == 0:
             desc = f"涔板叆淇″彿({continue_count})"
         elif self.buy_rank == 1:
-            desc = f"涔板叆淇″彿({continue_count})+M鍊尖墺1000涓�"
+            desc = f"涔板叆淇″彿({continue_count})+M鍊尖墺{m}涓�"
         elif self.buy_rank == 2:
-            desc = f"涔板叆淇″彿({continue_count})+M鍊尖墺1000涓�+鑷冲皯鍚�1绗斿ぇ鍗�"
+            desc = f"涔板叆淇″彿({continue_count})+M鍊尖墺{m}涓�+鑷冲皯鍚�1绗斿ぇ鍗�"
         elif self.buy_rank == 3:
-            desc = f"涔板叆淇″彿({continue_count})+M鍊尖墺1000涓�+鑷冲皯鍚�2绗斿ぇ鍗�"
+            desc = f"涔板叆淇″彿({continue_count})+M鍊尖墺{m}涓�+鑷冲皯鍚�2绗斿ぇ鍗�"
         else:
             desc = "甯歌涔板叆"
         desc += f"+鍥婃嫭鏃堕棿{time_range}s"
@@ -43,37 +46,46 @@
     # 3:涔板叆淇″彿+M1000+2绗斿ぇ鍗�
     # 100:鎵ц涔嬪墠鍥烘湁鏂规
     def get_buy_rank(self):
-        # 鍒ゆ柇鏈夋病鏈夌偢寮�
-        if code_price_manager.Buy1PriceManager.is_can_buy(self.code):
-            # 鍥炲皝
-            if self.score_index == 0:
-                return 0
-            elif self.score_index == 1:
-                return 1
-            elif self.score_index == 2:
-                return 2
-            else:
-                return 100
+        if self.score_index == 0:
+            return 0
+        elif self.score_index == 1:
+            return 1
+        elif self.score_index == 2:
+            return 2
         else:
-            # 棣栧皝
-            if tool.trade_time_sub(self.now_time, "10:30:00") < 0 or tool.trade_time_sub(self.now_time, "14:00:00") > 0:
-                if self.score_index == 0:
-                    return 1
-                elif self.score_index == 1:
-                    return 2
-                elif self.score_index == 2:
-                    return 3
-                else:
-                    return 100
-            else:
-                if self.score_index == 0:
-                    return 2
-                elif self.score_index == 1:
-                    return 3
-                elif self.score_index == 2:
-                    return 100
-                else:
-                    return 100
+            return 100
+        # 鏆傛椂涓嶉渶瑕佹姝や腑绛栫暐
+        # # 鍒ゆ柇鏈夋病鏈夌偢寮�
+        # if code_price_manager.Buy1PriceManager.is_can_buy(self.code):
+        #     # 鍥炲皝
+        #     if self.score_index == 0:
+        #         return 0
+        #     elif self.score_index == 1:
+        #         return 1
+        #     elif self.score_index == 2:
+        #         return 2
+        #     else:
+        #         return 100
+        # else:
+        #     # 棣栧皝
+        #     if tool.trade_time_sub(self.now_time, "10:30:00") < 0 or tool.trade_time_sub(self.now_time, "14:00:00") > 0:
+        #         if self.score_index == 0:
+        #             return 1
+        #         elif self.score_index == 1:
+        #             return 2
+        #         elif self.score_index == 2:
+        #             return 3
+        #         else:
+        #             return 100
+        #     else:
+        #         if self.score_index == 0:
+        #             return 2
+        #         elif self.score_index == 1:
+        #             return 3
+        #         elif self.score_index == 2:
+        #             return 100
+        #         else:
+        #             return 100
 
     # 寰楀垎
     def __init__(self, code, is_first_code, volume_rate, volume_rate_index, score, now_time=tool.get_now_time_str()):
@@ -132,8 +144,9 @@
     def get_time_range(self):
         # ts = [pow(3, 1), pow(3, 1), pow(3, 1), pow(3, 2), pow(3, 2), pow(3, 3), pow(3, 3), pow(3, 3)]
         ts = [pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1)]
-        if -1 < self.score_index < 3:
-            return ts[0]
+        # 鏆傛椂鍘婚櫎鍒嗙殑褰卞搷
+        # if -1 < self.score_index < 3:
+        #     return ts[0]
         volume_rate_index = self.volume_rate_index
         if self.volume_rate_index >= len(ts):
             volume_rate_index = -1
@@ -141,14 +154,14 @@
 
     # 鑾峰彇闇�瑕佺殑澶у崟涓暟
     def get_big_num_count(self):
-        if self.is_first_code:
-            if self.buy_rank < 2:
-                return 0
-            elif self.buy_rank == 2:
-                return 1
-            elif self.buy_rank == 3:
-                return 2
-        counts = [3, 1, 1, 1, 0, 0, 0, 0]
+        # if self.is_first_code:
+        #     if self.buy_rank < 2:
+        #         return 0
+        #     elif self.buy_rank == 2:
+        #         return 1
+        #     elif self.buy_rank == 3:
+        #         return 2
+        counts = [2, 1, 1, 1, 0, 0, 0, 0]
         volume_rate_index = self.volume_rate_index
         if self.volume_rate_index >= len(counts):
             volume_rate_index = -1
@@ -156,16 +169,16 @@
 
     # 鑾峰彇瀹夊叏绗旀暟褰卞搷姣斾緥
     def get_safe_count_rate(self):
-        rates = [0, -0.1, -0.2, -0.4, -0.6, -0.8, -0.8, -0.8]
+        rates = [0, -0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7]
         volume_rate_index = self.volume_rate_index
         if self.volume_rate_index >= len(rates):
             volume_rate_index = -1
         return rates[volume_rate_index]
 
     def get_safe_count(self):
-        if self.is_first_code:
-            if self.buy_rank < 4:
-                return 2
+        # if self.is_first_code:
+        #     if self.buy_rank < 4:
+        #         return 2
         base_count, min_count, max_count = L2TradeFactorUtil.get_safe_buy_count(self.code, True)
         rate = self.get_safe_count_rate()
         count = int(round(base_count * (1 + rate)))
@@ -187,14 +200,14 @@
             global_data_loader.load_zyltgb()
             zyltgb = global_util.zyltgb_map.get(self.code)
 
-        if self.is_first_code:
-            if self.buy_rank == 0:
-                return 0, ""
-            elif self.is_want_buy and zyltgb and zyltgb < 20 * 10000 * 10000:
-                # 灏忎簬20浜跨殑鎯充拱鍗�
-                return 500 * 10000, ""
-            elif self.buy_rank < 4:
-                return 1000 * 10000, ""
+        # if self.is_first_code:
+        #     if self.buy_rank == 0:
+        #         return 0, ""
+        #     elif self.is_want_buy and zyltgb and zyltgb < 20 * 10000 * 10000:
+        #         # 灏忎簬20浜跨殑鎯充拱鍗�
+        #         return 500 * 10000, ""
+        #     elif self.buy_rank < 4:
+        #         return 1000 * 10000, ""
 
         base_m = L2TradeFactorUtil.get_base_safe_val(zyltgb)
         rate = self.get_m_val_rate(self.volume_rate_index)
@@ -244,7 +257,7 @@
     # 鑾峰彇鎾ら攢姣斾緥
     @staticmethod
     def get_cancel_rate(volume_rate_index):
-        rates = [0.39, 0.49, 0.59, 0.69, 0.69, 0.79, 0.79, 0.79]
+        rates = [0.35, 0.45, 0.55, 0.65, 0.65, 0.75, 0.75, 0.75]
         if volume_rate_index >= len(rates):
             volume_rate_index = -1
         return rates[volume_rate_index]
@@ -524,7 +537,7 @@
     # print(L2TradeFactorUtil.get_safe_buy_count("003005"))
     # print(L2TradeFactorUtil.get_rate_factors("003004"))
     # print(L2TradeFactorUtil.factors_to_string("003004"))
-    for i in range(2, 15):
+    for i in range(2, 50):
         print(i, L2TradeFactorUtil.get_base_safe_val(100000000 * i))
     # print(L2TradeFactorUtil.get_limit_up_time_rate("11:30:00"))
     # print(L2TradeFactorUtil.get_limit_up_time_rate("13:00:00"))

--
Gitblit v1.8.0