Skip to content

Added param group and advanced status #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion routers/strategies_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

class StrategyParameter(BaseModel):
name: str
group: str
is_advanced: bool = False
type: str
prompt: str
default: Optional[Any]
Expand All @@ -38,13 +40,35 @@ class StrategyParameter(BaseModel):
display_type: str = Field(default="input", description="Can be 'input', 'slider', 'dropdown', 'toggle', or 'date'")


def is_advanced_parameter(name: str) -> bool:
advanced_keywords = [
"activation_bounds", "triple_barrier", "leverage", "dca", "macd", "natr",
"multiplier", "imbalance", "executor", "perp", "arbitrage"
]

simple_keywords = [
"controller_name", "candles", "interval", "stop_loss", "take_profit",
"buy", "sell", "position_size", "time_limit", "spot"
]

name_lower = name.lower()

if any(keyword in name_lower for keyword in advanced_keywords):
return True

if any(keyword in name_lower for keyword in simple_keywords):
return False

return True

def convert_to_strategy_parameter(name: str, field: ModelField) -> StrategyParameter:
param = StrategyParameter(
name=name,
type=str(field.type_.__name__),
prompt=field.description if hasattr(field, 'description') else "",
default=field.default,
required=field.required or field.default is not None,
is_advanced=is_advanced_parameter(name),
)

# structure of field
Expand All @@ -69,6 +93,9 @@ def convert_to_strategy_parameter(name: str, field: ModelField) -> StrategyParam
elif param.type == "bool":
param.display_type = "toggle"

# Determine the group for the parameter
param.group = determine_parameter_group(name)

# Check for specific use cases
if "connector" in name.lower():
param.is_connector = True
Expand All @@ -92,6 +119,28 @@ def convert_to_strategy_parameter(name: str, field: ModelField) -> StrategyParam
pass
return param

def determine_parameter_group(name: str) -> str:
if any(word in name.lower() for word in ["controller_name", "candles", "interval"]):
return "General Settings"
elif any(word in name.lower() for word in ["stop_loss", "trailing_stop", "take_profit", "activation_bounds", "leverage", "triple_barrier"]):
return "Risk Management"
elif "buy" in name.lower():
return "Buy Order Settings"
elif "sell" in name.lower():
return "Sell Order Settings"
elif "dca" in name.lower():
return "DCA Settings"
elif any(word in name.lower() for word in ["bb", "macd", "natr", "length", "multiplier"]):
return "Indicator Settings"
elif any(word in name.lower() for word in ["profitability", "position_size"]):
return "Profitability Settings"
elif any(word in name.lower() for word in ["time_limit", "executor", "imbalance"]):
return "Execution Settings"
elif any(word in name.lower() for word in ["spot", "perp"]):
return "Arbitrage Settings"
else:
return "Other"


@functools.lru_cache(maxsize=1)
def get_all_strategy_maps() -> Dict[str, Dict[str, StrategyParameter]]:
Expand Down Expand Up @@ -129,4 +178,4 @@ def get_all_strategy_maps() -> Dict[str, Dict[str, StrategyParameter]]:
print(f"Unexpected error processing {module_path}: {e}")
import traceback
traceback.print_exc()
return strategy_maps
return strategy_maps
Loading