From a846b46f15ad309a62fe400cf78dd7fc888155d7 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期一, 26 五月 2025 16:39:19 +0800
Subject: [PATCH] 完善大单够了加白机制

---
 api/outside_api_command_callback.py |  106 +++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 79 insertions(+), 27 deletions(-)

diff --git a/api/outside_api_command_callback.py b/api/outside_api_command_callback.py
index b8050ec..db672cd 100644
--- a/api/outside_api_command_callback.py
+++ b/api/outside_api_command_callback.py
@@ -14,12 +14,12 @@
 import constant
 import inited_data
 import outside_api_command_manager
-from cancel_strategy.s_l_h_cancel_strategy import SCancelBigNumComputer
-from code_attribute import gpcode_manager, code_volumn_manager, zyltgb_util
+from cancel_strategy.s_l_h_cancel_strategy import SCancelBigNumComputer, LCancelRateManager
+from code_attribute import gpcode_manager, code_volumn_manager, zyltgb_util, code_nature_analyse
 from code_attribute.code_data_util import ZYLTGBUtil
 from code_attribute.code_l1_data_manager import L1DataManager
 from code_attribute.gpcode_manager import CodePrePriceManager, CodesNameManager, WantBuyCodesManager, \
-    HumanRemoveForbiddenManager
+    HumanRemoveForbiddenManager, HumanForbiddenManager
 from db import mysql_data_delegate as mysql_data, redis_manager_delegate as redis_manager
 from db.redis_manager_delegate import RedisUtils
 from huaxin_client import l1_subscript_codes_manager
@@ -36,7 +36,8 @@
     logger_trade, logger_trade_position_api_request, logger_request_api, \
     logger_real_place_order_position, logger_device
 from output import l2_output_util
-from third_data import kpl_util, history_k_data_manager, huaxin_l1_data_manager, third_blocks_manager, kpl_data_manager
+from third_data import kpl_util, history_k_data_manager, huaxin_l1_data_manager, third_blocks_manager, kpl_data_manager, \
+    history_k_data_util
 from third_data.code_plate_key_manager import KPLCodeJXBlockManager, RealTimeKplMarketData
 from third_data.history_k_data_manager import HistoryKDataManager
 from third_data.history_k_data_util import JueJinApi, HistoryKDatasUtils
@@ -45,10 +46,10 @@
 from third_data.kpl_limit_up_data_manager import CodeLimitUpSequenceManager
 from third_data.kpl_util import KPLDataType
 from third_data.third_blocks_manager import CodeThirdBlocksManager, SOURCE_TYPE_KPL, BlockMapManager
-from trade import trade_manager, l2_trade_util, trade_data_manager, trade_constant
+from trade import trade_manager, l2_trade_util, trade_data_manager, trade_constant, trade_record_log_util
 import l2_data_util as l2_data_util_old
 from trade.buy_money_count_setting import BuyMoneyAndCountSetting, RadicalBuyBlockCodeCountManager
-from trade.buy_radical import block_special_codes_manager
+from trade.buy_radical import block_special_codes_manager, radical_buy_data_manager
 
 from trade.huaxin import huaxin_trade_api, huaxin_trade_data_update, \
     huaxin_trade_record_manager, huaxin_trade_order_processor, huaxin_sell_util
@@ -59,7 +60,7 @@
 from trade.trade_data_manager import RadicalBuyDealCodesManager
 from trade.trade_manager import TradeTargetCodeModeManager, AutoCancelSellModeManager
 from settings.trade_setting import MarketSituationManager, TradeBlockBuyModeManager
-from utils import socket_util, data_export_util, tool, huaxin_util, output_util, global_util
+from utils import socket_util, data_export_util, tool, huaxin_util, output_util, global_util, init_data_util
 from servers import server_util
 
 
@@ -291,17 +292,20 @@
             fresult = {"code": 0}
             if code_list_type == outside_api_command_manager.CODE_LIST_WANT:
                 if operate == outside_api_command_manager.OPERRATE_SET:
+                    trade_record_log_util.add_want_buy(code)
                     gpcode_manager.WantBuyCodesManager().add_code(code)
                     if l2_trade_util.is_in_forbidden_trade_codes(code):
                         l2_trade_util.remove_from_forbidden_trade_codes(code)
                         # 鍔犳兂涔板崟瑕佷粠榛戝悕鍗曠Щ闄�
                         HumanRemoveForbiddenManager().add_code(code)
