From 0e642d0c27e40df326733401be6f8c8115e54911 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期三, 23 七月 2025 17:01:25 +0800 Subject: [PATCH] L后默认撤单率修改/启用F撤 --- api/outside_api_command_callback.py | 501 ++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 331 insertions(+), 170 deletions(-) diff --git a/api/outside_api_command_callback.py b/api/outside_api_command_callback.py index 4c11619..2947365 100644 --- a/api/outside_api_command_callback.py +++ b/api/outside_api_command_callback.py @@ -1,3 +1,4 @@ +import base64 import concurrent.futures import copy import json @@ -13,11 +14,13 @@ 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, \ + 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 -from code_attribute.gpcode_manager import CodePrePriceManager, CodesNameManager, WantBuyCodesManager +from code_attribute.gpcode_manager import CodePrePriceManager, CodesNameManager, WantBuyCodesManager, \ + 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 @@ -26,7 +29,7 @@ l2_data_source_util, cancel_buy_strategy from l2.code_price_manager import Buy1PriceManager -from l2.l2_data_manager import TradePointManager +from l2.l2_data_manager import TradePointManager, OrderBeginPosInfo from l2.l2_data_util import L2DataUtil from l2.l2_transaction_data_manager import HuaXinBuyOrderManager, BigOrderDealManager from log_module import async_log_util, log_export @@ -34,27 +37,33 @@ 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.code_plate_key_manager import CodePlateKeyBuyManager, KPLCodeJXBlockManager, RealTimeKplMarketData, \ - RadicalBuyBlockManager +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 +from third_data.kpl_data_constant import LimitUpDataConstant 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 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 +from trade.buy_money_count_setting import BuyMoneyAndCountSetting, RadicalBuyBlockCodeCountManager +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 from trade.huaxin.huaxin_trade_record_manager import PositionManager, DealRecordManager, DelegateRecordManager +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_manager import TradeTargetCodeModeManager, AutoCancelSellModeManager +from trade.trade_data_manager import RadicalBuyDealCodesManager +from trade.trade_manager import TradeTargetCodeModeManager, AutoCancelSellModeManager, CodesContinueBuyMoneyManager, \ + CodesTradeStateManager 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 @@ -92,7 +101,7 @@ def __cancel_not_deal_order(self, code, order_ref, timeout=3): time.sleep(timeout) # 鎾や拱鍗� - huaxin_trade_api.cancel_order(1, code, "", orderRef=order_ref) + huaxin_trade_api.cancel_order(huaxin_trade_api.TRADE_DIRECTION_BUY, code, "", orderRef=order_ref) # 浜ゆ槗 def OnTrade(self, client_id, request_id, data): @@ -281,18 +290,25 @@ 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: + trade_record_log_util.add_want_buy(code) gpcode_manager.WantBuyCodesManager().add_code(code) - # 鍔犳兂涔板崟瑕佷粠榛戝悕鍗曠Щ闄� - l2_trade_util.remove_from_forbidden_trade_codes(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() @@ -309,8 +325,10 @@ cancel_type=trade_constant.CANCEL_TYPE_HUMAN) except Exception as e: logger_debug.exception(e) - l2_trade_util.forbidden_trade(code, msg="鎵嬪姩鍔犲叆 trade_server") + 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]) @@ -318,7 +336,8 @@ gpcode_manager.CodesNameManager.add_first_code_name(code, results[code]) elif operate == outside_api_command_manager.OPERRATE_DELETE: l2_trade_util.remove_from_forbidden_trade_codes(code) - WantBuyCodesManager().add_code(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 = [] @@ -328,14 +347,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 = [] @@ -364,6 +383,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]) @@ -381,6 +401,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]) @@ -388,6 +415,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.WhiteListCodeManager().remove_code(code) elif operate == outside_api_command_manager.OPERRATE_GET: codes = gpcode_manager.GreenListCodeManager().list_codes_cache() datas = [] @@ -441,7 +469,8 @@ 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) + green = gpcode_manager.GreenListCodeManager().is_in_cache(code) desc_list = [] if want: desc_list.append("銆愭兂涔板崟銆�") @@ -451,6 +480,11 @@ desc_list.append("銆愰粦鍚嶅崟銆�") if pause_buy: desc_list.append("銆愭殏涓嶄拱銆�") + if must_buy: + desc_list.append("銆愮孩鍚嶅崟銆�") + if green: + 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: @@ -469,7 +503,8 @@ try: fdata = {} try: - date = JueJinApi.get_previous_trading_date(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: @@ -526,17 +561,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("娌℃湁鑾峰彇鍒颁笂涓�涓氦鏄撴棩鐨勬棩鏈�") + latest_trading_date = history_k_data_util.get_k_bar_dead_date() codes = HistoryKDataManager().get_history_bars_codes(latest_trading_date) count = len(codes) fdata["today_history_k_bar_count"] = count except Exception as e: - logger_debug.exception(e) fdata["today_history_k_bar_count"] = -1 # 鑾峰彇鏁版嵁鏈嶅姟鍣ㄦ槸鍚﹁仈閫� @@ -858,40 +887,33 @@ [huaxin_util.TORA_TSTP_OST_Accepted, huaxin_util.TORA_TSTP_OST_PartTraded]) 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) if order_begin_pos is None or order_begin_pos.buy_single_index is None: - continue + 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) - # 璁$畻淇″彿浣嶇疆鍒扮湡瀹炰笅鍗曚綅缃殑鎬讳拱锛堜笉绠℃槸鍚﹀凡鎾わ級 - 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"] + if place_order_index is None: + place_order_index = 0 + # 鑾峰彇鍓╀笅鐨勭瑪鏁� total_left_count = 0 total_left_num = 0 @@ -916,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 = 0 - # 鑾峰彇宸茬粡鎴愪氦鐨勫ぇ鍗曟暟閲� - 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"] - + buy1_money = 1 real_place_order_after_count = 0 real_place_order_after_num = 0 is_ge_code = tool.is_ge_code(code) @@ -1001,77 +964,42 @@ real_place_order_after_count += 1 real_place_order_after_num += val["num"] - # 鑾峰彇褰撴棩鐨勯噺姣� - volume_rate = code_volumn_manager.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) + 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) - # 缁熻鐪熷疄涓嬪崟浣嶆槸鍚﹁窛绂诲ぇ鍗曚綅缃繃杩� - - 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 - 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": float(gpcode_manager.get_limit_up_price(code)), - "is_near_big_order": is_near_big_order, + "limit_up_price": limit_up_price, "block": '', - "trade_queue": [] + "trade_queue": [], + "l_down_cancel_rate": l_down_cancel_rate, + "l_down_cancel_rate_info": cancel_rate_info, } limit_up_data = kpl_data_manager.KPLLimitUpDataRecordManager.record_code_dict.get(code) # 鑾峰彇褰撳墠鏉垮潡 try: - 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]})" + 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 # 鑾峰彇娑ㄥ仠鏃堕棿 @@ -1092,7 +1020,14 @@ fdata['zyltgb'] = output_util.money_desc(zyltgb) except: pass - + # L鍚庡泭鎷揩鐓� + try: + 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 Exception as e: + logger_debug.exception(e) fdatas.append(fdata) except Exception as e: logger_debug.exception(e) @@ -1161,8 +1096,8 @@ elif ctype == "set_per_code_buy_money": # 璁剧疆鍗曞彧绁ㄧ殑涔板叆閲戦 money = data["money"] - if money > 30000: - raise Exception("鏈�澶氬彧鑳借缃�3w") + if money > 50000: + raise Exception("鏈�澶氬彧鑳借缃�5w") constant.BUY_MONEY_PER_CODE = money self.send_response({"code": 0, "data": {"money": constant.BUY_MONEY_PER_CODE}}, client_id, request_id) elif ctype == "get_per_code_buy_money": @@ -1172,6 +1107,8 @@ kpl_data_manager.PullTask.repaire_pull_task() # 淇鏁版嵁鏈嶅姟 server_util.repaire_data_server() + # 浠诲姟淇 + huaxin_trade_data_update.repaire_task() self.send_response({"code": 0, "data": {}}, client_id, request_id) elif ctype == "get_trade_queue": code = data["code"] @@ -1185,9 +1122,16 @@ # 鑾峰彇澶у崟鎴愪氦鍒楄〃 code = data["code"] data_list = BigOrderDealManager().get_total_buy_money_list(code) - bigger_money = l2_data_util_old.get_big_money_val(float(gpcode_manager.get_limit_up_price(code)), + bigger_money = l2_data_util_old.get_big_money_val(gpcode_manager.get_limit_up_price_as_num(code), tool.is_ge_code(code)) fdatas = [] + # 鍔犺浇璁㈤槄涔嬪墠鐨勫ぇ鍗� + pre_deals = BeforeSubDealBigOrderManager().get_deal_big_order_money_list(code) + if pre_deals: + for d in pre_deals: + if d[0] < bigger_money: + continue + fdatas.append(d[0]) for d in data_list: if d < bigger_money: continue @@ -1233,19 +1177,37 @@ 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) + kpl_blocks = set() 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) + + 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)] + "match_blocks": [list(filter_blocks), list(match_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]) @@ -1259,6 +1221,10 @@ # 璁剧疆涔板叆閲戦鍜屾暟閲� normal = data["normal"] radical = data["radical"] + default_buy_money = data["default_buy_money"] + if int(default_buy_money) not in constant.AVAILABLE_BUY_MONEYS: + raise Exception("榛樿閲戦涓嶅湪棰勮閲戦鍐�") + constant.BUY_MONEY_PER_CODE = default_buy_money BuyMoneyAndCountSetting().set_normal_buy_data(normal[0], json.loads(normal[1])) BuyMoneyAndCountSetting().set_radical_buy_data(radical[0], json.loads(radical[1])) data = { @@ -1273,11 +1239,206 @@ data = { "normal": BuyMoneyAndCountSetting().get_normal_buy_setting(), "radical": BuyMoneyAndCountSetting().get_radical_buy_setting(), - "moneys":constant.AVAILABLE_BUY_MONEYS + "moneys": constant.AVAILABLE_BUY_MONEYS, + "default_buy_money": constant.BUY_MONEY_PER_CODE } self.send_response({"code": 0, "data": data, "msg": f""}, client_id, request_id) + elif ctype == "set_radical_buy_block_count_setting": + # 璁剧疆涔板叆閲戦鍜屾暟閲� + data_str = data["data"] + data_str = base64.b64decode(data_str).decode('utf-8') + setting = json.loads(data_str) + RadicalBuyBlockCodeCountManager().set_block_code_count(setting) + self.send_response({"code": 0, "data": setting, "msg": f""}, + client_id, + request_id) + elif ctype == "get_radical_buy_block_count_setting": + # 璁剧疆涔板叆閲戦鍜屾暟閲� + data = RadicalBuyBlockCodeCountManager().get_block_code_count_settings() + self.send_response({"code": 0, "data": data, "msg": f""}, + client_id, + request_id) + elif ctype == "get_place_order_settings": + # 鑾峰彇涔板叆涓嬪崟璁剧疆 + 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, + "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 + }} + self.send_response({"code": 0, "data": data, "msg": f""}, + client_id, + request_id) + elif ctype == "set_place_order_settings": + radical_buy = data.get("radical_buy") + if radical_buy: + radical_buy = json.loads(radical_buy) + constant.MIN_CODE_RADICAL_BUY_PRICE = radical_buy["price"][0] + 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") + 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 + 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 + + self.send_response({"code": 0, "data": {}, "msg": f""}, + client_id, + request_id) + elif ctype == "get_buy_open_limit_up_codes": + # 鑾峰彇闅斿鍗曟帓1鐨勪唬鐮� + codes = gpcode_manager.BuyOpenLimitUpCodeManager().get_codes() + if not codes: + codes = set() + self.send_response({"code": 0, "data": list(codes), "msg": f""}, + client_id, + request_id) + + elif ctype == "set_buy_open_limit_up_codes": + # 璁剧疆闅斿鍗曟帓1鐨勪唬鐮� + codes = data.get("codes") + codes = json.loads(codes) + gpcode_manager.BuyOpenLimitUpCodeManager().set_codes(set(codes)) + self.send_response({"code": 0, "data": list(codes), "msg": f""}, + client_id, + request_id) + + elif ctype == "async_radical_buy_special_codes": + # 鍚屾鎵叆涔扮殑杈ㄨ瘑搴︿唬鐮� + count = block_special_codes_manager.update_block_special_codes() + self.send_response({"code": 0, "msg": f"鏇存柊鎴愬姛鏁伴噺锛歿count}"}, + client_id, + request_id) + + elif ctype == "get_same_block_limit_up_codes_count": + # 鑾峰彇鐩稿悓鏉垮潡鐨勬定鍋滀唬鐮佹暟閲� + codes = data.get("codes") + codes = json.loads(codes) + block_codes = {} + for code in codes: + # 鑾峰彇鏉垮潡 + fblocks, before_fblocks = RadicalBuyBlockManager.get_code_blocks(code) + # 鑾峰彇鏉垮潡鍘嗗彶娑ㄥ仠 + for b in fblocks: + codes = LimitUpDataConstant.get_history_limit_up_block_codes(b) + if codes: + if code not in block_codes: + block_codes[code] = {} + block_codes[code][b] = len(codes) + self.send_response({"code": 0, "data": block_codes}, + 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) + + 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: + # 鏀瑰皬鎵嶈兘閲嶆柊鍥婃嫭 + 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) + + 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) + CodesTradeStateManager().set_trade_state(code, trade_constant.TRADE_STATE_NOT_TRADE) + self.send_response({"code": 0, "data": {}}, + client_id, + request_id) + except Exception as e: logging.exception(e) logger_debug.exception(e) -- Gitblit v1.8.0