c4c8ad172a
Match hedge/roll/trend/order/key monitors for source badges, show option target monitors in green, and refresh the dashboard with the board 5s cycle. Co-authored-by: Cursor <cursoragent@cursor.com>
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
"""hub /api/hub/monitor:enrich 局部返回时须保留 keys."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from lib.hub.hub_bridge import build_hub_monitor_payload # noqa: E402
|
|
|
|
|
|
class TestHubMonitorPayload(unittest.TestCase):
|
|
def test_partial_enrich_keeps_keys(self):
|
|
keys = [{"id": 7, "symbol": "BTC/USDT"}]
|
|
orders = [{"id": 1}]
|
|
trends = [{"id": 9, "symbol": "ETH/USDT"}]
|
|
rolls = []
|
|
|
|
def enrich_only_trends(**_kw):
|
|
return {"trends": [{"id": 9, "add_count": 2}]}
|
|
|
|
out = build_hub_monitor_payload(
|
|
keys=keys,
|
|
orders=orders,
|
|
trends=trends,
|
|
rolls=rolls,
|
|
enrich=enrich_only_trends,
|
|
)
|
|
self.assertTrue(out["ok"])
|
|
self.assertEqual(out["keys"], keys)
|
|
self.assertEqual(out["orders"], orders)
|
|
self.assertEqual(out["rolls"], rolls)
|
|
self.assertEqual(out["hedges"], [])
|
|
self.assertEqual(out["trends"][0]["add_count"], 2)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|