trader_client.py 860 B

12345678910111213141516171819202122232425
  1. from __future__ import annotations
  2. from typing import Any
  3. from urllib.request import urlopen
  4. import json
  5. def list_strategies(base_url: str) -> list[dict[str, Any]]:
  6. root = base_url.rstrip('/')
  7. if root.endswith('/mcp/sse'):
  8. root = root[:-8]
  9. with urlopen(f"{root}/strategies", timeout=10) as resp:
  10. payload = json.loads(resp.read().decode("utf-8"))
  11. strategies = payload.get("configured", []) or []
  12. return [s for s in strategies if isinstance(s, dict)]
  13. def list_accounts(base_url: str) -> list[dict[str, Any]]:
  14. root = base_url.rstrip('/')
  15. if root.endswith('/mcp/sse'):
  16. root = root[:-8]
  17. with urlopen(f"{root}/accounts", timeout=10) as resp:
  18. payload = json.loads(resp.read().decode("utf-8"))
  19. accounts = payload.get("accounts", []) or []
  20. return [a for a in accounts if isinstance(a, dict)]