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:
dekun
2026-07-13 08:54:53 +08:00
parent 8e492987ec
commit c4bac23c48
2 changed files with 18 additions and 10 deletions
+10
View File
@@ -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()