+                        HumanForbiddenManager().remove_code(code)
                     name = gpcode_manager.get_code_name(code)
                     if not name:
                         results = HistoryKDatasUtils.get_gp_codes_names([code])
                         if results:
                             gpcode_manager.CodesNameManager.add_first_code_name(code, results[code])
                 elif operate == outside_api_command_manager.OPERRATE_DELETE:
+                    trade_record_log_util.remove_want_buy(code)
                     gpcode_manager.WantBuyCodesManager().remove_code(code)
                 elif operate == outside_api_command_manager.OPERRATE_GET:
                     codes = gpcode_manager.WantBuyCodesManager().list_code_cache()
@@ -321,6 +325,7 @@
                     l2_trade_util.forbidden_trade(code, msg="鎵嬪姩鍔犲叆 trade_server", force=True)
                     WantBuyCodesManager().remove_code(code)
                     HumanRemoveForbiddenManager().remove_code(code)
+                    HumanForbiddenManager().add_code(code)
                     name = gpcode_manager.get_code_name(code)
                     if not name:
                         results = HistoryKDatasUtils.get_gp_codes_names([code])
@@ -329,6 +334,7 @@
                 elif operate == outside_api_command_manager.OPERRATE_DELETE:
                     l2_trade_util.remove_from_forbidden_trade_codes(code)
                     HumanRemoveForbiddenManager().add_code(code)
+                    HumanForbiddenManager().remove_code(code)
                 elif operate == outside_api_command_manager.OPERRATE_GET:
                     codes = gpcode_manager.BlackListCodeManager().list_codes_cache()
                     datas = []
@@ -338,14 +344,14 @@
                     fresult = {"code": 0, "data": datas}
             elif code_list_type == outside_api_command_manager.CODE_LIST_WHITE:
                 if operate == outside_api_command_manager.OPERRATE_SET:
-                    gpcode_manager.WhiteListCodeManager().add_code(code)
+                    gpcode_manager.WhiteListCodeManager().add_code(code, is_human=True)
                     name = gpcode_manager.get_code_name(code)
                     if not name:
                         results = HistoryKDatasUtils.get_gp_codes_names([code])
                         if results:
                             gpcode_manager.CodesNameManager.add_first_code_name(code, results[code])
                 elif operate == outside_api_command_manager.OPERRATE_DELETE:
-                    gpcode_manager.WhiteListCodeManager().remove_code(code)
+                    gpcode_manager.WhiteListCodeManager().remove_code(code, is_human=True)
                 elif operate == outside_api_command_manager.OPERRATE_GET:
                     codes = gpcode_manager.WhiteListCodeManager().list_codes_cache()
                     datas = []
@@ -374,6 +380,7 @@
             elif code_list_type == outside_api_command_manager.CODE_LIST_MUST_BUY:
                 if operate == outside_api_command_manager.OPERRATE_SET:
                     gpcode_manager.MustBuyCodesManager().add_code(code)
+                    trade_record_log_util.add_must_buy(code, "鎵嬪姩鎷夌孩")
                     name = gpcode_manager.get_code_name(code)
                     if not name:
                         results = HistoryKDatasUtils.get_gp_codes_names([code])
@@ -487,7 +494,8 @@
         try:
             fdata = {}
             try:
-                date = HistoryKDatasUtils.get_trading_dates(tool.date_sub(tool.get_now_date_str(), 10) ,tool.get_now_date_str())
+                date = HistoryKDatasUtils.get_trading_dates(tool.date_sub(tool.get_now_date_str(), 10),
+                                                            tool.get_now_date_str())
                 if date:
                     fdata["juejin"] = 1
             except Exception as e:
@@ -544,21 +552,11 @@
 
             # 鑾峰彇浠婃棩K绾跨殑鏇存柊鏁伴噺
             try:
