From befe1e660da97a583781d7948aebf23da8424493 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 10 十月 2024 14:21:51 +0800
Subject: [PATCH] bug修复

---
 api/outside_api_command_callback.py |  145 +++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 124 insertions(+), 21 deletions(-)

diff --git a/api/outside_api_command_callback.py b/api/outside_api_command_callback.py
index f6d056a..a5b5ee6 100644
--- a/api/outside_api_command_callback.py
+++ b/api/outside_api_command_callback.py
@@ -1,4 +1,5 @@
 import concurrent.futures
+import copy
 import json
 import logging
 import threading
@@ -33,14 +34,18 @@
     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_data_manager, kpl_util, history_k_data_manager
-from third_data.code_plate_key_manager import CodePlateKeyBuyManager
+from third_data import kpl_util, history_k_data_manager, huaxin_l1_data_manager, third_blocks_manager, kpl_data_manager
+from third_data.code_plate_key_manager import CodePlateKeyBuyManager, KPLCodeJXBlockManager, RealTimeKplMarketData, \
+    RadicalBuyBlockManager
 from third_data.history_k_data_manager import HistoryKDataManager
 from third_data.history_k_data_util import JueJinApi, HistoryKDatasUtils
 from third_data.kpl_data_manager import KPLDataManager
+from third_data.kpl_limit_up_data_manager import CodeLimitUpSequenceManager
 from third_data.kpl_util import KPLDataType
-from trade import trade_manager, l2_trade_util
+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
 import l2_data_util as l2_data_util_old
+from trade.buy_money_count_setting import BuyMoneyAndCountSetting
 
 from trade.huaxin import huaxin_trade_api, huaxin_trade_data_update, \
     huaxin_trade_record_manager, huaxin_trade_order_processor, huaxin_sell_util
@@ -48,9 +53,9 @@
 from trade.sell import sell_manager
 from trade.sell.sell_rule_manager import TradeRuleManager, SellRule
 from trade.trade_manager import TradeTargetCodeModeManager, AutoCancelSellModeManager
-from settings.trade_setting import MarketSituationManager
+from settings.trade_setting import MarketSituationManager, TradeBlockBuyModeManager
 from utils import socket_util, data_export_util, tool, huaxin_util, output_util, global_util
-from server import server_util
+from servers import server_util
 
 
 class OutsideApiCommandCallback(outside_api_command_manager.ActionCallback):
@@ -135,7 +140,7 @@
                                 raise Exception("灏氭湭鑾峰彇鍒扮幇浠�")
                             # 鑾峰彇涔�1閲戦
                             price = round(float(current_price), 2)
-                            buy1_info = L1DataManager.current_buy1_dict.get(code)
+                            buy1_info = huaxin_l1_data_manager.get_buy1_info(code)
                             if buy1_info and buy1_info[0] * buy1_info[1] > 50 * 10000:
                                 # 濡傛灉涔�1鍦�50w浠ヤ笂灏卞姞涓�妗�
                                 price += 0.01
@@ -160,6 +165,7 @@
                 accountID = data["accountID"]
                 orderSysID = data["orderSysID"]
                 sinfo = data["sinfo"]
+                async_log_util.info(logger_trade, f"API鎾ゅ崟: {data}")
                 if orderSysID:
                     result = huaxin_trade_api.cancel_order(direction, code, orderSysID, sinfo=sinfo,
                                                            blocking=True, request_id=request_id)
@@ -178,11 +184,13 @@
                         msg_list.append(f"鎾ゅ崠鍗曟暟閲忥細{sell_count}")
                     except Exception as e:
                         logger_debug.exception(e)
-                    can_cancel = l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "鎵嬪姩鎾ゅ崟")
+                    can_cancel = l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "鎵嬪姩鎾ゅ崟",
+                                                                                     cancel_type=trade_constant.CANCEL_TYPE_HUMAN)
                     if not can_cancel:
                         msg_list.append(f"鏃犳硶鎾や拱鍗�")
                     else:
                         msg_list.append(f"宸叉挙涔板崟")
+                    async_log_util.info(logger_trade, f"API鎾ゅ崟缁撴灉: {msg_list}")
                     self.send_response({"code": 0, "data": {"code": 0, "msg": "锛�".join(msg_list)}}, client_id,
                                        request_id)
         except Exception as e:
@@ -273,10 +281,14 @@
             code_list_type = data["code_list_type"]
             operate = data["operate"]
             code = data.get("code")
+            if code and not tool.is_can_buy_code(code):
+                raise Exception(f"涓嶆槸鍙互浜ゆ槗鐨勪唬鐮侊細{code}")
             fresult = {"code": 0}
             if code_list_type == outside_api_command_manager.CODE_LIST_WANT:
                 if operate == outside_api_command_manager.OPERRATE_SET:
                     gpcode_manager.WantBuyCodesManager().add_code(code)
