hello_world.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from __future__ import annotations
  2. from src.trader_mcp.strategy_sdk import Strategy
  3. class Strategy(Strategy):
  4. LABEL = "Hello World"
  5. STRATEGY_PROFILE = {
  6. "expects": {},
  7. "avoids": {},
  8. "risk_profile": "demo",
  9. "capabilities": ["demo"],
  10. "role": "companion",
  11. "inventory_behavior": "none",
  12. "requires_rebalance_before_start": False,
  13. "requires_rebalance_before_stop": False,
  14. "safe_when_unbalanced": True,
  15. "can_run_with": [],
  16. }
  17. TICK_MINUTES = 0.2
  18. CONFIG_SCHEMA = {
  19. "label": {"type": "string", "default": "hello world"},
  20. }
  21. STATE_SCHEMA = {
  22. "counter": {"type": "int", "default": 0},
  23. }
  24. def init(self):
  25. # Tiny demo state, useful for persistence smoke tests.
  26. return {"counter": 0}
  27. def on_tick(self, tick):
  28. self.state["counter"] += 1
  29. return self.state["counter"]
  30. def apply_policy(self):
  31. policy = super().apply_policy()
  32. self.state["policy_derived"] = dict(policy)
  33. return policy
  34. def report(self):
  35. snapshot = self.context.get_strategy_snapshot() if hasattr(self.context, "get_strategy_snapshot") else {}
  36. return {
  37. "identity": snapshot.get("identity", {}),
  38. "control": snapshot.get("control", {}),
  39. "fit": dict(getattr(self, "STRATEGY_PROFILE", {}) or {}),
  40. "position": snapshot.get("position", {}),
  41. "state": {
  42. "counter": self.state["counter"],
  43. "label": self.config.get("label", "hello world"),
  44. },
  45. "assessment": {
  46. "confidence": None,
  47. "uncertainty": None,
  48. "reason": "demo strategy",
  49. "warnings": [],
  50. "policy": dict(self.config.get("policy") or {}),
  51. },
  52. "execution": snapshot.get("execution", {}),
  53. }
  54. def render(self):
  55. return {
  56. "widgets": [
  57. {"type": "text", "label": "message", "value": self.config.get("label", "hello world")},
  58. {"type": "metric", "label": "ticks", "value": self.state["counter"]},
  59. ]
  60. }