Skip to content
Open
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
13 changes: 11 additions & 2 deletions hummingbot_mcp/formatters/bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from .base import (
format_number,
format_percentage,
format_table_separator,
format_time_only,
get_field,
Expand Down Expand Up @@ -48,6 +47,16 @@ def format_bot_logs_as_table(logs: list[dict[str, Any]]) -> str:
return f"{header}\n{separator}\n" + "\n".join(rows)


def _format_percent_value(pct: Any) -> str:
if pct is None or pct == "N/A":
return "N/A"

try:
return f"{float(pct):.2f}%"
except (TypeError, ValueError):
return str(pct)


def format_active_bots_as_table(bots_data: dict[str, Any]) -> str:
"""
Format active bots data as a table string for better LLM processing.
Expand Down Expand Up @@ -100,7 +109,7 @@ def format_active_bots_as_table(bots_data: dict[str, Any]) -> str:
realized_pnl = format_number(get_field(ctrl_perf, "realized_pnl_quote", default=None), compact=False)
unrealized_pnl = format_number(get_field(ctrl_perf, "unrealized_pnl_quote", default=None), compact=False)
global_pnl = format_number(get_field(ctrl_perf, "global_pnl_quote", default=None), compact=False)
global_pnl_pct = format_percentage(get_field(ctrl_perf, "global_pnl_pct", default=None))
global_pnl_pct = _format_percent_value(get_field(ctrl_perf, "global_pnl_pct", default=None))
volume = format_number(get_field(ctrl_perf, "volume_traded", default=None), compact=False)

row = (
Expand Down