Skip to content

Commit e59f4db

Browse files
authored
Merge pull request #136 from okxapi/dev/BROK-1216
add tradeQuoteCcy request param to the trade-related endpoints
2 parents 06d4cd1 + e46a7e8 commit e59f4db

2 files changed

Lines changed: 146 additions & 2 deletions

File tree

‎okx/Account.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,18 @@ def set_leverage(self, lever, mgnMode, instId='', ccy='', posSide=''):
7676
return self._request_with_params(POST, SET_LEVERAGE, params)
7777

7878
# Get Maximum Tradable Size For Instrument
79-
def get_max_order_size(self, instId, tdMode, ccy='', px=''):
79+
def get_max_order_size(self, instId, tdMode, ccy='', px='', tradeQuoteCcy=None):
8080
params = {'instId': instId, 'tdMode': tdMode, 'ccy': ccy, 'px': px}
81+
if tradeQuoteCcy is not None:
82+
params['tradeQuoteCcy'] = tradeQuoteCcy
8183
return self._request_with_params(GET, MAX_TRADE_SIZE, params)
8284

8385
# Get Maximum Available Tradable Amount
84-
def get_max_avail_size(self, instId, tdMode, ccy='', reduceOnly='', unSpotOffset='', quickMgnType=''):
86+
def get_max_avail_size(self, instId, tdMode, ccy='', reduceOnly='', unSpotOffset='', quickMgnType='', tradeQuoteCcy=None):
8587
params = {'instId': instId, 'tdMode': tdMode, 'ccy': ccy, 'reduceOnly': reduceOnly,
8688
'unSpotOffset': unSpotOffset, 'quickMgnType': quickMgnType}
89+
if tradeQuoteCcy is not None:
90+
params['tradeQuoteCcy'] = tradeQuoteCcy
8791
return self._request_with_params(GET, MAX_AVAIL_SIZE, params)
8892

8993
# Increase / Decrease margin

‎test/unit/okx/test_account.py‎

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,146 @@ def test_set_auto_earn_different_currencies(self, mock_request):
552552
self.assertEqual(call_args['ccy'], ccy)
553553

554554

