From e0062b65da7f3ff34f4c831cc2ef3635b0f44437 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期五, 18 七月 2025 15:19:52 +0800 Subject: [PATCH] 加倍控制中心接口内容优化 --- api/outside_api_command_callback.py | 270 ++++++++++++++++++++++------------------------------- 1 files changed, 114 insertions(+), 156 deletions(-) diff --git a/api/outside_api_command_callback.py b/api/outside_api_command_callback.py index 27088d6..43c1f89 100644 --- a/api/outside_api_command_callback.py +++ b/api/outside_api_command_callback.py @@ -14,7 +14,8 @@ import constant import inited_data import outside_api_command_manager -from cancel_strategy.s_l_h_cancel_strategy import SCancelBigNumComputer, LCancelRateManager +from cancel_strategy.s_l_h_cancel_strategy import SCancelBigNumComputer, LCancelRateManager, \ + CancelRateHumanSettingManager, LCancelBigNumComputer, LDownCancelWatchIndexStatisticManager 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 @@ -54,11 +55,12 @@ from trade.huaxin import huaxin_trade_api, huaxin_trade_data_update, \ huaxin_trade_record_manager, huaxin_trade_order_processor, huaxin_sell_util from trade.huaxin.huaxin_trade_record_manager import PositionManager, DealRecordManager, DelegateRecordManager -from trade.buy_radical.radical_buy_data_manager import RadicalBuyBlockManager, BeforeSubDealBigOrderManager +from trade.buy_radical.radical_buy_data_manager import RadicalBuyBlockManager, BeforeSubDealBigOrderManager, \ + TotalDealBigOrderThresholdMoneyManager from trade.sell import sell_manager from trade.sell.sell_rule_manager import TradeRuleManager, SellRule from trade.trade_data_manager import RadicalBuyDealCodesManager -from trade.trade_manager import TradeTargetCodeModeManager, AutoCancelSellModeManager +from trade.trade_manager import TradeTargetCodeModeManager, AutoCancelSellModeManager, CodesContinueBuyMoneyManager from settings.trade_setting import MarketSituationManager, TradeBlockBuyModeManager from utils import socket_util, data_export_util, tool, huaxin_util, output_util, global_util, init_data_util from servers import server_util @@ -398,7 +400,13 @@ 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) + trade_record_log_util.add_green(code, "浜轰负鍔犵豢") + gpcode_manager.WantBuyCodesManager().add_code(code) + # 鍔犵櫧 + gpcode_manager.WhiteListCodeManager().add_code(code, is_human=True) + trade_record_log_util.add_white_buy(code, "鍔犵豢鍔犵櫧") + name = gpcode_manager.get_code_name(code) if not name: results = HistoryKDatasUtils.get_gp_codes_names([code]) @@ -406,7 +414,7 @@ gpcode_manager.CodesNameManager.add_first_code_name(code, results[code]) elif operate == outside_api_command_manager.OPERRATE_DELETE: gpcode_manager.GreenListCodeManager().remove_code(code) - gpcode_manager.WantBuyCodesManager().remove_code(code) + gpcode_manager.WhiteListCodeManager().remove_code(code) elif operate == outside_api_command_manager.OPERRATE_GET: codes = gpcode_manager.GreenListCodeManager().list_codes_cache() datas = [] @@ -873,17 +881,22 @@ account_available_money = trade_data_manager.AccountMoneyManager().get_available_money_cache() # 鑾峰彇濮旀墭涓殑浠g爜 # current_delegates = huaxin_trade_record_manager.DelegateRecordManager().list_current_delegates() + # TODO 娴嬭瘯 current_delegates, update_time = huaxin_trade_record_manager.DelegateRecordManager.list_by_day( tool.get_now_date_str("%Y%m%d"), None, - [huaxin_util.TORA_TSTP_OST_Accepted, huaxin_util.TORA_TSTP_OST_PartTraded]) + [huaxin_util.TORA_TSTP_OST_Accepted, huaxin_util.TORA_TSTP_OST_PartTraded, huaxin_util.TORA_TSTP_OST_AllCanceled ]) fdatas = [] if current_delegates: + codes_set = set() for c in current_delegates: try: if int(c["direction"]) != huaxin_util.TORA_TSTP_D_Buy: continue code = c["securityID"] + if code in codes_set: + continue orderSysID = c.get("orderSysID") + codes_set.add(code) code_name = gpcode_manager.get_code_name(code) # 鑾峰彇涓嬪崟浣嶇疆淇℃伅 order_begin_pos = TradePointManager().get_buy_compute_start_data_cache(code) @@ -900,22 +913,7 @@ place_order_index = SCancelBigNumComputer().get_real_place_order_index_cache(code) if place_order_index is None: place_order_index = 0 - # 璁$畻淇″彿浣嶇疆鍒扮湡瀹炰笅鍗曚綅缃殑鎬讳拱锛堜笉绠℃槸鍚﹀凡鎾わ級 - total_nums = 0 - for i in range(order_begin_pos.buy_single_index, place_order_index): - data = total_datas[i] - val = data["val"] - if not L2DataUtil.is_limit_up_price_buy(val): - continue - total_nums += val["num"] - # 璁$畻宸叉垚浜�/宸叉挙鍗曠殑鏁伴噺 - deal_or_cancel_num = 0 - for i in range(order_begin_pos.buy_single_index, trade_index + 1): - data = total_datas[i] - val = data["val"] - if not L2DataUtil.is_limit_up_price_buy(val): - continue - deal_or_cancel_num += val["num"] + # 鑾峰彇鍓╀笅鐨勭瑪鏁� total_left_count = 0 total_left_num = 0 @@ -940,69 +938,10 @@ if dealing_info: if str(total_datas[trade_index]["val"]["orderNo"]) == str(dealing_info[0]): total_left_num += (total_datas[trade_index]["val"]["num"] - dealing_info[1] // 100) - limit_up_price = gpcode_manager.get_limit_up_price(code) + limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) buy1_money = Buy1PriceManager().get_latest_buy1_money(code) if buy1_money is None: buy1_money = 1 - # 鑾峰彇宸茬粡鎴愪氦鐨勫ぇ鍗曟暟閲� - total_big_num = 0 - total_big_count = 0 - is_ge_code = tool.is_ge_code(code) - for i in range(0, trade_index): - val = total_datas[i]["val"] - if not L2DataUtil.is_limit_up_price_buy(val): - continue - # 鏄笉鏄ぇ鍗� - if not l2_data_util_old.is_big_money(val, is_ge_code): - continue - - canceled_data = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_canceled_data_v2( - code, - i, - total_datas, - l2_data_util.local_today_canceled_buyno_map.get( - code)) - if not canceled_data: - total_big_count += 1 - else: - total_big_num -= canceled_data["val"]["num"] - total_big_num += val["num"] - - not_deal_total_big_num_pre = 0 - not_deal_total_big_count_pre = 0 - not_deal_total_big_num_after = 0 - not_deal_total_big_count_after = 0 - is_ge_code = tool.is_ge_code(code) - for i in range(trade_index, total_datas[-1]["index"] + 1): - val = total_datas[i]["val"] - if not L2DataUtil.is_limit_up_price_buy(val): - continue - # 鏄笉鏄ぇ鍗� - if not l2_data_util_old.is_big_money(val, is_ge_code): - continue - - canceled_data = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_canceled_data_v2( - code, - i, - total_datas, - l2_data_util.local_today_canceled_buyno_map.get( - code)) - if not canceled_data: - if i < place_order_index: - not_deal_total_big_count_pre += 1 - else: - not_deal_total_big_count_after += 1 - - else: - if i < place_order_index: - not_deal_total_big_num_pre -= canceled_data["val"]["num"] - else: - not_deal_total_big_num_after -= canceled_data["val"]["num"] - if i < place_order_index: - not_deal_total_big_num_pre += val["num"] - else: - not_deal_total_big_num_after += val["num"] - real_place_order_after_count = 0 real_place_order_after_num = 0 is_ge_code = tool.is_ge_code(code) @@ -1025,88 +964,26 @@ real_place_order_after_count += 1 real_place_order_after_num += val["num"] - # 鑾峰彇褰撴棩鐨勯噺姣� - volume_rate = code_volumn_manager.CodeVolumeManager().get_volume_rate(code) - # 鏄惁闇�瑕佹敞鎰� need_pay_attention = (total_left_count <= 10 or total_left_num * float( limit_up_price) * 100 < 1500 * 10000) and ( - real_place_order_after_count <= 10 or real_place_order_after_num * float( - limit_up_price) * 100 < 1500 * 10000) - - # 缁熻鐪熷疄涓嬪崟浣嶆槸鍚﹁窛绂诲ぇ鍗曚綅缃繃杩� - - is_near_big_order = False - try: - count = 0 - for i in range(place_order_index - 1, -1, -1): - data = total_datas[i] - val = data["val"] - if not L2DataUtil.is_limit_up_price_buy(val): - continue - money = val["num"] * float(val["price"]) - if money < 50 * 100: - continue - left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2( - code, - i, - total_datas, - l2_data_util.local_today_canceled_buyno_map.get( - code)) - if left_count <= 0: - continue - - if money >= 299 * 100: - if count < 1: - is_near_big_order = True - else: - count += 1 - if count >= 1: - break - except: - pass + real_place_order_after_count <= 10 or real_place_order_after_num * limit_up_price * 100 < 1500 * 10000) # L鎾ゆ瘮渚� - l_down_cancel_rate, must_buy = LCancelRateManager.get_cancel_rate(code, - buy_mode=OrderBeginPosInfo.MODE_RADICAL) + l_down_cancel_rate, must_buy, cancel_rate_info = 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, + fdata = {"id": orderSysID, "code_info": (code, code_name), "buy1_money": output_util.money_desc(buy1_money), - "big_num_count": total_big_count, - "big_num_money": output_util.money_desc( - total_big_num * float(limit_up_price) * 100), - "not_deal_big_num_count": ( - not_deal_total_big_count_pre, not_deal_total_big_count_after), - "not_deal_big_num_money": (output_util.money_desc( - not_deal_total_big_num_pre * float(limit_up_price) * 100), - output_util.money_desc( - not_deal_total_big_num_after * float( - limit_up_price) * 100)), "left_count": total_left_count, - "volume_rate": volume_rate, "left_money": output_util.money_desc(total_left_num * float(limit_up_price) * 100), "pay_attention": need_pay_attention, "trade_progress_percent": round( total_left_num * float(limit_up_price) * 100 * 100 / buy1_money, 2), # 鎴愪氦杩涘害姣斾緥 - "limit_up_price": gpcode_manager.get_limit_up_price_as_num(code), - "is_near_big_order": is_near_big_order, + "limit_up_price": limit_up_price, "block": '', "trade_queue": [], "l_down_cancel_rate": l_down_cancel_rate, - "expire_rate": expire_rate + "l_down_cancel_rate_info": cancel_rate_info, } limit_up_data = kpl_data_manager.KPLLimitUpDataRecordManager.record_code_dict.get(code) # 鑾峰彇褰撳墠鏉垮潡 @@ -1143,15 +1020,14 @@ fdata['zyltgb'] = output_util.money_desc(zyltgb) except: pass - + # L鍚庡泭鎷揩鐓� try: - if order_begin_pos: - fdata['mode'] = order_begin_pos.mode - else: - fdata['mode'] = -1 + current_info = LCancelBigNumComputer().statistic_l_down_watch_indexes_info(code) + fdata['l_down_watch_indexes_info'] = {} + if current_info: + fdata['l_down_watch_indexes_info']['current'] = current_info except: pass - fdatas.append(fdata) except Exception as e: logger_debug.exception(e) @@ -1319,7 +1195,9 @@ 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[ + 0][ + "close"]), volumes_data) data = { @@ -1476,7 +1354,87 @@ client_id, request_id) + elif ctype == "test_cancel_order": + # 鑾峰彇鐩稿悓鏉垮潡鐨勬定鍋滀唬鐮佹暟閲� + code = data.get("code") + trade_manager.start_cancel_buy(code, force=True) + self.send_response({"code": 0, "data": {}}, + client_id, + request_id) + elif ctype == "set_total_deal_big_order_threshold_money": + code = data.get("code") + money = data.get("money") + if not code or not money: + self.send_response({"code": 1, "data": {}, "msg": "code/money涓虹┖"}, + client_id, + request_id) + return + TotalDealBigOrderThresholdMoneyManager().set_money(code, int(money), + trade_manager.CodesTradeStateManager().get_trade_state_cache( + code)) + + # 濡傛灉鏄姞绾㈢姸鎬侊紝涓斿ぇ鍗曚笉澶熷氨闇�瑕佺Щ绾� + if gpcode_manager.MustBuyCodesManager().is_in_cache(code): + deal_big_order_info = radical_buy_data_manager.get_total_deal_big_order_info(code, + gpcode_manager.get_limit_up_price_as_num( + code)) + if deal_big_order_info[0] > 0: + gpcode_manager.MustBuyCodesManager().remove_code(code) + trade_record_log_util.add_common_msg(code, "绉荤孩", f"澶у崟闃堝�间慨鏀癸紙{money}锛�") + self.send_response({"code": 0, "data": {}}, + client_id, + request_id) + elif ctype == "set_l_down_rate": + # 璁剧疆L鍚庢挙鍗曟瘮渚� + code = data.get("code") + rate = data.get("rate") + if rate < 0 or rate > 2: + self.send_response({"code": 1, "msg": "姣斾緥鑼冨洿涓嶅湪0-1涔嬮棿"}, + client_id, + request_id) + return + rate = round(rate, 2) + old_rate = LCancelRateManager().get_cancel_rate(0)[0] + CancelRateHumanSettingManager().set_l_down(code, rate) + # L鍚庨噸鏂板泭鎷� + if rate < old_rate: + # 鏀瑰皬鎵嶈兘閲嶆柊鍥婃嫭 + LCancelBigNumComputer().re_compute_l_down_watch_indexes(code, is_force=True) + self.send_response({"code": 0, "data": {}}, + client_id, + request_id) + + elif ctype == "get_continue_buy_info": + # 璁剧疆L鍚庢挙鍗曟瘮渚� + code = data.get("code") + money = CodesContinueBuyMoneyManager().get_continue_buy_money(code) + if money is None: + money = 0 + self.send_response({"code": 0, "data": {"money": money, "money_list": constant.AVAILABLE_BUY_MONEYS}}, + client_id, + request_id) + elif ctype == "set_continue_buy_money": + # 璁剧疆L鍚庢挙鍗曟瘮渚� + code = data.get("code") + money = data.get("money") + if money <= 0: + # 琛ㄧず绉婚櫎缁拱閲戦 + CodesContinueBuyMoneyManager().remove_continue_buy_money(code) + self.send_response({"code": 0, "data": {}}, + client_id, + request_id) + return + if money not in constant.AVAILABLE_BUY_MONEYS: + self.send_response({"code": 1, "msg": f"閲戦锛坽money}锛夋病鍦▄constant.AVAILABLE_BUY_MONEYS}涓�"}, + client_id, + request_id) + return + CodesContinueBuyMoneyManager().set_continue_buy_money(code, money) + l2_trade_util.remove_from_forbidden_trade_codes(code) + self.send_response({"code": 0, "data": {}}, + client_id, + request_id) except Exception as e: logging.exception(e) -- Gitblit v1.8.0