22
22
23
23
class StrategyParameter (BaseModel ):
24
24
name : str
25
+ group : str
26
+ is_advanced : bool = False
25
27
type : str
26
28
prompt : str
27
29
default : Optional [Any ]
@@ -38,13 +40,35 @@ class StrategyParameter(BaseModel):
38
40
display_type : str = Field (default = "input" , description = "Can be 'input', 'slider', 'dropdown', 'toggle', or 'date'" )
39
41
40
42
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
+
41
64
def convert_to_strategy_parameter (name : str , field : ModelField ) -> StrategyParameter :
42
65
param = StrategyParameter (
43
66
name = name ,
44
67
type = str (field .type_ .__name__ ),
45
68
prompt = field .description if hasattr (field , 'description' ) else "" ,
46
69
default = field .default ,
47
70
required = field .required or field .default is not None ,
71
+ is_advanced = is_advanced_parameter (name ),
48
72
)
49
73
50
74
# structure of field
@@ -69,6 +93,9 @@ def convert_to_strategy_parameter(name: str, field: ModelField) -> StrategyParam
69
93
elif param .type == "bool" :
70
94
param .display_type = "toggle"
71
95
96
+ # Determine the group for the parameter
97
+ param .group = determine_parameter_group (name )
98
+
72
99
# Check for specific use cases
73
100
if "connector" in name .lower ():
74
101
param .is_connector = True
@@ -98,6 +125,28 @@ def convert_to_strategy_parameter(name: str, field: ModelField) -> StrategyParam
98
125
pass
99
126
return param
100
127
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
+
101
150
102
151
@functools .lru_cache (maxsize = 1 )
103
152
def get_all_strategy_maps () -> Dict [str , Dict [str , StrategyParameter ]]:
@@ -135,4 +184,4 @@ def get_all_strategy_maps() -> Dict[str, Dict[str, StrategyParameter]]:
135
184
print (f"Unexpected error processing { module_path } : { e } " )
136
185
import traceback
137
186
traceback .print_exc ()
138
- return strategy_maps
187
+ return strategy_maps
0 commit comments