hello_world.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. }
  11. TICK_MINUTES = 0.2
  12. CONFIG_SCHEMA = {
  13. "label": {"type": "string", "default": "hello world"},
  14. }
  15. STATE_SCHEMA = {
  16. "counter": {"type": "int", "default": 0},
  17. }
  18. def init(self):
  19. # Tiny demo state, useful for persistence smoke tests.
  20. return {"counter": 0}
  21. def on_tick(self, tick):
  22. self.state["counter"] += 1
  23. return self.state["counter"]
  24. def apply_policy(self):
  25. policy = super().apply_policy()
  26. self.state["policy_derived"] = dict(policy)
  27. return policy
  28. def report(self):
  29. snapshot = self.context.get_strategy_snapshot() if hasattr(self.context, "get_strategy_snapshot") else {}
  30. return {
  31. "identity": snapshot.get("identity", {}),
  32. "control": snapshot.get("control", {}),
  33. "fit": dict(getattr(self, "STRATEGY_PROFILE", {}) or {}),
  34. "position": snapshot.get("position", {}),
  35. "state": {
  36. "counter": self.state["counter"],
  37. "label": self.config.get("label", "hello world"),
  38. },
  39. "assessment": {
  40. "confidence": None,
  41. "uncertainty": None,
  42. "reason": "demo strategy",
  43. "warnings": [],
  44. "policy": dict(self.config.get("policy") or {}),
  45. },
  46. "execution": snapshot.get("execution", {}),
  47. }
  48. def render(self):
  49. return {
  50. "widgets": [
  51. {"type": "text", "label": "message", "value": self.config.get("label", "hello world")},
  52. {"type": "metric", "label": "ticks", "value": self.state["counter"]},
  53. ]
  54. }