-                dates = HistoryKDatasUtils.get_latest_trading_date_cache(5)
-                latest_trading_date = None
-                if dates:
-                    latest_trading_date = dates[0]
-                if latest_trading_date is None:
-                    raise Exception("娌℃湁鑾峰彇鍒颁笂涓�涓氦鏄撴棩鐨勬棩鏈�")
-                # 4鐐逛箣鍚庢敼涓鸿幏鍙栦粖鏃ョ殑鏁版嵁
-                if tool.get_now_time_as_int()>160000:
-                    latest_trading_date = tool.get_now_date_str()
+                latest_trading_date = history_k_data_util.get_k_bar_dead_date()
                 codes = HistoryKDataManager().get_history_bars_codes(latest_trading_date)
                 count = len(codes)
-                logger_debug.info(f"K绾夸唬鐮佹暟閲忥細{count}")
                 fdata["today_history_k_bar_count"] = count
             except Exception as e:
-                logger_debug.exception(e)
                 fdata["today_history_k_bar_count"] = -1
 
             # 鑾峰彇鏁版嵁鏈嶅姟鍣ㄦ槸鍚﹁仈閫�
@@ -1067,6 +1065,23 @@
                                             break
                             except:
                                 pass
+                            # L鎾ゆ瘮渚�
+                            l_down_cancel_rate, must_buy = LCancelRateManager.get_cancel_rate(code,
+                                                                                              buy_mode=OrderBeginPosInfo.MODE_RADICAL)
+
+                            # 鍦ㄦ寕鐨勮窛绂绘垚浜よ繘搴︿綅閲戦/锛堣繙杩戞湡鍙傝�冮噺-鍗曞綋鏃ュ疄鏃舵垚浜ら噺锛�*100%
+                            expire_rate = "鏈煡"
+                            try:
+                                referer_volume = code_volumn_manager.CodeVolumeManager().get_radical_buy_refer_volume(
+                                    code, limit_up_price)
+                                today_volumn = code_volumn_manager.CodeVolumeManager().get_today_volumn_cache(code)
+                                if referer_volume == today_volumn:
+                                    expire_rate = "100%"
+                                else:
+                                    expire_rate = f"{100 - round(100 * total_left_num * 100 / (referer_volume - today_volumn), 2)}%"
+                            except:
+                                pass
+
                             fdata = {"id": orderSysID, "code_info": (code, code_name), "total_num": total_nums,
                                      "finish_num": deal_or_cancel_num,
                                      "buy1_money": output_util.money_desc(buy1_money),
@@ -1089,7 +1104,9 @@
                                      "limit_up_price": gpcode_manager.get_limit_up_price_as_num(code),
                                      "is_near_big_order": is_near_big_order,
                                      "block": '',
-                                     "trade_queue": []
+                                     "trade_queue": [],
+                                     "l_down_cancel_rate": l_down_cancel_rate,
+                                     "expire_rate": expire_rate
                                      }
                             limit_up_data = kpl_data_manager.KPLLimitUpDataRecordManager.record_code_dict.get(code)
                             # 鑾峰彇褰撳墠鏉垮潡
@@ -1291,12 +1308,28 @@
                 filter_blocks, match_blocks = RadicalBuyBlockManager.get_code_blocks(code)
                 source_origin_dict[SOURCE_TYPE_KPL] = kpl_blocks
                 source_dict[SOURCE_TYPE_KPL] = BlockMapManager().filter_blocks(kpl_blocks)
+
+                dates = HistoryKDatasUtils.get_latest_trading_date_cache(5)
+                latest_trading_date = None
+                is_new_top = False
+                if dates:
+                    latest_trading_date = dates[0]
+                if latest_trading_date:
+                    volumes_data = HistoryKDataManager().get_history_bars(code, latest_trading_date)
+                    if volumes_data:
+                        is_new_top = code_nature_analyse.is_new_top(code,
+                                                                    gpcode_manager.get_limit_up_price_by_preprice(code,
+                                                                                                                  volumes_data[0]["close"]),
+                                                                    volumes_data)
+
                 data = {
                     "blocks": {},
                     "origin_blocks": {},
                     "match_blocks": [list(filter_blocks), list(match_blocks)],
                     # 鏉垮潡鍑�娴佸叆鎯呭喌
-                    "block_in_moneys": [RealTimeKplMarketData.get_block_info_at_block_in(b) for b in filter_blocks]
+                    "block_in_moneys": [RealTimeKplMarketData.get_block_info_at_block_in(b) for b in filter_blocks],
+                    # 鏄惁鏄獊鐮存澘
+                    "is_new_top": is_new_top
                 }
                 for s in source_origin_dict:
                     data["origin_blocks"][s] = list(source_origin_dict[s])
