From 8b848e8a9fa242b39f92f3a28faf89be10a6e456 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期五, 17 三月 2023 17:43:32 +0800
Subject: [PATCH] 首板策略优化

---
 juejin.py |   56 ++++++++++++++++++++++++--------------------------------
 1 files changed, 24 insertions(+), 32 deletions(-)

diff --git a/juejin.py b/juejin.py
index 21ee3b9..a252307 100644
--- a/juejin.py
+++ b/juejin.py
@@ -85,8 +85,8 @@
         l2_trade_util.init_forbidden_trade_codes()
         # 娓呯┖鐧藉悕鍗�
         l2_trade_util.WhiteListCodeManager.clear()
-
-    # TODO 鍒犻櫎鎵�鏈夐鏉夸唬鐮�
+        # 娓呯┖鎯宠涔�
+        gpcode_manager.WantBuyCodesManager.clear()
 
 
 # 姣忔棩鍒濆鍖�
@@ -477,11 +477,11 @@
         return f_results
 
     @classmethod
-    def get_history_tick_n(cls, code, count):
+    def get_history_tick_n(cls, code, count, fields=None):
         account_id, s_id, token = getAccountInfo()
         symbols = gpcode_manager.get_gp_list_with_prefix([code])
         gmapi.set_token(token)
-        results = gmapi.history_n(symbol=symbols[0], frequency="1d", count=count)
+        results = gmapi.history_n(symbol=symbols[0], frequency="1d", count=count, fields=fields)
         return results
 
     @classmethod
@@ -577,24 +577,26 @@
 
 
 # 鑾峰彇杩�90澶╃殑鏈�澶ч噺涓庢渶杩戠殑閲�
+# 鑾峰彇鏈�杩戜竴娆℃定鍋�/娑ㄥ仠涓嬩竴涓氦鏄撴棩鐨勬渶澶у��
 def get_volumn(code) -> object:
-    end = datetime.datetime.now()
-    account_id, s_id, token = getAccountInfo()
-    gmapi.set_token(token)
-    gmapi.set_account_id(account_id)
-    results = gmapi.history_n(symbol=gpcode_manager.get_gp_list_with_prefix([code])[0], frequency="1d",
-                              count=60,
-                              fields="volume",
-                              end_time=end)
-    if not results:
-        return None
-    yes_volume = results[-1]["volume"]
-    max_volume = results[0]["volume"]
-    for result in results:
-        volumn = int(result["volume"])
-        if volumn > max_volume:
-            max_volume = volumn
-    return (max_volume, yes_volume)
+    datas = JueJinManager.get_history_tick_n(code, 60, "open,high,low,close,volume,pre_close,bob")
+    # 璁$畻
+    datas.sort(key=lambda x: x["bob"], reverse=True)
+    max_volume = 0
+    for i in range(len(datas)):
+        # 鏌ヨ娑ㄥ仠
+        item = datas[i]
+        volume = item["volume"]
+        if max_volume < volume:
+            max_volume = volume
+        # 鏄惁鏈夋定鍋�
+        limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"]))
+        if abs(limit_up_price - item["high"]) < 0.01:
+            next_volume = 0
+            if i > 0:
+                next_volume = datas[i - 1]["volume"]
+            return (max(volume, next_volume), max(volume, next_volume))
+    return (max_volume, max_volume)
 
 
 # 鏍规嵁娑ㄥ箙楂樹綆鍒嗛厤浜ゆ槗绐楀彛
@@ -609,14 +611,4 @@
 
 
 if __name__ == '__main__':
-    free_count = 0
-    if free_count < 2:
-        # 绌洪棽浣嶇疆涓嶈冻
-        listen_codes = gpcode_manager.get_listen_codes()
-        for code in listen_codes:
-            if not gpcode_manager.is_in_gp_pool(code):
-                client_id, pos = gpcode_manager.get_listen_code_pos(code)
-                gpcode_manager.set_listen_code_by_pos(client_id, pos, "")
-                free_count += 1
-                if free_count > 2:
-                    break
+    print(get_volumn("002291"))

--
Gitblit v1.8.0