Parse OKX spot swap errors into friendly Chinese instead of raw JSON.
Map sCode 51008 to a clear insufficient-balance message for the currency exchange UI. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -30,6 +30,16 @@ class TestOkxSpotSwap(unittest.TestCase):
|
||||
self.assertEqual(body["tgtCcy"], "base_ccy")
|
||||
self.assertEqual(body["side"], "sell")
|
||||
|
||||
def test_insufficient_balance_returns_chinese_message(self):
|
||||
ex = MagicMock()
|
||||
ex.private_post_trade_order.side_effect = Exception(
|
||||
'okx {"code":"1","data":[{"sCode":"51008","sMsg":"Order failed. Your available USDT balance is insufficient."}]}'
|
||||
)
|
||||
result = spot_market_swap_usdt_usdc(ex, direction="usdt_to_usdc", amount=20)
|
||||
self.assertFalse(result["ok"])
|
||||
self.assertEqual(result["msg"], "资金账户 USDT 可用余额不足")
|
||||
self.assertNotIn("{", result["msg"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user