diff --git a/backend/app/sim/matcher.py b/backend/app/sim/matcher.py index 143f0ed..a021cd0 100644 --- a/backend/app/sim/matcher.py +++ b/backend/app/sim/matcher.py @@ -213,8 +213,8 @@ class Matcher: detail="opened", data={ "group_id": group_id, - "perp": pf.__dict__, - "option": of.__dict__, + "perp": pf.to_dict(), + "option": of.to_dict(), "initial_premium": initial_premium, "fees": pf.fee + of.fee, }, diff --git a/backend/app/sim/pricing.py b/backend/app/sim/pricing.py index cb607db..854bf5e 100644 --- a/backend/app/sim/pricing.py +++ b/backend/app/sim/pricing.py @@ -2,7 +2,7 @@ from __future__ import annotations -from dataclasses import dataclass +from dataclasses import asdict, dataclass @dataclass(slots=True) @@ -13,6 +13,9 @@ class PriceResult: slip: float notional: float + def to_dict(self) -> dict[str, float]: + return asdict(self) + def perp_fill( *, diff --git a/backend/app/strategy/engine.py b/backend/app/strategy/engine.py index 2b166cc..7e994da 100644 --- a/backend/app/strategy/engine.py +++ b/backend/app/strategy/engine.py @@ -82,7 +82,15 @@ class StrategyEngine: r = self.matcher.close_group(reason="emergency") if r.ok: self._after_close() - return {"close": r.__dict__, "state": self.state()} + return { + "close": { + "ok": r.ok, + "detail": r.detail, + "liquidity_wait": r.liquidity_wait, + "data": r.data, + }, + "state": self.state(), + } def _after_close(self) -> None: s = get_settings() @@ -147,7 +155,7 @@ class StrategyEngine: # 有仓:盯平仓 if pos.get("status") == "open": - self._set_state(phase="open") + self._set_state(phase="open", last_error=None) upl = self.matcher.unrealized() decision = check_exits( perp_upl=float(upl["perp_upl"]),