From ad615df734b4d82f9a83a7d1805ac9fabdf01a53 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期四, 21 八月 2025 18:27:39 +0800 Subject: [PATCH] 200元股价以下的不足4手算4手/撤单率设置为100%不计算L后后半段撤单 --- api/outside_api_command_callback.py | 402 ++++++++++++++++++++++++++++++++------------------------ 1 files changed, 230 insertions(+), 172 deletions(-) diff --git a/api/outside_api_command_callback.py b/api/outside_api_command_callback.py index 897abee..6c1a734 100644 --- a/api/outside_api_command_callback.py +++ b/api/outside_api_command_callback.py @@ -20,7 +20,7 @@ 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, HumanForbiddenManager + HumanRemoveForbiddenManager, HumanForbiddenManager, CodesContinueBuyMoneyManager 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 @@ -60,7 +60,8 @@ 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, CodesContinueBuyMoneyManager +from trade.trade_manager import TradeTargetCodeModeManager, AutoCancelSellModeManager, \ + CodesTradeStateManager 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 @@ -319,11 +320,11 @@ elif code_list_type == outside_api_command_manager.CODE_LIST_BLACK: if operate == outside_api_command_manager.OPERRATE_SET: # 鍏堟墜鍔ㄦ挙鍗� - try: - l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "鎵嬪姩鎷夐粦", - cancel_type=trade_constant.CANCEL_TYPE_HUMAN) - except Exception as e: - logger_debug.exception(e) + # try: + # 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", force=True) WantBuyCodesManager().remove_code(code) HumanRemoveForbiddenManager().remove_code(code) @@ -805,7 +806,7 @@ current_price = L1DataManager.get_l1_current_price(code) if current_price: fdata["cost_price"] = current_price - pre_close_price = CodePrePriceManager.get_price_pre_cache(code) + pre_close_price = CodePrePriceManager().get_price_pre_cache(code) if current_price and pre_close_price: rate = round((float(current_price) - float(pre_close_price)) / float(pre_close_price), 4) fdata["cost_price_rate"] = rate @@ -912,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 @@ -952,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) @@ -1037,89 +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, 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, float(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 Exception as e: - logger_debug.exception(e) - - 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, "l_down_cancel_rate_info": cancel_rate_info, - "expire_rate": expire_rate } limit_up_data = kpl_data_manager.KPLLimitUpDataRecordManager.record_code_dict.get(code) # 鑾峰彇褰撳墠鏉垮潡 @@ -1156,29 +1020,187 @@ fdata['zyltgb'] = output_util.money_desc(zyltgb) except: pass - - try: - if order_begin_pos: - fdata['mode'] = order_begin_pos.mode - else: - fdata['mode'] = -1 - except: - pass # L鍚庡泭鎷揩鐓� try: current_info = LCancelBigNumComputer().statistic_l_down_watch_indexes_info(code) - last_info = LDownCancelWatchIndexStatisticManager().get_statistic_info(code) fdata['l_down_watch_indexes_info'] = {} if current_info: fdata['l_down_watch_indexes_info']['current'] = current_info - if last_info: - fdata['l_down_watch_indexes_info']['last'] = last_info - except: - pass + except Exception as e: + logger_debug.exception(e) fdatas.append(fdata) except Exception as e: logger_debug.exception(e) + result = {"code": 0, "data": {"account_available_money": account_available_money, "delegates": fdatas, "rate_of_increase_step": constant.L_DOWN_RATE_INCREASE_STEP}} + self.send_response(result, client_id, request_id) + elif ctype == "get_delegated_buy_code_infos_v2": + account_available_money = trade_data_manager.AccountMoneyManager().get_available_money_cache() + # 鑾峰彇濮旀墭涓殑浠g爜 + current_delegates = huaxin_trade_record_manager.DelegateRecordManager().list_current_delegates() + fdatas = [] + if current_delegates: + codes_set = set() + for c in current_delegates: + _start_time = time.time() + 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) + if order_begin_pos is None or order_begin_pos.buy_single_index is None: + order_begin_pos = OrderBeginPosInfo(buy_single_index=0, buy_exec_index=0) + l2_data_util.load_l2_data(code) + total_datas = l2_data_util.local_today_datas.get(code) + if not total_datas: + continue + trade_index, is_default = transaction_progress.TradeBuyQueue().get_traded_index(code) + if trade_index is None: + trade_index = 0 + # 涓嬪崟浣嶇疆 + place_order_index = SCancelBigNumComputer().get_real_place_order_index_cache(code) + if place_order_index is None: + place_order_index = 0 + + # 鑾峰彇鍓╀笅鐨勭瑪鏁� + total_left_count = 0 + total_left_num = 0 + for i in range(trade_index + 1, place_order_index): + data = total_datas[i] + val = data["val"] + if not L2DataUtil.is_limit_up_price_buy(val): + continue + if val["num"] * float(val["price"]) < 5000: + 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: + total_left_count += left_count + total_left_num += val["num"] * left_count + # 鑾峰彇姝e湪鎴愪氦 + dealing_info = HuaXinBuyOrderManager.get_dealing_order_info(code) + 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_as_num(code) + buy1_money = Buy1PriceManager().get_latest_buy1_money(code) + if buy1_money is None: + buy1_money = 1 + real_place_order_after_count = 0 + real_place_order_after_num = 0 + is_ge_code = tool.is_ge_code(code) + # 缁熻鐪熷疄涓嬪崟浣嶇疆鍚庨潰鏈挙鐨勯噾棰� + for i in range(place_order_index, total_datas[-1]["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: + real_place_order_after_count += 1 + real_place_order_after_num += val["num"] + + # 鏄惁闇�瑕佹敞鎰� + 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 * limit_up_price * 100 < 1500 * 10000) + # L鎾ゆ瘮渚� + l_down_cancel_rate, must_buy, cancel_rate_info = LCancelRateManager.get_cancel_rate(code, + buy_mode=OrderBeginPosInfo.MODE_RADICAL) + + # 璁$畻澶у崟鎴愪氦 + # (缂哄皯鐨勮祫閲�, 鍑�鎴愪氦閲戦, 瑕佹眰鐨勫ぇ鍗曢噾棰�, 璁$畻寰楀埌鐨勫ぇ鍗曢槇鍊奸噾棰�, 浜轰负璁剧疆鐨勫ぇ鍗�) + deal_big_money_info = radical_buy_data_manager.get_total_deal_big_order_info( + code, gpcode_manager.get_limit_up_price_as_num(code)) + + fdata = {"id": orderSysID, "code_info": (code, code_name), + "buy1_money": output_util.money_desc(buy1_money), + "left_count": total_left_count, + "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": limit_up_price, + "block": '', + "trade_queue": [], + "l_down_cancel_rate": l_down_cancel_rate, + "l_down_cancel_rate_info": cancel_rate_info + } + if deal_big_money_info: + fdata["deal_big_money_info"] = deal_big_money_info + + limit_up_data = kpl_data_manager.KPLLimitUpDataRecordManager.record_code_dict.get(code) + # 鑾峰彇褰撳墠鏉垮潡 + try: + limit_up_sequences = CodeLimitUpSequenceManager.get_current_limit_up_sequence(code) + if limit_up_sequences: + buy_blocks = RadicalBuyDealCodesManager().get_code_blocks(code) + blocks_info = [] + for limit_up_sequence in limit_up_sequences: + # 鑾峰彇浠g爜涓嬪崟鐨勬澘鍧� + if buy_blocks and limit_up_sequence[0] not in buy_blocks: + continue + blocks_info.append( + f"{limit_up_sequence[0]}-{limit_up_sequence[1]}({limit_up_sequence[2]}&{limit_up_sequence[2] - limit_up_sequence[3]})") + if buy_blocks: + fdata['block'] = "/".join(blocks_info) + except: + pass + # 鑾峰彇娑ㄥ仠鏃堕棿 + if limit_up_data: + fdata['limit_up_time'] = tool.to_time_str(limit_up_data[2]) + + # 鑾峰彇濮旀墭闃熷垪 + try: + real_place_order_index = SCancelBigNumComputer().get_real_place_order_index_cache(code) + if real_place_order_index is not None: + trade_queue = l2_output_util.get_trade_queue_at_near_place_order(code, + real_place_order_index, + 9) + fdata['trade_queue'] = trade_queue + # 鑷敱娴侀�氳偂鏈� + zyltgb = global_util.zyltgb_map.get(code) + if zyltgb is not None: + fdata['zyltgb'] = output_util.money_desc(zyltgb) + except: + pass + # L鍚庡泭鎷揩鐓� + try: + __start_time = time.time() + 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 + use_time = time.time() - __start_time + if use_time > 0.05: + async_log_util.info(logger_debug, f"缁熻瀹炴挙鐢ㄦ椂锛歿code} - {use_time}") + except Exception as e: + logger_debug.exception(e) + fdatas.append(fdata) + except Exception as e: + logger_debug.exception(e) + finally: + use_time = time.time() - _start_time + if use_time > 0.1: + async_log_util.info(logger_debug, f"濮旀墭淇℃伅缁熻鑰楁椂锛歿c['securityID']}-{use_time}") result = {"code": 0, "data": {"account_available_money": account_available_money, "delegates": fdatas}} self.send_response(result, client_id, request_id) elif ctype == "set_real_place_order_index": @@ -1416,7 +1438,9 @@ "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, - "can_auto_add_white": 1 if constant.CAN_AUTO_ADD_WHITE else 0 + "can_auto_add_white": 1 if constant.CAN_AUTO_ADD_WHITE else 0, + "can_auto_add_want_buy_codes": 1 if constant.CAN_AUTO_ADD_WANT_BUY_CODES else 0, + "can_auto_l_down_rate_change": 1 if constant.CAN_AUTO_L_DOWN_RATE_CHANGE else 0 }} self.send_response({"code": 0, "data": data, "msg": f""}, client_id, @@ -1443,6 +1467,15 @@ if radical_buy.get('can_auto_add_white') is not None: constant.CAN_AUTO_ADD_WHITE = True if radical_buy.get( 'can_auto_add_white') else False + if radical_buy.get('can_auto_add_want_buy_codes') is not None: + constant.CAN_AUTO_ADD_WANT_BUY_CODES = True if radical_buy.get( + 'can_auto_add_want_buy_codes') else False + + if radical_buy.get('can_auto_l_down_rate_change') is not None: + constant.CAN_AUTO_L_DOWN_RATE_CHANGE = True if radical_buy.get( + 'can_auto_l_down_rate_change') else False + + self.send_response({"code": 0, "data": {}, "msg": f""}, client_id, @@ -1542,15 +1575,22 @@ request_id) return rate = round(rate, 2) - old_rate = LCancelRateManager().get_cancel_rate(0)[0] - # L鍚庢暟鎹揩鐓� - last_info = LCancelBigNumComputer().statistic_l_down_watch_indexes_info(code) - LDownCancelWatchIndexStatisticManager().set_statistic_info(code, last_info) + old_rate = LCancelRateManager().get_cancel_rate(code)[0] CancelRateHumanSettingManager().set_l_down(code, rate) # L鍚庨噸鏂板泭鎷� - if rate < old_rate: - # 鏀瑰皬鎵嶈兘閲嶆柊鍥婃嫭 - LCancelBigNumComputer().re_compute_l_down_watch_indexes(code) + # if rate < old_rate: + # 鏀瑰皬鎵嶈兘閲嶆柊鍥婃嫭 + trade_record_log_util.add_common_msg(code, "L鍚庨噸鏂板泭鎷�", msg=f"淇敼鎾ゅ崟姣斾緥: {old_rate}->{rate}") + LCancelBigNumComputer().re_compute_l_down_watch_indexes(code, is_force=True, is_human=True) + + self.send_response({"code": 0, "data": {}}, + client_id, + request_id) + elif ctype == "remove_l_down_rate": + # 鍒犻櫎L鍚庢挙鍗曟瘮渚� + code = data.get("code") + CancelRateHumanSettingManager().remove_l_down(code) + trade_record_log_util.add_common_msg(code, "鍒犻櫎L鍚庨璁炬瘮渚�") self.send_response({"code": 0, "data": {}}, client_id, request_id) @@ -1582,10 +1622,28 @@ return CodesContinueBuyMoneyManager().set_continue_buy_money(code, money) l2_trade_util.remove_from_forbidden_trade_codes(code) + CodesTradeStateManager().set_trade_state(code, trade_constant.TRADE_STATE_NOT_TRADE) self.send_response({"code": 0, "data": {}}, client_id, request_id) - + elif ctype == "set_code_today_ex_rights": + # 浠g爜浠婃棩闄ゆ潈锛岄渶瑕佹洿鏂癒绾� + code = data.get("code") + volumes_data = history_k_data_manager.update_history_k_bars_of_code(code, force=True, juejin=True) + if not volumes_data: + result = {"code": 1, "msg": "鎷夊彇K绾垮け璐�"} + else: + # 鏇存柊鏄ㄦ棩鏀剁洏浠锋暟鎹� + CodePrePriceManager().set_price_pre(code, volumes_data[0]['close'], force=True) + gpcode_manager.clear_limit_up_price_cache(code) + limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) + # 鏇存柊K绾跨壒寰佹暟鎹� + k_format = code_nature_analyse.get_k_format(code, limit_up_price, volumes_data) + code_nature_analyse.CodeNatureRecordManager().save_k_format(code, k_format) + result = {"code": 0, "msg": "璁剧疆鎴愬姛"} + self.send_response(result, + client_id, + request_id) except Exception as e: logging.exception(e) logger_debug.exception(e) -- Gitblit v1.8.0