2222
2323class StrategyParameter (BaseModel ):
2424 name : str
25+ group : str
26+ is_advanced : bool = False
2527 type : str
2628 prompt : str
2729 default : Optional [Any ]
@@ -38,13 +40,35 @@ class StrategyParameter(BaseModel):
3840 display_type : str = Field (default = "input" , description = "Can be 'input', 'slider', 'dropdown', 'toggle', or 'date'" )
3941
4042
43+ def is_advanced_parameter (name : str ) -> bool :
44+ advanced_keywords = [
45+ "activation_bounds" , "triple_barrier" , "leverage" , "dca" , "macd" , "natr" ,
46+ "multiplier" , "imbalance" , "executor" , "perp" , "arbitrage"
47+ ]
48+
49+ simple_keywords = [
50+ "controller_name" , "candles" , "interval" , "stop_loss" , "take_profit" ,
51+ "buy" , "sell" , "position_size" , "time_limit" , "spot"
52+ ]
53+
54+ name_lower = name .lower ()
55+
56+ if any (keyword in name_lower for keyword in advanced_keywords ):
57+ return True
58+
59+ if any (keyword in name_lower for keyword in simple_keywords ):
60+ return False
61+
62+ return True
63+
4164def convert_to_strategy_parameter (name : str , field : ModelField ) -> StrategyParameter :
4265 param = StrategyParameter (
4366 name = name ,
4467 type = str (field .type_ .__name__ ),
4568 prompt = field .description if hasattr (field , 'description' ) else "" ,
4669 default = field .default ,
4770 required = field .required or field .default is not None ,
71+ is_advanced = is_advanced_parameter (name ),
4872 )
4973
5074 # structure of field
@@ -69,6 +93,9 @@ def convert_to_strategy_parameter(name: str, field: ModelField) -> StrategyParam
6993 elif param .type == "bool" :
7094 param .display_type = "toggle"
7195
96+ # Determine the group for the parameter
97+ param .group = determine_parameter_group (name )
98+
7299 # Check for specific use cases
73100 if "connector" in name .lower ():
74101 param .is_connector = True
@@ -98,6 +125,28 @@ def convert_to_strategy_parameter(name: str, field: ModelField) -> StrategyParam
98125 pass
99126 return param
100127
128+ def determine_parameter_group (name : str ) -> str :
129+ if any (word in name .lower () for word in ["controller_name" , "candles" , "interval" ]):
130+ return "General Settings"
131+ elif any (word in name .lower () for word in ["stop_loss" , "trailing_stop" , "take_profit" , "activation_bounds" , "leverage" , "triple_barrier" ]):
132+ return "Risk Management"
133+ elif "buy" in name .lower ():
134+ return "Buy Order Settings"
135+ elif "sell" in name .lower ():
136+ return "Sell Order Settings"
137+ elif "dca" in name .lower ():
138+ return "DCA Settings"
139+ elif any (word in name .lower () for word in ["bb" , "macd" , "natr" , "length" , "multiplier" ]):
140+ return "Indicator Settings"
141+ elif any (word in name .lower () for word in ["profitability" , "position_size" ]):
142+ return "Profitability Settings"
143+ elif any (word in name .lower () for word in ["time_limit" , "executor" , "imbalance" ]):
144+ return "Execution Settings"
145+ elif any (word in name .lower () for word in ["spot" , "perp" ]):
146+ return "Arbitrage Settings"
147+ else :
148+ return "Other"
149+
101150
102151@functools .lru_cache (maxsize = 1 )
103152def get_all_strategy_maps () -> Dict [str , Dict [str , StrategyParameter ]]:
@@ -135,4 +184,4 @@ def get_all_strategy_maps() -> Dict[str, Dict[str, StrategyParameter]]:
135184 print (f"Unexpected error processing { module_path } : { e } " )
136185 import traceback
137186 traceback .print_exc ()
138- return strategy_maps
187+ return strategy_maps
0 commit comments