| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- from __future__ import annotations
- from src.trader_mcp.strategy_sdk import Strategy
- class Strategy(Strategy):
- LABEL = "Hello World"
- STRATEGY_PROFILE = {
- "expects": {},
- "avoids": {},
- "risk_profile": "demo",
- "capabilities": ["demo"],
- }
- TICK_MINUTES = 0.2
- CONFIG_SCHEMA = {
- "label": {"type": "string", "default": "hello world"},
- }
- STATE_SCHEMA = {
- "counter": {"type": "int", "default": 0},
- }
- def init(self):
- # Tiny demo state, useful for persistence smoke tests.
- return {"counter": 0}
- def on_tick(self, tick):
- self.state["counter"] += 1
- return self.state["counter"]
- def apply_policy(self):
- policy = super().apply_policy()
- self.state["policy_derived"] = dict(policy)
- return policy
- def report(self):
- snapshot = self.context.get_strategy_snapshot() if hasattr(self.context, "get_strategy_snapshot") else {}
- return {
- "identity": snapshot.get("identity", {}),
- "control": snapshot.get("control", {}),
- "fit": dict(getattr(self, "STRATEGY_PROFILE", {}) or {}),
- "position": snapshot.get("position", {}),
- "state": {
- "counter": self.state["counter"],
- "label": self.config.get("label", "hello world"),
- },
- "assessment": {
- "confidence": None,
- "uncertainty": None,
- "reason": "demo strategy",
- "warnings": [],
- "policy": dict(self.config.get("policy") or {}),
- },
- "execution": snapshot.get("execution", {}),
- }
- def render(self):
- return {
- "widgets": [
- {"type": "text", "label": "message", "value": self.config.get("label", "hello world")},
- {"type": "metric", "label": "ticks", "value": self.state["counter"]},
- ]
- }
|