@@ -1354,8 +1387,10 @@
                 data = {
                     "radical_buy": {"price": (constant.MIN_CODE_RADICAL_BUY_PRICE, constant.MAX_CODE_RADICAL_BUY_PRICE),
                                     "zyltgb": constant.RADICAL_BUY_ZYLTGB_AS_YI_RANGES,
-                                    "top_block_count_by_market_strong":constant.RADICAL_BUY_TOP_IN_COUNT_BY_MARKET_STRONG,
-                                    "special_codes_max_block_in_rank": constant.RADICAL_BUY_TOP_IN_INDEX_WITH_SPECIAL
+                                    "top_block_count_by_market_strong": constant.RADICAL_BUY_TOP_IN_COUNT_BY_MARKET_STRONG,
+                                    "special_codes_max_block_in_rank": constant.RADICAL_BUY_TOP_IN_INDEX_WITH_SPECIAL,
+                                    "ignore_block_in_money_market_strong": constant.IGNORE_BLOCK_IN_MONEY_MARKET_STRONG,
+                                    "buy_first_limit_up": 1 if constant.CAN_BUY_FIRST_LIMIT_UP else 0
                                     }}
                 self.send_response({"code": 0, "data": data, "msg": f""},
                                    client_id,
@@ -1368,10 +1403,17 @@
                     constant.MAX_CODE_RADICAL_BUY_PRICE = radical_buy["price"][1]
                     constant.RADICAL_BUY_ZYLTGB_AS_YI_RANGES = radical_buy["zyltgb"]
                     if radical_buy.get("top_block_count_by_market_strong"):
-                        constant.RADICAL_BUY_TOP_IN_COUNT_BY_MARKET_STRONG = radical_buy.get("top_block_count_by_market_strong")
+                        constant.RADICAL_BUY_TOP_IN_COUNT_BY_MARKET_STRONG = radical_buy.get(
+                            "top_block_count_by_market_strong")
                     if radical_buy.get("special_codes_max_block_in_rank"):
                         constant.RADICAL_BUY_TOP_IN_INDEX_WITH_SPECIAL = radical_buy.get(
                             "special_codes_max_block_in_rank")
+                    if radical_buy.get('ignore_block_in_money_market_strong') is not None:
+                        constant.IGNORE_BLOCK_IN_MONEY_MARKET_STRONG = radical_buy.get(
+                            'ignore_block_in_money_market_strong')
+                    if radical_buy.get('buy_first_limit_up') is not None:
+                        constant.CAN_BUY_FIRST_LIMIT_UP = True if radical_buy.get(
+                            'buy_first_limit_up') else False
 
                 self.send_response({"code": 0, "data": {}, "msg": f""},
                                    client_id,
@@ -1411,7 +1453,7 @@
                     fblocks, before_fblocks = RadicalBuyBlockManager.get_code_blocks(code)
                     # 鑾峰彇鏉垮潡鍘嗗彶娑ㄥ仠
                     for b in fblocks:
-                        codes =  LimitUpDataConstant.get_history_limit_up_block_codes(b)
+                        codes = LimitUpDataConstant.get_history_limit_up_block_codes(b)
                         if codes:
                             if code not in block_codes:
                                 block_codes[code] = {}
@@ -1420,6 +1462,16 @@
                                    client_id,
                                    request_id)
 
+            elif ctype == "test_place_order":
+                # 鑾峰彇鐩稿悓鏉垮潡鐨勬定鍋滀唬鐮佹暟閲�
+                code = data.get("code")
+                # total_datas = l2_data_util.local_today_datas.get(code)
+                # trade_manager.test_order(code, total_datas[-1], total_datas[-1]["index"])
+                # radical_buy_data_manager.pull_pre_deal_big_orders(code)
+                self.send_response({"code": 0, "data": {}},
+                                   client_id,
+                                   request_id)
+
 
 
         except Exception as e:

--
Gitblit v1.8.0