Skip to content

Commit 892bc6b

Browse files
authored
Merge pull request #128 from okxapi/dev/BROK-1214
Dev/brok 1214
2 parents 240216f + e02411c commit 892bc6b

4 files changed

Lines changed: 125 additions & 0 deletions

File tree

okx/Account.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,9 @@ def set_auto_repay(self, autoRepay=False):
325325
def spot_borrow_repay_history(self, ccy='', type='', after='', before='', limit=''):
326326
params = {'ccy': ccy, 'type': type, 'after': after, 'before': before, 'limit': limit}
327327
return self._request_with_params(GET, GET_BORROW_REPAY_HISTORY, params)
328+
329+
def set_auto_earn(self, ccy, action, earnType=None):
330+
params = {'ccy': ccy, 'action': action}
331+
if earnType is not None:
332+
params['earnType'] = earnType
333+
return self._request_with_params(POST, SET_AUTO_EARN, params)

okx/consts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
MANUAL_REBORROW_REPAY = '/api/v5/account/spot-manual-borrow-repay'
6767
SET_AUTO_REPAY='/api/v5/account/set-auto-repay'
6868
GET_BORROW_REPAY_HISTORY='/api/v5/account/spot-borrow-repay-history'
69+
SET_AUTO_EARN='/api/v5/account/set-auto-earn'
6970

7071
# Funding
7172
NON_TRADABLE_ASSETS = '/api/v5/asset/non-tradable-assets'

test/AccountTest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ def setUp(self):
146146
# logger.info(f'{self.AccountAPI.set_auto_repay(autoRepay=True)}')
147147
# def test_spot_borrow_repay_history(self):
148148
# logger.debug(self.AccountAPI.spot_borrow_repay_history(ccy="USDT",type="auto_borrow",after="1597026383085"))
149+
def test_set_auto_earn(self):
150+
logger.debug(self.AccountAPI.set_auto_earn(ccy="USDT", action="turn_on", earnType='0'))
149151

150152
if __name__ == '__main__':
151153
unittest.main()

test/unit/okx/test_account.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,122 @@ def test_zero_idxVol_is_included(self, mock_request):
436436
mock_request.assert_called_once_with(c.POST, c.POSITION_BUILDER, expected_params)
437437

438438

439+
class TestAccountAPISetAutoEarn(unittest.TestCase):
440+
"""Unit tests for the set_auto_earn method"""
441+
442+
def setUp(self):
443+
"""Set up test fixtures"""
444+
self.account_api = AccountAPI(
445+
api_key='test_key',
446+
api_secret_key='test_secret',
447+
passphrase='test_pass',
448+
flag='0'
449+
)
450+
451+
@patch.object(AccountAPI, '_request_with_params')
452+
def test_set_auto_earn_with_all_params(self, mock_request):
453+
"""Test set_auto_earn with all parameters provided"""
454+
# Arrange
455+
mock_response = {'code': '0', 'msg': '', 'data': []}
456+
mock_request.return_value = mock_response
457+
458+
# Act
459+
result = self.account_api.set_auto_earn(
460+
ccy='USDT',
461+
action='turn_on',
462+
earnType='0'
463+
)
464+
465+
# Assert
466+
expected_params = {
467+
'ccy': 'USDT',
468+
'action': 'turn_on',
469+
'earnType': '0'
470+
}
471+
mock_request.assert_called_once_with(c.POST, c.SET_AUTO_EARN, expected_params)
472+
self.assertEqual(result, mock_response)
473+
474+
@patch.object(AccountAPI, '_request_with_params')
475+
def test_set_auto_earn_turn_on_action(self, mock_request):
476+
"""Test set_auto_earn with turn_on action"""
477+
# Arrange
478+
mock_response = {'code': '0', 'msg': '', 'data': []}
479+
mock_request.return_value = mock_response
480+
481+
# Act
482+
result = self.account_api.set_auto_earn(
483+
ccy='BTC',
484+
action='turn_on',
485+
earnType='0'
486+
)
487+
488+
# Assert
489+
expected_params = {
490+
'ccy': 'BTC',
491+
'action': 'turn_on',
492+
'earnType': '0'
493+
}
494+
mock_request.assert_called_once_with(c.POST, c.SET_AUTO_EARN, expected_params)
495+
496+
@patch.object(AccountAPI, '_request_with_params')
497+
def test_set_auto_earn_turn_off_action(self, mock_request):
498+
"""Test set_auto_earn with turn_off action"""
499+
# Arrange
500+
mock_response = {'code': '0', 'msg': '', 'data': []}
501+
mock_request.return_value = mock_response
502+
503+
# Act
504+
result = self.account_api.set_auto_earn(
505+
ccy='ETH',
506+
action='turn_off',
507+
earnType='0'
508+
)
509+
510+
# Assert
511+
expected_params = {
512+
'ccy': 'ETH',
513+
'action': 'turn_off',
514+
'earnType': '0'
515+
}
516+
mock_request.assert_called_once_with(c.POST, c.SET_AUTO_EARN, expected_params)
517+
518+
@patch.object(AccountAPI, '_request_with_params')
519+
def test_set_auto_earn_with_required_params_only(self, mock_request):
520+
"""Test set_auto_earn with required parameters only (ccy, action)"""
521+
# Arrange
522+
mock_response = {'code': '0', 'msg': '', 'data': []}
523+
mock_request.return_value = mock_response
524+
525+
# Act
526+
result = self.account_api.set_auto_earn(ccy='USDT', action='turn_on')
527+
528+
# Assert
529+
expected_params = {
530+
'ccy': 'USDT',
531+
'action': 'turn_on'
532+
}
533+
mock_request.assert_called_once_with(c.POST, c.SET_AUTO_EARN, expected_params)
534+
535+
@patch.object(AccountAPI, '_request_with_params')
536+
def test_set_auto_earn_different_currencies(self, mock_request):
537+
"""Test set_auto_earn with different currencies"""
538+
mock_response = {'code': '0', 'msg': '', 'data': []}
539+
mock_request.return_value = mock_response
540+
541+
currencies = ['USDT', 'BTC', 'ETH', 'USDC']
542+
543+
for ccy in currencies:
544+
mock_request.reset_mock()
545+
result = self.account_api.set_auto_earn(
546+
ccy=ccy,
547+
action='turn_on',
548+
earnType='0'
549+
)
550+
551+
call_args = mock_request.call_args[0][2]
552+
self.assertEqual(call_args['ccy'], ccy)
553+
554+
439555
if __name__ == '__main__':
440556
unittest.main()
441557

0 commit comments

Comments
 (0)