+                    # 鍔犳兂涔板崟瑕佷粠榛戝悕鍗曠Щ闄�
+                    l2_trade_util.remove_from_forbidden_trade_codes(code)
                     name = gpcode_manager.get_code_name(code)
                     if not name:
                         results = HistoryKDatasUtils.get_gp_codes_names([code])
@@ -295,7 +307,8 @@
                 if operate == outside_api_command_manager.OPERRATE_SET:
                     # 鍏堟墜鍔ㄦ挙鍗�
                     try:
-                        l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "鎵嬪姩鎷夐粦")
+                        l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "鎵嬪姩鎷夐粦",
+                                                                            cancel_type=trade_constant.CANCEL_TYPE_HUMAN)
                     except Exception as e:
                         logger_debug.exception(e)
                     l2_trade_util.forbidden_trade(code, msg="鎵嬪姩鍔犲叆 trade_server")
@@ -367,6 +380,23 @@
                         name = gpcode_manager.get_code_name(code)
                         datas.append(f"{name}:{code}")
                     fresult = {"code": 0, "data": datas}
+            elif code_list_type == outside_api_command_manager.CODE_LIST_GREEN:
+                if operate == outside_api_command_manager.OPERRATE_SET:
+                    gpcode_manager.GreenListCodeManager().add_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:
+                    gpcode_manager.GreenListCodeManager().remove_code(code)
+                elif operate == outside_api_command_manager.OPERRATE_GET:
+                    codes = gpcode_manager.GreenListCodeManager().list_codes_cache()
+                    datas = []
+                    for code in codes:
+                        name = gpcode_manager.get_code_name(code)
+                        datas.append(f"{name}:{code}")
+                    fresult = {"code": 0, "data": datas}
 
             self.send_response(fresult, client_id, request_id)
         except Exception as e:
@@ -413,7 +443,7 @@
             white = gpcode_manager.WhiteListCodeManager().is_in_cache(code)
             black = l2_trade_util.is_in_forbidden_trade_codes(code)
             pause_buy = gpcode_manager.PauseBuyCodesManager().is_in_cache(code)
-
+            must_buy = gpcode_manager.MustBuyCodesManager().is_in_cache(code)
             desc_list = []
             if want:
                 desc_list.append("銆愭兂涔板崟銆�")
@@ -423,6 +453,9 @@
                 desc_list.append("銆愰粦鍚嶅崟銆�")
             if pause_buy:
                 desc_list.append("銆愭殏涓嶄拱銆�")
+            if must_buy:
+                desc_list.append("銆愮孩鍚嶅崟銆�")
+
             result = {"code": 0, "data": {"code_info": (code, code_name), "desc": "".join(desc_list)}}
             self.send_response(result, client_id, request_id)
         except Exception as e:
@@ -535,6 +568,11 @@
                 l1_subscript_codes_manager.save_codes(codes_sh, codes_sz)
             result = {"code": 0, "data": {"codes_sh": len(codes_sh), "codes_sz": len(codes_sz)}}
             self.send_response(result, client_id, request_id)
+            # 鎷夊彇涓夋柟鏉垮潡
+            codes = []
+            codes.extend(codes_sh)
+            codes.extend(codes_sz)
+            threading.Thread(target=third_blocks_manager.load_if_less, args=(codes,), daemon=True).start()
         except Exception as e:
             logger_debug.error(e)
 
@@ -817,7 +855,7 @@
                 except Exception as e:
                     self.send_response({"code": 1, "msg": str(e)}, client_id, request_id)
             elif ctype == "get_delegated_buy_code_infos":
