fix(hub): show contract-based unrealized PnL in monitor and chart

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-04 20:20:36 +08:00
parent ef8656e95d
commit 806350231e
6 changed files with 267 additions and 63 deletions
+23 -1
View File
@@ -11,7 +11,11 @@ sys.path.insert(0, str(ROOT / "manual_trading_hub"))
from agent import _position_mark_price, _ticker_mark_price # noqa: E402
sys.path.insert(0, str(ROOT))
from hub_position_metrics import parse_position_unrealized_pnl # noqa: E402
from hub_position_metrics import ( # noqa: E402
estimate_linear_swap_upnl_usdt,
parse_position_unrealized_pnl,
resolve_position_display_upnl,
)
class TestHubAgentMarkPrice(unittest.TestCase):
@@ -48,6 +52,24 @@ class TestHubAgentMarkPrice(unittest.TestCase):
)
self.assertAlmostEqual(pnl, 6.81)
def test_estimate_short_hype_contract_size(self):
upnl = estimate_linear_swap_upnl_usdt(
"short", 73.187, 66.038, 11, 0.1
)
self.assertAlmostEqual(upnl, 7.86, places=1)
def test_resolve_prefers_computed_when_exchange_off(self):
shown = resolve_position_display_upnl(
"short", 73.187, 66.038, 11, 1.0, 7.86
)
self.assertAlmostEqual(shown, 78.64, places=1)
def test_resolve_keeps_exchange_when_aligned(self):
shown = resolve_position_display_upnl(
"short", 73.187, 66.038, 11, 0.1, 7.86
)
self.assertAlmostEqual(shown, 7.86, places=2)
if __name__ == "__main__":
unittest.main()