feat条件单候选展示交易户资金,并支持打开实例划转。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
"""条件单候选:带出交易户资金字段."""
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
class TestCondCandidatesFunds(unittest.TestCase):
|
||||
def test_candidates_include_trading_usdt(self):
|
||||
from lib.cond_orders_cache_lib import _candidates_from_snaps
|
||||
|
||||
rows = [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "okx-a",
|
||||
"online": True,
|
||||
"error": "",
|
||||
"snapshot": {
|
||||
"positions_brief": [],
|
||||
"cond_order_locked": False,
|
||||
"instance": {"mode": "live"},
|
||||
"funds": {"trading_usdt": 123.456, "funding_usdt": 50.0},
|
||||
},
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "okx-b",
|
||||
"online": False,
|
||||
"error": "timeout",
|
||||
"snapshot": {
|
||||
"positions_brief": [{"inst_id": "x"}],
|
||||
"cond_order_locked": False,
|
||||
"instance": {"mode": "sim"},
|
||||
"funds": {},
|
||||
},
|
||||
},
|
||||
]
|
||||
out = _candidates_from_snaps(rows)
|
||||
self.assertEqual(len(out), 2)
|
||||
self.assertTrue(out[0]["selectable"])
|
||||
self.assertAlmostEqual(out[0]["trading_usdt"], 123.456, places=3)
|
||||
self.assertAlmostEqual(out[0]["funding_usdt"], 50.0, places=3)
|
||||
self.assertFalse(out[1]["selectable"])
|
||||
self.assertIsNone(out[1]["trading_usdt"])
|
||||
|
||||
def test_open_url_tab_appended(self):
|
||||
from lib.sso_lib import build_embed_open_url
|
||||
|
||||
url = build_embed_open_url(
|
||||
"https://okx.example.com",
|
||||
bridge_token="tok",
|
||||
embed_path="/embed",
|
||||
tab="options",
|
||||
)
|
||||
self.assertIn("hub_sso?", url)
|
||||
self.assertIn("next=", url)
|
||||
# next 已 urlencode,解码后应含 tab=options
|
||||
from urllib.parse import parse_qs, unquote, urlparse
|
||||
|
||||
q = parse_qs(urlparse(url).query)
|
||||
next_path = unquote(q.get("next", [""])[0])
|
||||
self.assertIn("tab=options", next_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user