-                account_available_money = trade_manager.AccountAvailableMoneyManager().get_available_money_cache()
+                account_available_money = trade_data_manager.AccountMoneyManager().get_available_money_cache()
                 # 鑾峰彇濮旀墭涓殑浠g爜
                 # current_delegates = huaxin_trade_record_manager.DelegateRecordManager().list_current_delegates()
                 current_delegates, update_time = huaxin_trade_record_manager.DelegateRecordManager.list_by_day(
@@ -1035,17 +1073,10 @@
                             limit_up_data = kpl_data_manager.KPLLimitUpDataRecordManager.record_code_dict.get(code)
                             # 鑾峰彇褰撳墠鏉垮潡
                             try:
-                                can_buy_result = CodePlateKeyBuyManager.can_buy(code)
-                                if can_buy_result:
-                                    if can_buy_result[0]:
-                                        fdata['block'] = ",".join(
-                                            [f"{x[0]}-{x[1] + 1}({x[2]}&{x[3] - x[2]})" for x in can_buy_result[0]])
-                                    else:
-                                        if can_buy_result[1]:
-                                            if limit_up_data:
-                                                fdata['block'] = f"{limit_up_data[5]}-鐙嫍"
-                                            else:
-                                                fdata['block'] = f"鐙嫍"
+                                limit_up_sequence = CodeLimitUpSequenceManager.get_current_limit_up_sequence(code)
+                                if limit_up_sequence:
+                                    fdata[
+                                        'block'] = f"{limit_up_sequence[0]}-{limit_up_sequence[1]}({limit_up_sequence[2]}&{limit_up_sequence[2] - limit_up_sequence[3]})"
                             except:
                                 pass
                             # 鑾峰彇娑ㄥ仠鏃堕棿
@@ -1181,8 +1212,80 @@
                 count = history_k_data_manager.update_history_k_bars()
                 self.send_response({"code": 0, "data": {"count": count}, "msg": f"闇�瑕佹洿鏂癒绾夸唬鐮佹暟閲忥細{count}"}, client_id,
                                    request_id)
+            elif ctype == "get_buy_block_mode":
+                # 鑾峰彇涔板叆鏉垮潡鐨勬ā寮�
+                can_buy_unique_block = TradeBlockBuyModeManager().can_buy_unique_block()
+                self.send_response({"code": 0, "data": {"unique_block": 1 if can_buy_unique_block else 0}, "msg": f""},
+                                   client_id,
+                                   request_id)
+
+            elif ctype == "set_buy_unique_block_mode":
+                mode = data["mode"]
+                # 娣诲姞鐙嫍涔板叆妯″紡
+                if mode > 0:
+                    TradeBlockBuyModeManager().add_unique_block()
+                else:
+                    TradeBlockBuyModeManager().remove_unique_block()
+                self.send_response({"code": 0, "data": {}, "msg": f""},
+                                   client_id,
+                                   request_id)
+            elif ctype == "get_code_third_blocks":
+                # 鑾峰彇绗笁鏂规澘鍧楁暟鎹�
+                code = data["code"]
+                source_dict = copy.deepcopy(CodeThirdBlocksManager().get_source_blocks(code))
+                if not source_dict:
+                    source_dict = {}
+                source_origin_dict = copy.deepcopy(CodeThirdBlocksManager().get_source_blocks_origin(code))
+                if not source_origin_dict:
+                    source_origin_dict = {}
+                kpl_blocks = RadicalBuyBlockManager.get_code_kpl_blocks(code)
+                if kpl_blocks is None:
+                    kpl_blocks = set()
+                if not kpl_blocks:
+                    KPLCodeJXBlockManager().load_jx_blocks_radical(code)
+
+                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)
+                data = {
+                    "blocks": {},
+                    "origin_blocks": {},
+                    "match_blocks": [list(filter_blocks), list(match_blocks)]
+                }
+                for s in source_origin_dict:
+                    data["origin_blocks"][s] = list(source_origin_dict[s])
+                for s in source_dict:
+                    data["blocks"][s] = list(source_dict[s])
+
+                self.send_response({"code": 0, "data": data, "msg": f""},
+                                   client_id,
+                                   request_id)
+            elif ctype == "set_buy_money_count_setting":
+                # 璁剧疆涔板叆閲戦鍜屾暟閲�
+                normal = data["normal"]
+                radical = data["radical"]
+                BuyMoneyAndCountSetting().set_normal_buy_data(normal[0], json.loads(normal[1]))
+                BuyMoneyAndCountSetting().set_radical_buy_data(radical[0], json.loads(radical[1]))
+                data = {
+                    "normal": BuyMoneyAndCountSetting().get_normal_buy_setting(),
+                    "radical": BuyMoneyAndCountSetting().get_radical_buy_setting()
+                }
+                self.send_response({"code": 0, "data": data, "msg": f""},
+                                   client_id,
+                                   request_id)
+            elif ctype == "get_buy_money_count_setting":
+                # 璁剧疆涔板叆閲戦鍜屾暟閲�
+                data = {
+                    "normal": BuyMoneyAndCountSetting().get_normal_buy_setting(),
+                    "radical": BuyMoneyAndCountSetting().get_radical_buy_setting(),
+                    "moneys":constant.AVAILABLE_BUY_MONEYS
+                }
+                self.send_response({"code": 0, "data": data, "msg": f""},
+                                   client_id,
+                                   request_id)
         except Exception as e:
             logging.exception(e)
+            logger_debug.exception(e)
             self.send_response({"code": 1, "msg": f"鏁版嵁澶勭悊鍑洪敊锛歿e}"}, client_id, request_id)
         finally:
             use_time = time.time() - __start_time

--
Gitblit v1.8.0