e2a28e6c94
Co-authored-by: Cursor <cursoragent@cursor.com>
95 lines
3.3 KiB
Python
95 lines
3.3 KiB
Python
"""条件单候选:带出交易户资金字段."""
|
|
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},
|
|
"transfer_blocked": False,
|
|
},
|
|
},
|
|
{
|
|
"id": 2,
|
|
"name": "okx-b",
|
|
"online": False,
|
|
"error": "timeout",
|
|
"snapshot": {
|
|
"positions_brief": [{"inst_id": "x"}],
|
|
"cond_order_locked": False,
|
|
"instance": {"mode": "sim"},
|
|
"funds": {},
|
|
"transfer_blocked": True,
|
|
"transfer_block_msg": "期权持仓中禁止划转",
|
|
},
|
|
},
|
|
]
|
|
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[0]["transfer_blocked"])
|
|
self.assertFalse(out[1]["selectable"])
|
|
self.assertIsNone(out[1]["trading_usdt"])
|
|
self.assertTrue(out[1]["transfer_blocked"])
|
|
self.assertEqual(out[0]["allowed_underlys"], ["ETH", "BTC"])
|
|
|
|
def test_candidates_carry_allowed_underlys(self):
|
|
from lib.cond_orders_cache_lib import _candidates_from_snaps
|
|
|
|
rows = [
|
|
{
|
|
"id": 3,
|
|
"name": "eth-only",
|
|
"online": True,
|
|
"error": "",
|
|
"snapshot": {
|
|
"positions_brief": [],
|
|
"cond_order_locked": False,
|
|
"instance": {"mode": "sim", "underly": "ETH", "allowed_underlys": ["ETH"]},
|
|
"options_allowed_underlys": ["ETH"],
|
|
"options_underly": "ETH",
|
|
"funds": {"trading_usdt": 1.0, "funding_usdt": 2.0},
|
|
},
|
|
}
|
|
]
|
|
out = _candidates_from_snaps(rows)
|
|
self.assertEqual(out[0]["allowed_underlys"], ["ETH"])
|
|
self.assertEqual(out[0]["default_underly"], "ETH")
|
|
|
|
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()
|