Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 7 additions & 5 deletions routers/connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ async def get_connector_config_map(connector_name: str, accounts_service: Accoun
Each field contains:
- type: The expected data type (e.g., "str", "SecretStr", "int")
- required: Whether the field is required
- allowed_values: List of accepted values (only for Literal fields)
- prompt: Human readable prompt from the Hummingbot config map (when defined)
"""
return accounts_service.get_connector_config_map(connector_name)


@router.get("/{connector_name}/trading-rules")
async def get_trading_rules(
request: Request,
request: Request,
connector_name: str,
trading_pairs: Optional[List[str]] = Query(default=None, description="Filter by specific trading pairs")
):
"""
Get trading rules for a connector, optionally filtered by trading pairs.

This endpoint uses the MarketDataService to access non-trading connector instances,
which means no authentication or account setup is required.

Expand All @@ -68,12 +70,12 @@ async def get_trading_rules(

# Get trading rules (filtered by trading pairs if provided)
rules = await market_data_service.get_trading_rules(connector_name, trading_pairs)

if "error" in rules:
raise HTTPException(status_code=404, detail=f"Connector '{connector_name}' not found or error: {rules['error']}")

return rules

except HTTPException:
raise
except Exception as e:
Expand Down
31 changes: 31 additions & 0 deletions services/unified_connector_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,10 +1361,41 @@ def get_connector_config_map(connector_name: str):
field_info = {"type": type_name, "required": field.is_required()}
if allowed_values is not None:
field_info["allowed_values"] = allowed_values

prompt = UnifiedConnectorService._resolve_field_prompt(
field, connector_config.hb_config
)
if prompt is not None:
field_info["prompt"] = prompt

fields_info[key] = field_info

return fields_info

@staticmethod
def _resolve_field_prompt(field, config_map) -> Optional[str]:
"""Resolve the Hummingbot prompt of a config field, if it defines one.

Prompts are stored in ``json_schema_extra`` either as a plain string or as
a callable taking the config map, so callables are evaluated here.
"""
extra = field.json_schema_extra
if not isinstance(extra, dict):
return None

prompt = extra.get("prompt")
if prompt is None:
return None

if callable(prompt):
try:
prompt = prompt(config_map)
except Exception as e:
logger.debug(f"Could not resolve prompt for config field: {e}")
return None

return str(prompt) if prompt is not None else None

# =========================================================================
# Cleanup
# =========================================================================
Expand Down
Loading