Fix OKX spot swap tgtCcy and show options trading USDT in header.
OKX requires quote_ccy/base_ccy for market orders; include trading_usdt in balance display and total funds. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
import unittest
|
||||
|
||||
from lib.instance.instance_embed_context_lib import (
|
||||
options_funding_label,
|
||||
profit_loss_ratio_from_averages,
|
||||
profit_loss_ratio_from_trades,
|
||||
total_funds_usdt,
|
||||
@@ -27,6 +28,15 @@ class TestHeaderStatsLib(unittest.TestCase):
|
||||
def test_total_funds_usdt(self):
|
||||
self.assertEqual(total_funds_usdt(100.5, 59.27), 159.77)
|
||||
self.assertIsNone(total_funds_usdt(None, 10))
|
||||
self.assertEqual(
|
||||
total_funds_usdt(100, 50, options_trading_usdc=0.2, options_trading_usdt=10),
|
||||
160.2,
|
||||
)
|
||||
|
||||
def test_options_funding_label(self):
|
||||
self.assertEqual(options_funding_label(1.5, 10), "1.50 USDC · 10.00 USDT")
|
||||
self.assertEqual(options_funding_label(None, 10), "10.00 USDT")
|
||||
self.assertEqual(options_funding_label(None, None), "—")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
"""OKX USDT/USDC 现货市价兑换参数."""
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from lib.exchange.okx_options_lib import spot_market_swap_usdt_usdc
|
||||
|
||||
|
||||
class TestOkxSpotSwap(unittest.TestCase):
|
||||
def test_usdt_to_usdc_uses_quote_ccy(self):
|
||||
ex = MagicMock()
|
||||
ex.private_post_trade_order.return_value = {
|
||||
"data": [{"sCode": "0", "ordId": "1"}],
|
||||
}
|
||||
result = spot_market_swap_usdt_usdc(ex, direction="usdt_to_usdc", amount=10)
|
||||
self.assertTrue(result["ok"])
|
||||
body = ex.private_post_trade_order.call_args[0][0]
|
||||
self.assertEqual(body["tgtCcy"], "quote_ccy")
|
||||
self.assertEqual(body["side"], "buy")
|
||||
|
||||
def test_usdc_to_usdt_uses_base_ccy(self):
|
||||
ex = MagicMock()
|
||||
ex.private_post_trade_order.return_value = {
|
||||
"data": [{"sCode": "0", "ordId": "2"}],
|
||||
}
|
||||
result = spot_market_swap_usdt_usdc(ex, direction="usdc_to_usdt", amount=5)
|
||||
self.assertTrue(result["ok"])
|
||||
body = ex.private_post_trade_order.call_args[0][0]
|
||||
self.assertEqual(body["tgtCcy"], "base_ccy")
|
||||
self.assertEqual(body["side"], "sell")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user