From 7e40b520a4fd7405c16519bf6454e29ec2e7ad7e Mon Sep 17 00:00:00 2001 From: "zihao.jiang" Date: Mon, 22 Dec 2025 15:04:12 +0800 Subject: [PATCH] add tradeQuoteCcy request param to the trade-related endpoints --- okx/Account.py | 8 +- test/unit/okx/test_account.py | 140 ++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 2 deletions(-) diff --git a/okx/Account.py b/okx/Account.py index a6b182e..5fddf9f 100644 --- a/okx/Account.py +++ b/okx/Account.py @@ -76,14 +76,18 @@ def set_leverage(self, lever, mgnMode, instId='', ccy='', posSide=''): return self._request_with_params(POST, SET_LEVERAGE, params) # Get Maximum Tradable Size For Instrument - def get_max_order_size(self, instId, tdMode, ccy='', px=''): + def get_max_order_size(self, instId, tdMode, ccy='', px='', tradeQuoteCcy=None): params = {'instId': instId, 'tdMode': tdMode, 'ccy': ccy, 'px': px} + if tradeQuoteCcy is not None: + params['tradeQuoteCcy'] = tradeQuoteCcy return self._request_with_params(GET, MAX_TRADE_SIZE, params) # Get Maximum Available Tradable Amount - def get_max_avail_size(self, instId, tdMode, ccy='', reduceOnly='', unSpotOffset='', quickMgnType=''): + def get_max_avail_size(self, instId, tdMode, ccy='', reduceOnly='', unSpotOffset='', quickMgnType='', tradeQuoteCcy=None): params = {'instId': instId, 'tdMode': tdMode, 'ccy': ccy, 'reduceOnly': reduceOnly, 'unSpotOffset': unSpotOffset, 'quickMgnType': quickMgnType} + if tradeQuoteCcy is not None: + params['tradeQuoteCcy'] = tradeQuoteCcy return self._request_with_params(GET, MAX_AVAIL_SIZE, params) # Increase / Decrease margin diff --git a/test/unit/okx/test_account.py b/test/unit/okx/test_account.py index 75794df..57f949d 100644 --- a/test/unit/okx/test_account.py +++ b/test/unit/okx/test_account.py @@ -552,6 +552,146 @@ def test_set_auto_earn_different_currencies(self, mock_request): self.assertEqual(call_args['ccy'], ccy) +class TestAccountAPIGetMaxOrderSize(unittest.TestCase): + """Unit tests for the get_max_order_size method""" + + def setUp(self): + """Set up test fixtures""" + self.account_api = AccountAPI( + api_key='test_key', + api_secret_key='test_secret', + passphrase='test_pass', + flag='0' + ) + + @patch.object(AccountAPI, '_request_with_params') + def test_get_max_order_size_with_required_params(self, mock_request): + """Test get_max_order_size with required parameters only""" + mock_response = {'code': '0', 'msg': '', 'data': []} + mock_request.return_value = mock_response + + result = self.account_api.get_max_order_size( + instId='BTC-USDT', + tdMode='cash' + ) + + expected_params = { + 'instId': 'BTC-USDT', + 'tdMode': 'cash', + 'ccy': '', + 'px': '' + } + mock_request.assert_called_once_with(c.GET, c.MAX_TRADE_SIZE, expected_params) + self.assertEqual(result, mock_response) + + @patch.object(AccountAPI, '_request_with_params') + def test_get_max_order_size_with_tradeQuoteCcy(self, mock_request): + """Test get_max_order_size with tradeQuoteCcy parameter for Unified USD Orderbook""" + mock_response = {'code': '0', 'msg': '', 'data': []} + mock_request.return_value = mock_response + + result = self.account_api.get_max_order_size( + instId='BTC-USD', + tdMode='cash', + tradeQuoteCcy='USDC' + ) + + expected_params = { + 'instId': 'BTC-USD', + 'tdMode': 'cash', + 'ccy': '', + 'px': '', + 'tradeQuoteCcy': 'USDC' + } + mock_request.assert_called_once_with(c.GET, c.MAX_TRADE_SIZE, expected_params) + + @patch.object(AccountAPI, '_request_with_params') + def test_get_max_order_size_without_tradeQuoteCcy(self, mock_request): + """Test get_max_order_size without tradeQuoteCcy (should not include in params)""" + mock_response = {'code': '0', 'msg': '', 'data': []} + mock_request.return_value = mock_response + + result = self.account_api.get_max_order_size( + instId='BTC-USDT', + tdMode='cash' + ) + + call_args = mock_request.call_args[0][2] + self.assertNotIn('tradeQuoteCcy', call_args) + + +class TestAccountAPIGetMaxAvailSize(unittest.TestCase): + """Unit tests for the get_max_avail_size method""" + + def setUp(self): + """Set up test fixtures""" + self.account_api = AccountAPI( + api_key='test_key', + api_secret_key='test_secret', + passphrase='test_pass', + flag='0' + ) + + @patch.object(AccountAPI, '_request_with_params') + def test_get_max_avail_size_with_required_params(self, mock_request): + """Test get_max_avail_size with required parameters only""" + mock_response = {'code': '0', 'msg': '', 'data': []} + mock_request.return_value = mock_response + + result = self.account_api.get_max_avail_size( + instId='BTC-USDT', + tdMode='cash' + ) + + expected_params = { + 'instId': 'BTC-USDT', + 'tdMode': 'cash', + 'ccy': '', + 'reduceOnly': '', + 'unSpotOffset': '', + 'quickMgnType': '' + } + mock_request.assert_called_once_with(c.GET, c.MAX_AVAIL_SIZE, expected_params) + self.assertEqual(result, mock_response) + + @patch.object(AccountAPI, '_request_with_params') + def test_get_max_avail_size_with_tradeQuoteCcy(self, mock_request): + """Test get_max_avail_size with tradeQuoteCcy parameter for Unified USD Orderbook""" + mock_response = {'code': '0', 'msg': '', 'data': []} + mock_request.return_value = mock_response + + result = self.account_api.get_max_avail_size( + instId='BTC-USD', + tdMode='cash', + tradeQuoteCcy='USDC' + ) + + expected_params = { + 'instId': 'BTC-USD', + 'tdMode': 'cash', + 'ccy': '', + 'reduceOnly': '', + 'unSpotOffset': '', + 'quickMgnType': '', + 'tradeQuoteCcy': 'USDC' + } + mock_request.assert_called_once_with(c.GET, c.MAX_AVAIL_SIZE, expected_params) + + @patch.object(AccountAPI, '_request_with_params') + def test_get_max_avail_size_without_tradeQuoteCcy(self, mock_request): + """Test get_max_avail_size without tradeQuoteCcy (should not include in params)""" + mock_response = {'code': '0', 'msg': '', 'data': []} + mock_request.return_value = mock_response + + result = self.account_api.get_max_avail_size( + instId='BTC-USDT', + tdMode='cash' + ) + + call_args = mock_request.call_args[0][2] + self.assertNotIn('tradeQuoteCcy', call_args) + + if __name__ == '__main__': unittest.main()