From 7d43159161fb2029b999521c1933ff8119712d2e Mon Sep 17 00:00:00 2001 From: 007live Date: Thu, 7 Mar 2024 18:11:38 +0800 Subject: [PATCH] feat: supported position builder --- okx/Account.py | 14 ++++++++++++++ okx/__init__.py | 2 +- okx/consts.py | 1 + test/AccountTest.py | 17 +++++++++++++++-- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/okx/Account.py b/okx/Account.py index 644c3cf..b45436b 100644 --- a/okx/Account.py +++ b/okx/Account.py @@ -26,6 +26,20 @@ class AccountAPI(OkxClient): params = {'instType': instType, 'instId': instId} return self._request_with_params(GET, POSITION_INFO, params) + def position_builder(self,inclRealPosAndEq=False, spotOffsetType=None, greeksType=None, simPos=None, simAsset=None): + params = {} + if inclRealPosAndEq is not None: + params['inclRealPosAndEq'] = inclRealPosAndEq + if spotOffsetType is not None: + params['spotOffsetType'] = spotOffsetType + if greeksType is not None: + params['greksType'] = greeksType + if simPos is not None: + params['simPos'] = simPos + if simAsset is not None: + params['simAsset'] = simAsset + return self._request_with_params(POST, POSITION_BUILDER, params) + # Get Bills Details (recent 7 days) def get_account_bills(self, instType='', ccy='', mgnMode='', ctType='', type='', subType='', after='', before='', limit=''): diff --git a/okx/__init__.py b/okx/__init__.py index ec4b7fd..5c113f6 100644 --- a/okx/__init__.py +++ b/okx/__init__.py @@ -2,4 +2,4 @@ Python SDK for the OKX API v5 """ -__version__="0.2.7" \ No newline at end of file +__version__="0.2.8" \ No newline at end of file diff --git a/okx/consts.py b/okx/consts.py index 618e6ca..8551bea 100644 --- a/okx/consts.py +++ b/okx/consts.py @@ -53,6 +53,7 @@ GET_VIP_LOAN_ORDER_DETAIL= '/api/v5/account/vip-loan-order-detail' SET_RISK_OFFSET_TYPE = '/api/v5/account/set-riskOffset-type' SET_AUTO_LOAN = '/api/v5/account/set-auto-loan' ACTIVSTE_OPTION = '/api/v5/account/activate-option' +POSITION_BUILDER = '/api/v5/account/position-builder' # funding-complete-testcomplete DEPOSIT_ADDRESS = '/api/v5/asset/deposit-address' diff --git a/test/AccountTest.py b/test/AccountTest.py index 0f75f90..c70f890 100644 --- a/test/AccountTest.py +++ b/test/AccountTest.py @@ -21,8 +21,21 @@ class AccountTest(unittest.TestCase): # def test_get_pm_limit(self): # print(self.AccountAPI.get_pm_limit("SWAP","BTC-USDT")) # positions-history - def test_get_positions_history(self): - print(self.AccountAPI.get_positions_history()) + # def test_get_positions_history(self): + # print(self.AccountAPI.get_positions_history()) + # def test_positions_builder(self): + # print("Both real and virtual positions and assets are calculated") + # sim_pos = [{'instId': 'BTC-USDT-SWAP', 'pos': '10'}, {'instId': 'BTC-USDT-SWAP', 'pos': '10'}] + # sim_asset = [{'ccy': 'USDT', 'amt': '100'}] + # print(self.AccountAPI.position_builder(inclRealPosAndEq=False, spotOffsetType='1', greeksType='CASH', + # simPos=sim_pos, simAsset=sim_asset)) + # + # print("Only existing real positions are calculated") + # print(self.AccountAPI.position_builder(inclRealPosAndEq=True, greeksType='CASH')) + # + # print("Only virtual positions are calculated") + # print(self.AccountAPI.position_builder(inclRealPosAndEq=False, simPos=sim_pos)) + # def test_get_user_config(self): # print(self.AccountAPI.get_account_config()) # def test_get_positions(self):