555+
class TestAccountAPIGetMaxOrderSize(unittest.TestCase):
556+
"""Unit tests for the get_max_order_size method"""
557+
558+
def setUp(self):
559+
"""Set up test fixtures"""
560+
self.account_api = AccountAPI(
561+
api_key='test_key',
562+
api_secret_key='test_secret',
563+
passphrase='test_pass',
564+
flag='0'
565+
)
566+
567+
@patch.object(AccountAPI, '_request_with_params')
568+
def test_get_max_order_size_with_required_params(self, mock_request):
569+
"""Test get_max_order_size with required parameters only"""
570+
mock_response = {'code': '0', 'msg': '', 'data': []}
571+
mock_request.return_value = mock_response
572+
573+
result = self.account_api.get_max_order_size(
574+
instId='BTC-USDT',
575+
tdMode='cash'
576+
)
577+
578+
expected_params = {
579+
'instId': 'BTC-USDT',
580+
'tdMode': 'cash',
581+
'ccy': '',
582+
'px': ''
583+
}
584+
mock_request.assert_called_once_with(c.GET, c.MAX_TRADE_SIZE, expected_params)
585+
self.assertEqual(result, mock_response)
586+
587+
@patch.object(AccountAPI, '_request_with_params')
588+
def test_get_max_order_size_with_tradeQuoteCcy(self, mock_request):
589+
"""Test get_max_order_size with tradeQuoteCcy parameter for Unified USD Orderbook"""
590+
mock_response = {'code': '0', 'msg': '', 'data': []}
591+
mock_request.return_value = mock_response
592+
593+
result = self.account_api.get_max_order_size(
594+
instId='BTC-USD',
595+
tdMode='cash',
596+
tradeQuoteCcy='USDC'
597+
)
598+
599+
expected_params = {
600+
'instId': 'BTC-USD',
601+
'tdMode': 'cash',
602+
'ccy': '',
603+
'px': '',
604+
'tradeQuoteCcy': 'USDC'
605+
}
606+
mock_request.assert_called_once_with(c.GET, c.MAX_TRADE_SIZE, expected_params)
607+
608+
@patch.object(AccountAPI, '_request_with_params')
609+
def test_get_max_order_size_without_tradeQuoteCcy(self, mock_request):
610+
"""Test get_max_order_size without tradeQuoteCcy (should not include in params)"""
611+
mock_response = {'code': '0', 'msg': '', 'data': []}
612+
mock_request.return_value = mock_response
613+
614+
result = self.account_api.get_max_order_size(
615+
instId='BTC-USDT',
616+
tdMode='cash'
617+
)
618+
619+
call_args = mock_request.call_args[0][2]
620+
self.assertNotIn('tradeQuoteCcy', call_args)
621+
622+
623+
class TestAccountAPIGetMaxAvailSize(unittest.TestCase):
624+
"""Unit tests for the get_max_avail_size method"""
625+
626+
def setUp(self):
627+
"""Set up test fixtures"""
628+
self.account_api = AccountAPI(
629+
api_key='test_key',
630+
api_secret_key='test_secret',
631+
passphrase='test_pass',
632+
flag='0'
633+
)
634+
635+
@patch.object(AccountAPI, '_request_with_params')
636+
def test_get_max_avail_size_with_required_params(self, mock_request):
637+
"""Test get_max_avail_size with required parameters only"""
638+
mock_response = {'code': '0', 'msg': '', 'data': []}
639+
mock_request.return_value = mock_response
640+
641+
result = self.account_api.get_max_avail_size(
642+
instId='BTC-USDT',
643+
tdMode='cash'
644+
)
645+
646+
expected_params = {
647+
'instId': 'BTC-USDT',
648+
'tdMode': 'cash',
649+
'ccy': '',
650+
'reduceOnly': '',
651+
'unSpotOffset': '',
652+
'quickMgnType': ''
653+
}
654+
mock_request.assert_called_once_with(c.GET, c.MAX_AVAIL_SIZE, expected_params)
655+
self.assertEqual(result, mock_response)
656+
657+
@patch.object(AccountAPI, '_request_with_params')
658+
def test_get_max_avail_size_with_tradeQuoteCcy(self, mock_request):
659+
"""Test get_max_avail_size with tradeQuoteCcy parameter for Unified USD Orderbook"""
660+
mock_response = {'code': '0', 'msg': '', 'data': []}
661+
mock_request.return_value = mock_response
662+
663+
result = self.account_api.get_max_avail_size(
664+
instId='BTC-USD',
665+
tdMode='cash',
666+
tradeQuoteCcy='USDC'
667+
)
668+
669+
expected_params = {
670+
'instId': 'BTC-USD',
671+
'tdMode': 'cash',
672+
'ccy': '',
673+
'reduceOnly': '',
674+
'unSpotOffset': '',
675+
'quickMgnType': '',
676+
'tradeQuoteCcy': 'USDC'
677+
}
678+
mock_request.assert_called_once_with(c.GET, c.MAX_AVAIL_SIZE, expected_params)
679+
680+
@patch.object(AccountAPI, '_request_with_params')
681+
def test_get_max_avail_size_without_tradeQuoteCcy(self, mock_request):
682+
"""Test get_max_avail_size without tradeQuoteCcy (should not include in params)"""
683+
mock_response = {'code': '0', 'msg': '', 'data': []}
684+
mock_request.return_value = mock_response
685+
686+
result = self.account_api.get_max_avail_size(
687+
instId='BTC-USDT',
688+
tdMode='cash'
689+
)
690+
691+
call_args = mock_request.call_args[0][2]
692+
self.assertNotIn('tradeQuoteCcy', call_args)
693+
694+
555695
if __name__ == '__main__':
556696
unittest.main()
557697

0 commit comments

Comments
 (0)