From 0df40584c2d94c19f9590bcf4497eb3fdac45c30 Mon Sep 17 00:00:00 2001 From: 007live Date: Thu, 9 May 2024 16:20:58 +0800 Subject: [PATCH] remove use_server_time param --- okx/Account.py | 2 +- okx/BlockTrading.py | 2 +- okx/Convert.py | 2 +- okx/Earning.py | 2 +- okx/FDBroker.py | 2 +- okx/Funding.py | 6 +++--- okx/Grid.py | 2 +- okx/MarketData.py | 2 +- okx/NDBroker.py | 2 +- okx/PublicData.py | 2 +- okx/SpreadTrading.py | 2 +- okx/Status.py | 2 +- okx/SubAccount.py | 2 +- okx/Trade.py | 4 ++-- okx/TradingData.py | 2 +- okx/__init__.py | 2 +- okx/consts.py | 4 ++-- okx/okxclient.py | 11 ++++++++--- test/AccountTest.py | 4 ++-- test/FundingTest.py | 2 ++ test/TradeTest.py | 1 - 21 files changed, 33 insertions(+), 27 deletions(-) diff --git a/okx/Account.py b/okx/Account.py index b45436b..10fd1ff 100644 --- a/okx/Account.py +++ b/okx/Account.py @@ -4,7 +4,7 @@ from .consts import * class AccountAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True,proxy = None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain = 'https://www.okx.com',debug = True,proxy = None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) # Get Positions diff --git a/okx/BlockTrading.py b/okx/BlockTrading.py index 49646f5..2979105 100644 --- a/okx/BlockTrading.py +++ b/okx/BlockTrading.py @@ -3,7 +3,7 @@ from .consts import * class BlockTradingAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) def counterparties(self): diff --git a/okx/Convert.py b/okx/Convert.py index 2e57252..fe5f5fe 100644 --- a/okx/Convert.py +++ b/okx/Convert.py @@ -3,7 +3,7 @@ from .consts import * class ConvertAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True,proxy = None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain = 'https://www.okx.com',debug = True,proxy = None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) def get_currencies(self): diff --git a/okx/Earning.py b/okx/Earning.py index 963e13f..bd19bef 100644 --- a/okx/Earning.py +++ b/okx/Earning.py @@ -3,7 +3,7 @@ from .consts import * class EarningAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) def get_offers(self,productId = '',protocolType = '',ccy = ''): diff --git a/okx/FDBroker.py b/okx/FDBroker.py index f1f220c..f2224fa 100644 --- a/okx/FDBroker.py +++ b/okx/FDBroker.py @@ -3,7 +3,7 @@ from .consts import * class FDBrokerAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) def generate_rebate_details_download_link(self, begin ='', end = ''): diff --git a/okx/Funding.py b/okx/Funding.py index 4f2e905..179dd0a 100644 --- a/okx/Funding.py +++ b/okx/Funding.py @@ -5,7 +5,7 @@ from .consts import * class FundingAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) # Get Deposit Address @@ -39,12 +39,12 @@ class FundingAPI(OkxClient): def get_deposit_history(self, ccy='', state='', after='', before='', limit='', txId='', depId='', fromWdId=''): params = {'ccy': ccy, 'state': state, 'after': after, 'before': before, 'limit': limit, 'txId': txId, 'depId': depId, 'fromWdId': fromWdId} - return self._request_with_params(GET, DEPOSIT_HISTORIY, params) + return self._request_with_params(GET, DEPOSIT_HISTORY, params) # Get Withdrawal History def get_withdrawal_history(self, ccy='', wdId='', state='', after='', before='', limit='',txId=''): params = {'ccy': ccy, 'wdId': wdId, 'state': state, 'after': after, 'before': before, 'limit': limit,'txId':txId} - return self._request_with_params(GET, WITHDRAWAL_HISTORIY, params) + return self._request_with_params(GET, WITHDRAWAL_HISTORY, params) # Get Currencies def get_currencies(self, ccy=''): diff --git a/okx/Grid.py b/okx/Grid.py index b09e8d5..dca8e9e 100644 --- a/okx/Grid.py +++ b/okx/Grid.py @@ -3,7 +3,7 @@ from .consts import * class GridAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) def grid_order_algo(self, instId='', algoOrdType='', maxPx='', minPx='', gridNum='', runType='', tpTriggerPx='', diff --git a/okx/MarketData.py b/okx/MarketData.py index 72e822a..0eb938b 100644 --- a/okx/MarketData.py +++ b/okx/MarketData.py @@ -4,7 +4,7 @@ from .consts import * class MarketAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) diff --git a/okx/NDBroker.py b/okx/NDBroker.py index 1df88de..d1db365 100644 --- a/okx/NDBroker.py +++ b/okx/NDBroker.py @@ -1,7 +1,7 @@ from .okxclient import OkxClient from .consts import * class NDBrokerAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) #GET /api/v5/broker/nd/info diff --git a/okx/PublicData.py b/okx/PublicData.py index 214a565..e191469 100644 --- a/okx/PublicData.py +++ b/okx/PublicData.py @@ -4,7 +4,7 @@ from .consts import * class PublicAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) # Get Instruments diff --git a/okx/SpreadTrading.py b/okx/SpreadTrading.py index 18a4033..3404536 100644 --- a/okx/SpreadTrading.py +++ b/okx/SpreadTrading.py @@ -4,7 +4,7 @@ from .consts import * class SpreadTradingAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) # Place Order diff --git a/okx/Status.py b/okx/Status.py index 7281de9..fa4230d 100644 --- a/okx/Status.py +++ b/okx/Status.py @@ -3,7 +3,7 @@ from .consts import * class StatusAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) def status(self, state=''): diff --git a/okx/SubAccount.py b/okx/SubAccount.py index 08aa3c0..61af341 100644 --- a/okx/SubAccount.py +++ b/okx/SubAccount.py @@ -3,7 +3,7 @@ from .consts import * class SubAccountAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) def get_account_balance(self, subAcct): diff --git a/okx/Trade.py b/okx/Trade.py index 504b463..f5cd0ed 100644 --- a/okx/Trade.py +++ b/okx/Trade.py @@ -6,7 +6,7 @@ from .consts import * class TradeAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain='https://www.okx.com', debug=True, proxy=None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) @@ -40,7 +40,7 @@ class TradeAPI(OkxClient): def amend_order(self, instId, cxlOnFail='', ordId='', clOrdId='', reqId='', newSz='', newPx='', newTpTriggerPx='', newTpOrdPx='', newSlTriggerPx='', newSlOrdPx='', newTpTriggerPxType='', newSlTriggerPxType='', attachAlgoOrds=''): - params = {'instId': instId, 'cxlOnFailc': cxlOnFail, 'ordId': ordId, 'clOrdId': clOrdId, 'reqId': reqId, + params = {'instId': instId, 'cxlOnFail': cxlOnFail, 'ordId': ordId, 'clOrdId': clOrdId, 'reqId': reqId, 'newSz': newSz, 'newPx': newPx, 'newTpTriggerPx': newTpTriggerPx, 'newTpOrdPx': newTpOrdPx, 'newSlTriggerPx': newSlTriggerPx, 'newSlOrdPx': newSlOrdPx, 'newTpTriggerPxType': newTpTriggerPxType, 'newSlTriggerPxType': newSlTriggerPxType} diff --git a/okx/TradingData.py b/okx/TradingData.py index bda2b4f..8944b41 100644 --- a/okx/TradingData.py +++ b/okx/TradingData.py @@ -4,7 +4,7 @@ from .consts import * class TradingDataAPI(OkxClient): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None): OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy) diff --git a/okx/__init__.py b/okx/__init__.py index 5c113f6..daad9a1 100644 --- a/okx/__init__.py +++ b/okx/__init__.py @@ -2,4 +2,4 @@ Python SDK for the OKX API v5 """ -__version__="0.2.8" \ No newline at end of file +__version__="0.2.9" \ No newline at end of file diff --git a/okx/consts.py b/okx/consts.py index 8551bea..234bc08 100644 --- a/okx/consts.py +++ b/okx/consts.py @@ -61,14 +61,14 @@ GET_BALANCES = '/api/v5/asset/balances' FUNDS_TRANSFER = '/api/v5/asset/transfer' TRANSFER_STATE = '/api/v5/asset/transfer-state' WITHDRAWAL_COIN = '/api/v5/asset/withdrawal' -DEPOSIT_HISTORIY = '/api/v5/asset/deposit-history' +DEPOSIT_HISTORY = '/api/v5/asset/deposit-history' CURRENCY_INFO = '/api/v5/asset/currencies' PURCHASE_REDEMPT = '/api/v5/asset/purchase_redempt' BILLS_INFO = '/api/v5/asset/bills' DEPOSIT_LIGHTNING = '/api/v5/asset/deposit-lightning' WITHDRAWAL_LIGHTNING = '/api/v5/asset/withdrawal-lightning' CANCEL_WITHDRAWAL = '/api/v5/asset/cancel-withdrawal' #need add -WITHDRAWAL_HISTORIY = '/api/v5/asset/withdrawal-history' +WITHDRAWAL_HISTORY = '/api/v5/asset/withdrawal-history' CONVERT_DUST_ASSETS = '/api/v5/asset/convert-dust-assets' #need add ASSET_VALUATION = '/api/v5/asset/asset-valuation' #need add SET_LENDING_RATE = '/api/v5/asset/set-lending-rate' diff --git a/okx/okxclient.py b/okx/okxclient.py index ae8d6d9..fa44488 100644 --- a/okx/okxclient.py +++ b/okx/okxclient.py @@ -1,22 +1,26 @@ import json +import warnings import httpx from httpx import Client +from datetime import datetime, timezone from . import consts as c, utils, exceptions class OkxClient(Client): - def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1',base_api=c.API_URL, debug='True', proxy=None): + def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1',base_api=c.API_URL, debug='True', proxy=None): super().__init__(base_url=base_api, http2=True, proxy=proxy) self.API_KEY = api_key self.API_SECRET_KEY = api_secret_key self.PASSPHRASE = passphrase - self.use_server_time = use_server_time + self.use_server_time = False self.flag = flag self.domain = base_api self.debug = debug + if use_server_time is not None: + warnings.warn("use_server_time parameter is deprecated. Please remove it.", DeprecationWarning) def _request(self, method, request_path, params): if method == c.GET: @@ -50,6 +54,7 @@ class OkxClient(Client): request_path = c.API_URL + c.SERVER_TIMESTAMP_URL response = self.get(request_path) if response.status_code == 200: - return response.json()['data'][0]['ts'] + ts = datetime.fromtimestamp(int(response.json()['data'][0]['ts']) / 1000.0, tz=timezone.utc) + return ts.isoformat(timespec='milliseconds').replace('+00:00', 'Z') else: return "" diff --git a/test/AccountTest.py b/test/AccountTest.py index c70f890..74e8395 100644 --- a/test/AccountTest.py +++ b/test/AccountTest.py @@ -21,8 +21,8 @@ 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'}] diff --git a/test/FundingTest.py b/test/FundingTest.py index d5725fd..d96926c 100644 --- a/test/FundingTest.py +++ b/test/FundingTest.py @@ -58,6 +58,8 @@ class FundingTest(unittest.TestCase): print(self.FundingAPI.get_lending_rate_summary('BTC')) """ + def test_get_non_tradable_assets(self): + print(self.FundingAPI.get_non_tradable_assets()) # def test_get_lending_summary(self): # print(self.FundingAPI.get_lending_rate_summary('BTC')) # def test_get_lending_rate_history(self): diff --git a/test/TradeTest.py b/test/TradeTest.py index 82487d9..c221f50 100644 --- a/test/TradeTest.py +++ b/test/TradeTest.py @@ -163,7 +163,6 @@ class TradeTest(unittest.TestCase): # print(self.tradeApi.get_oneclick_repay_list('cross')) # def test_oneclick_repay(self): # print(self.tradeApi.oneclick_repay(['BTC'],'USDT')) - # """ # 485903392536264704 # 485936482235191296 # def test_oneclick_repay_history(self):