Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions okx/Account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
140 changes: 140 additions & 0 deletions test/unit/okx/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Loading