Compare commits
10 Commits
c4e7a98b0e
...
9313397381
| Author | SHA1 | Date |
|---|---|---|
|
|
9313397381 | |
|
|
6cd392d1a6 | |
|
|
7420e2a4da | |
|
|
f983c5bc2d | |
|
|
2a796ab74d | |
|
|
ef7e4f3a21 | |
|
|
0df40584c2 | |
|
|
26956b9b5e | |
|
|
e2e7b4f8af | |
|
|
a10a7f1145 |
123
okx/Account.py
123
okx/Account.py
|
|
@ -1,10 +1,11 @@
|
||||||
from .okxclient import OkxClient
|
|
||||||
from .consts import *
|
from .consts import *
|
||||||
|
from .okxclient import OkxClient
|
||||||
|
|
||||||
|
|
||||||
class AccountAPI(OkxClient):
|
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=False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||||
|
|
||||||
# Get Positions
|
# Get Positions
|
||||||
|
|
@ -26,7 +27,8 @@ class AccountAPI(OkxClient):
|
||||||
params = {'instType': instType, 'instId': instId}
|
params = {'instType': instType, 'instId': instId}
|
||||||
return self._request_with_params(GET, POSITION_INFO, params)
|
return self._request_with_params(GET, POSITION_INFO, params)
|
||||||
|
|
||||||
def position_builder(self,inclRealPosAndEq=False, spotOffsetType=None, greeksType=None, simPos=None, simAsset=None):
|
def position_builder(self, inclRealPosAndEq=False, spotOffsetType=None, greeksType=None, simPos=None,
|
||||||
|
simAsset=None):
|
||||||
params = {}
|
params = {}
|
||||||
if inclRealPosAndEq is not None:
|
if inclRealPosAndEq is not None:
|
||||||
params['inclRealPosAndEq'] = inclRealPosAndEq
|
params['inclRealPosAndEq'] = inclRealPosAndEq
|
||||||
|
|
@ -48,10 +50,11 @@ class AccountAPI(OkxClient):
|
||||||
return self._request_with_params(GET, BILLS_DETAIL, params)
|
return self._request_with_params(GET, BILLS_DETAIL, params)
|
||||||
|
|
||||||
# Get Bills Details (recent 3 months)
|
# Get Bills Details (recent 3 months)
|
||||||
def get_account_bills_archive(self, instType='', ccy='', mgnMode='', ctType='', type='', subType='', after='', before='',
|
def get_account_bills_archive(self, instType='', ccy='', mgnMode='', ctType='', type='', subType='', after='',
|
||||||
limit=''):
|
before='',
|
||||||
|
limit='', begin='', end=''):
|
||||||
params = {'instType': instType, 'ccy': ccy, 'mgnMode': mgnMode, 'ctType': ctType, 'type': type,
|
params = {'instType': instType, 'ccy': ccy, 'mgnMode': mgnMode, 'ctType': ctType, 'type': type,
|
||||||
'subType': subType, 'after': after, 'before': before, 'limit': limit}
|
'subType': subType, 'after': after, 'before': before, 'limit': limit, 'begin': begin, 'end': end}
|
||||||
return self._request_with_params(GET, BILLS_ARCHIVE, params)
|
return self._request_with_params(GET, BILLS_ARCHIVE, params)
|
||||||
|
|
||||||
# Get Account Configuration
|
# Get Account Configuration
|
||||||
|
|
@ -85,12 +88,17 @@ class AccountAPI(OkxClient):
|
||||||
return self._request_with_params(POST, ADJUSTMENT_MARGIN, params)
|
return self._request_with_params(POST, ADJUSTMENT_MARGIN, params)
|
||||||
|
|
||||||
# Get Leverage
|
# Get Leverage
|
||||||
def get_leverage(self, instId, mgnMode):
|
def get_leverage(self, mgnMode, ccy='', instId=''):
|
||||||
params = {'instId': instId, 'mgnMode': mgnMode}
|
params = {'instId': instId, 'mgnMode': mgnMode, 'ccy': ccy}
|
||||||
return self._request_with_params(GET, GET_LEVERAGE, params)
|
return self._request_with_params(GET, GET_LEVERAGE, params)
|
||||||
|
|
||||||
|
# Get instruments
|
||||||
|
def get_instruments(self, instType='', ugly='', instFamily='', instId=''):
|
||||||
|
params = {'instType': instType, 'ugly': ugly, 'instFamily': instFamily, 'instId': instId}
|
||||||
|
return self._request_with_params(GET, GET_INSTRUMENTS, params)
|
||||||
|
|
||||||
# Get the maximum loan of isolated MARGIN
|
# Get the maximum loan of isolated MARGIN
|
||||||
def get_max_loan(self, instId, mgnMode, mgnCcy):
|
def get_max_loan(self, instId, mgnMode, mgnCcy=''):
|
||||||
params = {'instId': instId, 'mgnMode': mgnMode, 'mgnCcy': mgnCcy}
|
params = {'instId': instId, 'mgnMode': mgnMode, 'mgnCcy': mgnCcy}
|
||||||
return self._request_with_params(GET, MAX_LOAN, params)
|
return self._request_with_params(GET, MAX_LOAN, params)
|
||||||
|
|
||||||
|
|
@ -154,7 +162,8 @@ class AccountAPI(OkxClient):
|
||||||
return self._request_without_params(GET, ACCOUNT_RISK)
|
return self._request_without_params(GET, ACCOUNT_RISK)
|
||||||
|
|
||||||
# GET /api/v5/account/positions-history
|
# GET /api/v5/account/positions-history
|
||||||
def get_positions_history(self,instType = '', instId = '',mgnMode = '',type = '',posId = '',after = '',before ='',limit = ''):
|
def get_positions_history(self, instType='', instId='', mgnMode='', type='', posId='', after='', before='',
|
||||||
|
limit=''):
|
||||||
params = {
|
params = {
|
||||||
'instType': instType,
|
'instType': instType,
|
||||||
'instId': instId,
|
'instId': instId,
|
||||||
|
|
@ -211,3 +220,97 @@ class AccountAPI(OkxClient):
|
||||||
# - Activate option
|
# - Activate option
|
||||||
def activate_option(self):
|
def activate_option(self):
|
||||||
return self._request_without_params(POST, ACTIVSTE_OPTION)
|
return self._request_without_params(POST, ACTIVSTE_OPTION)
|
||||||
|
|
||||||
|
def get_fix_loan_borrowing_limit(self):
|
||||||
|
return self._request_without_params(GET, BORROWING_LIMIT)
|
||||||
|
|
||||||
|
def get_fix_loan_borrowing_quote(self, type=None, ccy=None, amt=None, maxRate=None, term=None, ordId=None):
|
||||||
|
params = {}
|
||||||
|
if type is not None:
|
||||||
|
params['type'] = type
|
||||||
|
if ccy is not None:
|
||||||
|
params['ccy'] =ccy
|
||||||
|
if amt is not None:
|
||||||
|
params['amt'] = amt
|
||||||
|
if maxRate is not None:
|
||||||
|
params['maxRate'] = maxRate
|
||||||
|
if term is not None:
|
||||||
|
params['term'] = term
|
||||||
|
if ordId is not None:
|
||||||
|
params['ordId'] = ordId
|
||||||
|
return self._request_with_params(GET, BORROWING_QUOTE, params)
|
||||||
|
|
||||||
|
def place_fix_loan_borrowing_order(self, ccy=None, amt=None, maxRate=None, term=None, reborrow=False, reborrowRate=None):
|
||||||
|
params = {}
|
||||||
|
if ccy is not None:
|
||||||
|
params['ccy'] =ccy
|
||||||
|
if amt is not None:
|
||||||
|
params['amt'] = amt
|
||||||
|
if maxRate is not None:
|
||||||
|
params['maxRate'] = maxRate
|
||||||
|
if term is not None:
|
||||||
|
params['term'] = term
|
||||||
|
if reborrow is not None:
|
||||||
|
params['reborrow'] = reborrow
|
||||||
|
if reborrowRate is not None:
|
||||||
|
params['reborrowRate'] = reborrowRate
|
||||||
|
return self._request_with_params(POST, PLACE_BORROWING_ORDER, params)
|
||||||
|
|
||||||
|
def amend_fix_loan_borrowing_order(self, ordId=None, reborrow=None, renewMaxRate=None):
|
||||||
|
params = {}
|
||||||
|
if ordId is not None:
|
||||||
|
params['ordId'] = ordId
|
||||||
|
if reborrow is not None:
|
||||||
|
params['reborrow'] = reborrow
|
||||||
|
if renewMaxRate is not None:
|
||||||
|
params['renewMaxRate'] = renewMaxRate
|
||||||
|
return self._request_with_params(POST, AMEND_BORROWING_ORDER, params)
|
||||||
|
|
||||||
|
def fix_loan_manual_reborrow(self, ordId=None, maxRate=None):
|
||||||
|
params = {}
|
||||||
|
if ordId is not None:
|
||||||
|
params['ordId'] = ordId
|
||||||
|
if maxRate is not None:
|
||||||
|
params['maxRate'] = maxRate
|
||||||
|
return self._request_with_params(POST, MANUAL_REBORROW, params)
|
||||||
|
|
||||||
|
def repay_fix_loan_borrowing_order(self, ordId=None):
|
||||||
|
params = {}
|
||||||
|
if ordId is not None:
|
||||||
|
params['ordId'] = ordId
|
||||||
|
return self._request_with_params(POST, REPAY_BORROWING_ORDER, params)
|
||||||
|
def get_fix_loan_borrowing_orders_list(self, ordId=None, ccy=None, state=None, after=None, before=None, limit=None):
|
||||||
|
params = {}
|
||||||
|
if ordId is not None:
|
||||||
|
params['ordId'] = ordId
|
||||||
|
if ccy is not None:
|
||||||
|
params['ccy'] =ccy
|
||||||
|
if state is not None:
|
||||||
|
params['state'] = state
|
||||||
|
if after is not None:
|
||||||
|
params['after'] = after
|
||||||
|
if before is not None:
|
||||||
|
params['before'] = before
|
||||||
|
if limit is not None:
|
||||||
|
params['limit'] = limit
|
||||||
|
return self._request_with_params(GET, BORROWING_ORDERS_LIST, params)
|
||||||
|
|
||||||
|
def spot_manual_borrow_repay(self, ccy=None, side=None, amt=None):
|
||||||
|
params = {}
|
||||||
|
if ccy is not None:
|
||||||
|
params['ccy'] = ccy
|
||||||
|
if side is not None:
|
||||||
|
params['side'] = side
|
||||||
|
if amt is not None:
|
||||||
|
params['amt'] = amt
|
||||||
|
return self._request_with_params(POST, MANUAL_REBORROW_REPAY, params)
|
||||||
|
|
||||||
|
def set_auto_repay(self, autoRepay=False):
|
||||||
|
params = {}
|
||||||
|
if autoRepay is not None:
|
||||||
|
params['autoRepay'] = autoRepay
|
||||||
|
return self._request_with_params(POST, SET_AUTO_REPAY, params)
|
||||||
|
|
||||||
|
def spot_borrow_repay_history(self, ccy='', type='', after='', before='', limit=''):
|
||||||
|
params = {'ccy': ccy, 'type': type, 'after': after, 'before': before, 'limit': limit}
|
||||||
|
return self._request_with_params(GET, GET_BORROW_REPAY_HISTORY, params)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from .consts import *
|
||||||
|
|
||||||
|
|
||||||
class BlockTradingAPI(OkxClient):
|
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 = False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||||
|
|
||||||
def counterparties(self):
|
def counterparties(self):
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from .consts import *
|
||||||
|
|
||||||
|
|
||||||
class ConvertAPI(OkxClient):
|
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 = False,proxy = None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||||
|
|
||||||
def get_currencies(self):
|
def get_currencies(self):
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from .consts import *
|
||||||
|
|
||||||
class CopyTradingAPI(OkxClient):
|
class CopyTradingAPI(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=False, flag='1',
|
||||||
domain='https://www.okx.com', debug=True, proxy=None):
|
domain='https://www.okx.com', debug=False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,
|
||||||
proxy=proxy)
|
proxy=proxy)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from .consts import *
|
||||||
|
|
||||||
|
|
||||||
class EarningAPI(OkxClient):
|
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 = False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||||
|
|
||||||
def get_offers(self,productId = '',protocolType = '',ccy = ''):
|
def get_offers(self,productId = '',protocolType = '',ccy = ''):
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from .consts import *
|
||||||
|
|
||||||
|
|
||||||
class FDBrokerAPI(OkxClient):
|
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 = False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
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 = ''):
|
def generate_rebate_details_download_link(self, begin ='', end = ''):
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ from .consts import *
|
||||||
class FundingAPI(OkxClient):
|
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 = False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||||
|
|
||||||
# Get Non Tradable Assets
|
# Get Non Tradable Assets
|
||||||
|
|
@ -35,8 +35,8 @@ class FundingAPI(OkxClient):
|
||||||
return self._request_with_params(POST, FUNDS_TRANSFER, params)
|
return self._request_with_params(POST, FUNDS_TRANSFER, params)
|
||||||
|
|
||||||
# Withdrawal
|
# Withdrawal
|
||||||
def withdrawal(self, ccy, amt, dest, toAddr, fee, chain='', areaCode='', clientId=''):
|
def withdrawal(self, ccy, amt, dest, toAddr, chain='', areaCode='', clientId=''):
|
||||||
params = {'ccy': ccy, 'amt': amt, 'dest': dest, 'toAddr': toAddr, 'fee': fee, 'chain': chain,
|
params = {'ccy': ccy, 'amt': amt, 'dest': dest, 'toAddr': toAddr, 'chain': chain,
|
||||||
'areaCode': areaCode, 'clientId': clientId}
|
'areaCode': areaCode, 'clientId': clientId}
|
||||||
return self._request_with_params(POST, WITHDRAWAL_COIN, params)
|
return self._request_with_params(POST, WITHDRAWAL_COIN, params)
|
||||||
|
|
||||||
|
|
@ -44,12 +44,12 @@ class FundingAPI(OkxClient):
|
||||||
def get_deposit_history(self, ccy='', state='', after='', before='', limit='', txId='', depId='', fromWdId=''):
|
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,
|
params = {'ccy': ccy, 'state': state, 'after': after, 'before': before, 'limit': limit, 'txId': txId,
|
||||||
'depId': depId, 'fromWdId': fromWdId}
|
'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
|
# Get Withdrawal History
|
||||||
def get_withdrawal_history(self, ccy='', wdId='', state='', after='', before='', limit='',txId=''):
|
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}
|
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
|
# Get Currencies
|
||||||
def get_currencies(self, ccy=''):
|
def get_currencies(self, ccy=''):
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from .consts import *
|
||||||
|
|
||||||
|
|
||||||
class GridAPI(OkxClient):
|
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 = False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
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='',
|
def grid_order_algo(self, instId='', algoOrdType='', maxPx='', minPx='', gridNum='', runType='', tpTriggerPx='',
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from .consts import *
|
||||||
|
|
||||||
class MarketAPI(OkxClient):
|
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 = False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from .okxclient import OkxClient
|
from .okxclient import OkxClient
|
||||||
from .consts import *
|
from .consts import *
|
||||||
class NDBrokerAPI(OkxClient):
|
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 = False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||||
|
|
||||||
#GET /api/v5/broker/nd/info
|
#GET /api/v5/broker/nd/info
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from .consts import *
|
||||||
|
|
||||||
class PublicAPI(OkxClient):
|
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 = False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||||
|
|
||||||
# Get Instruments
|
# Get Instruments
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
from okx.consts import GET, LENDING_OFFERS, LENDING_APY_HISTORY, PENDING_LENDING_VOLUME, PLACE_LENDING_ORDER, POST, \
|
||||||
|
AMEND_LENDING_ORDER, LENDING_ORDERS_LIST, LENDING_SUB_ORDERS
|
||||||
|
from okx.okxclient import OkxClient
|
||||||
|
|
||||||
|
|
||||||
|
class SimpleEarnFixedAPI(OkxClient):
|
||||||
|
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=None, flag='1',
|
||||||
|
domain='https://www.okx.com', debug=False, proxy=None):
|
||||||
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||||
|
|
||||||
|
def get_lending_offers(self, ccy=None, term=None):
|
||||||
|
params = {}
|
||||||
|
if ccy is not None:
|
||||||
|
params['ccy'] = ccy
|
||||||
|
if term is not None:
|
||||||
|
params['term'] = term
|
||||||
|
return self._request_with_params(GET, LENDING_OFFERS, params)
|
||||||
|
|
||||||
|
def get_lending_apy_history(self, ccy=None, term=None):
|
||||||
|
params = {}
|
||||||
|
if ccy is not None:
|
||||||
|
params['ccy'] = ccy
|
||||||
|
if term is not None:
|
||||||
|
params['term'] = term
|
||||||
|
return self._request_with_params(GET, LENDING_APY_HISTORY, params)
|
||||||
|
|
||||||
|
def get_pending_lending_volume(self, ccy=None, term=None):
|
||||||
|
params = {}
|
||||||
|
if ccy is not None:
|
||||||
|
params['ccy'] = ccy
|
||||||
|
if term is not None:
|
||||||
|
params['term'] = term
|
||||||
|
return self._request_with_params(GET, PENDING_LENDING_VOLUME, params)
|
||||||
|
|
||||||
|
def place_lending_order(self, ccy=None, amt=None, rate=None, term=None, autoRenewal=False):
|
||||||
|
params = {}
|
||||||
|
if ccy is not None:
|
||||||
|
params['ccy'] = ccy
|
||||||
|
if amt is not None:
|
||||||
|
params['amt'] = amt
|
||||||
|
if rate is not None:
|
||||||
|
params['rate'] = rate
|
||||||
|
if term is not None:
|
||||||
|
params['term'] = term
|
||||||
|
if autoRenewal:
|
||||||
|
params['autoRenewal'] = autoRenewal
|
||||||
|
return self._request_with_params(POST, PLACE_LENDING_ORDER, params)
|
||||||
|
def amend_lending_order(self, ordId=None, changeAmt=None, rate=None,autoRenewal=False):
|
||||||
|
params = {}
|
||||||
|
if ordId is not None:
|
||||||
|
params['ordId'] = ordId
|
||||||
|
if changeAmt is not None:
|
||||||
|
params['amt'] = changeAmt
|
||||||
|
if rate is not None:
|
||||||
|
params['rate'] = rate
|
||||||
|
params['autoRenewal'] = autoRenewal
|
||||||
|
return self._request_with_params(POST, AMEND_LENDING_ORDER, params)
|
||||||
|
|
||||||
|
def get_lending_orders_list(self, ordId = None,ccy=None, state=None, after=None,before=None,limit=None):
|
||||||
|
params = {}
|
||||||
|
if ordId is not None:
|
||||||
|
params['ordId'] = ordId
|
||||||
|
if ccy is not None:
|
||||||
|
params['ccy'] = ccy
|
||||||
|
if state is not None:
|
||||||
|
params['state'] = state
|
||||||
|
if after is not None:
|
||||||
|
params['after'] = after
|
||||||
|
if before is not None:
|
||||||
|
params['before'] = before
|
||||||
|
if limit:
|
||||||
|
params['limit'] = limit
|
||||||
|
return self._request_with_params(GET, LENDING_ORDERS_LIST, params)
|
||||||
|
|
||||||
|
def get_lending_sub_orders(self, ordId = None, state=None, after=None,before=None,limit=None):
|
||||||
|
params = {}
|
||||||
|
if ordId is not None:
|
||||||
|
params['ordId'] = ordId
|
||||||
|
if state is not None:
|
||||||
|
params['state'] = state
|
||||||
|
if after is not None:
|
||||||
|
params['after'] = after
|
||||||
|
if before is not None:
|
||||||
|
params['before'] = before
|
||||||
|
if limit:
|
||||||
|
params['limit'] = limit
|
||||||
|
return self._request_with_params(GET, LENDING_SUB_ORDERS, params)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -4,7 +4,7 @@ from .consts import *
|
||||||
|
|
||||||
class SpreadTradingAPI(OkxClient):
|
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 = False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||||
|
|
||||||
# Place Order
|
# Place Order
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from .consts import *
|
||||||
|
|
||||||
|
|
||||||
class StatusAPI(OkxClient):
|
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 = False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||||
|
|
||||||
def status(self, state=''):
|
def status(self, state=''):
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from .consts import *
|
||||||
|
|
||||||
|
|
||||||
class SubAccountAPI(OkxClient):
|
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 = False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||||
|
|
||||||
def get_account_balance(self, subAcct):
|
def get_account_balance(self, subAcct):
|
||||||
|
|
|
||||||
10
okx/Trade.py
10
okx/Trade.py
|
|
@ -6,8 +6,8 @@ from .consts import *
|
||||||
|
|
||||||
class TradeAPI(OkxClient):
|
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):
|
domain='https://www.okx.com', debug=False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||||
|
|
||||||
# Place Order
|
# Place Order
|
||||||
|
|
@ -40,7 +40,7 @@ class TradeAPI(OkxClient):
|
||||||
def amend_order(self, instId, cxlOnFail='', ordId='', clOrdId='', reqId='', newSz='', newPx='', newTpTriggerPx='',
|
def amend_order(self, instId, cxlOnFail='', ordId='', clOrdId='', reqId='', newSz='', newPx='', newTpTriggerPx='',
|
||||||
newTpOrdPx='', newSlTriggerPx='', newSlOrdPx='', newTpTriggerPxType='', newSlTriggerPxType='',
|
newTpOrdPx='', newSlTriggerPx='', newSlOrdPx='', newTpTriggerPxType='', newSlTriggerPxType='',
|
||||||
attachAlgoOrds=''):
|
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,
|
'newSz': newSz, 'newPx': newPx, 'newTpTriggerPx': newTpTriggerPx, 'newTpOrdPx': newTpOrdPx,
|
||||||
'newSlTriggerPx': newSlTriggerPx, 'newSlOrdPx': newSlOrdPx, 'newTpTriggerPxType': newTpTriggerPxType,
|
'newSlTriggerPx': newSlTriggerPx, 'newSlOrdPx': newSlOrdPx, 'newTpTriggerPxType': newTpTriggerPxType,
|
||||||
'newSlTriggerPxType': newSlTriggerPxType}
|
'newSlTriggerPxType': newSlTriggerPxType}
|
||||||
|
|
@ -86,9 +86,9 @@ class TradeAPI(OkxClient):
|
||||||
return self._request_with_params(GET, ORDERS_HISTORY_ARCHIVE, params)
|
return self._request_with_params(GET, ORDERS_HISTORY_ARCHIVE, params)
|
||||||
|
|
||||||
# Get Transaction Details
|
# Get Transaction Details
|
||||||
def get_fills(self, instType='', uly='', instId='', ordId='', after='', before='', limit='', instFamily=''):
|
def get_fills(self, instType='', uly='', instId='', ordId='', after='', before='', limit='', instFamily='',begin='',end=''):
|
||||||
params = {'instType': instType, 'uly': uly, 'instId': instId, 'ordId': ordId, 'after': after, 'before': before,
|
params = {'instType': instType, 'uly': uly, 'instId': instId, 'ordId': ordId, 'after': after, 'before': before,
|
||||||
'limit': limit, 'instFamily': instFamily}
|
'limit': limit, 'instFamily': instFamily,'begin': begin, 'end' :end}
|
||||||
return self._request_with_params(GET, ORDER_FILLS, params)
|
return self._request_with_params(GET, ORDER_FILLS, params)
|
||||||
|
|
||||||
# Place Algo Order
|
# Place Algo Order
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from .consts import *
|
||||||
|
|
||||||
class TradingDataAPI(OkxClient):
|
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 = False, proxy=None):
|
||||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,4 @@
|
||||||
Python SDK for the OKX API v5
|
Python SDK for the OKX API v5
|
||||||
|
|
||||||
"""
|
"""
|
||||||
__version__="0.2.8"
|
__version__="0.3.5"
|
||||||
|
|
@ -54,6 +54,17 @@ SET_RISK_OFFSET_TYPE = '/api/v5/account/set-riskOffset-type'
|
||||||
SET_AUTO_LOAN = '/api/v5/account/set-auto-loan'
|
SET_AUTO_LOAN = '/api/v5/account/set-auto-loan'
|
||||||
ACTIVSTE_OPTION = '/api/v5/account/activate-option'
|
ACTIVSTE_OPTION = '/api/v5/account/activate-option'
|
||||||
POSITION_BUILDER = '/api/v5/account/position-builder'
|
POSITION_BUILDER = '/api/v5/account/position-builder'
|
||||||
|
GET_INSTRUMENTS = '/api/v5/account/instruments'
|
||||||
|
BORROWING_LIMIT = '/api/v5/account/fixed-loan/borrowing-limit'
|
||||||
|
BORROWING_QUOTE = '/api/v5/account/fixed-loan/borrowing-quote'
|
||||||
|
PLACE_BORROWING_ORDER= '/api/v5/account/fixed-loan/borrowing-order'
|
||||||
|
AMEND_BORROWING_ORDER='/api/v5/account/fixed-loan/amend-borrowing-order'
|
||||||
|
MANUAL_REBORROW = '/api/v5/account/fixed-loan/manual-reborrow'
|
||||||
|
REPAY_BORROWING_ORDER='/api/v5/account/fixed-loan/repay-borrowing-order'
|
||||||
|
BORROWING_ORDERS_LIST='/api/v5/account/fixed-loan/borrowing-orders-list'
|
||||||
|
MANUAL_REBORROW_REPAY = '/api/v5/account/spot-manual-borrow-repay'
|
||||||
|
SET_AUTO_REPAY='/api/v5/account/set-auto-repay'
|
||||||
|
GET_BORROW_REPAY_HISTORY='/api/v5/account/spot-borrow-repay-history'
|
||||||
|
|
||||||
# funding-complete-testcomplete
|
# funding-complete-testcomplete
|
||||||
NON_TRADABLE_ASSETS = '/api/v5/asset/non-tradable-assets'
|
NON_TRADABLE_ASSETS = '/api/v5/asset/non-tradable-assets'
|
||||||
|
|
@ -62,14 +73,14 @@ GET_BALANCES = '/api/v5/asset/balances'
|
||||||
FUNDS_TRANSFER = '/api/v5/asset/transfer'
|
FUNDS_TRANSFER = '/api/v5/asset/transfer'
|
||||||
TRANSFER_STATE = '/api/v5/asset/transfer-state'
|
TRANSFER_STATE = '/api/v5/asset/transfer-state'
|
||||||
WITHDRAWAL_COIN = '/api/v5/asset/withdrawal'
|
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'
|
CURRENCY_INFO = '/api/v5/asset/currencies'
|
||||||
PURCHASE_REDEMPT = '/api/v5/asset/purchase_redempt'
|
PURCHASE_REDEMPT = '/api/v5/asset/purchase_redempt'
|
||||||
BILLS_INFO = '/api/v5/asset/bills'
|
BILLS_INFO = '/api/v5/asset/bills'
|
||||||
DEPOSIT_LIGHTNING = '/api/v5/asset/deposit-lightning'
|
DEPOSIT_LIGHTNING = '/api/v5/asset/deposit-lightning'
|
||||||
WITHDRAWAL_LIGHTNING = '/api/v5/asset/withdrawal-lightning'
|
WITHDRAWAL_LIGHTNING = '/api/v5/asset/withdrawal-lightning'
|
||||||
CANCEL_WITHDRAWAL = '/api/v5/asset/cancel-withdrawal' #need add
|
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
|
CONVERT_DUST_ASSETS = '/api/v5/asset/convert-dust-assets' #need add
|
||||||
ASSET_VALUATION = '/api/v5/asset/asset-valuation' #need add
|
ASSET_VALUATION = '/api/v5/asset/asset-valuation' #need add
|
||||||
SET_LENDING_RATE = '/api/v5/asset/set-lending-rate'
|
SET_LENDING_RATE = '/api/v5/asset/set-lending-rate'
|
||||||
|
|
@ -154,7 +165,7 @@ ORDERS_FILLS_HISTORY = '/api/v5/trade/fills-history'
|
||||||
PLACE_ALGO_ORDER = '/api/v5/trade/order-algo'
|
PLACE_ALGO_ORDER = '/api/v5/trade/order-algo'
|
||||||
CANCEL_ALGOS = '/api/v5/trade/cancel-algos'
|
CANCEL_ALGOS = '/api/v5/trade/cancel-algos'
|
||||||
Cancel_Advance_Algos = '/api/v5/trade/cancel-advance-algos'
|
Cancel_Advance_Algos = '/api/v5/trade/cancel-advance-algos'
|
||||||
ORDERS_ALGO_OENDING = '/api/v5/trade/orders-algo-pending'
|
ORDERS_ALGO_PENDING = '/api/v5/trade/orders-algo-pending'
|
||||||
ORDERS_ALGO_HISTORY = '/api/v5/trade/orders-algo-history'
|
ORDERS_ALGO_HISTORY = '/api/v5/trade/orders-algo-history'
|
||||||
GET_ALGO_ORDER_DETAILS = '/api/v5/trade/order-algo'
|
GET_ALGO_ORDER_DETAILS = '/api/v5/trade/order-algo'
|
||||||
AMEND_ALGO_ORDER = '/api/v5/trade/amend-algos'
|
AMEND_ALGO_ORDER = '/api/v5/trade/amend-algos'
|
||||||
|
|
@ -291,3 +302,14 @@ SPREAD_GET_SPREADS = '/api/v5/sprd/spreads'
|
||||||
SPREAD_GET_ORDER_BOOK = '/api/v5/sprd/books'
|
SPREAD_GET_ORDER_BOOK = '/api/v5/sprd/books'
|
||||||
SPREAD_GET_TICKER = '/api/v5/sprd/ticker'
|
SPREAD_GET_TICKER = '/api/v5/sprd/ticker'
|
||||||
SPREAD_GET_PUBLIC_TRADES = '/api/v5/sprd/public-trades'
|
SPREAD_GET_PUBLIC_TRADES = '/api/v5/sprd/public-trades'
|
||||||
|
|
||||||
|
# Simple earn fixed
|
||||||
|
LENDING_OFFERS = '/api/v5/finance/fixed-loan/lending-offers'
|
||||||
|
LENDING_APY_HISTORY='/api/v5/finance/fixed-loan/lending-apy-history'
|
||||||
|
PENDING_LENDING_VOLUME = '/api/v5/finance/fixed-loan/pending-lending-volume'
|
||||||
|
PLACE_LENDING_ORDER= '/api/v5/finance/fixed-loan/lending-order'
|
||||||
|
AMEND_LENDING_ORDER='/api/v5/finance/fixed-loan/amend-lending-order'
|
||||||
|
LENDING_ORDERS_LIST='/api/v5/finance/fixed-loan/lending-orders-list'
|
||||||
|
LENDING_SUB_ORDERS='/api/v5/finance/fixed-loan/lending-sub-orders'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,29 @@
|
||||||
import json
|
import json
|
||||||
|
import warnings
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from httpx import Client
|
from httpx import Client
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
from . import consts as c, utils, exceptions
|
from . import consts as c, utils, exceptions
|
||||||
|
|
||||||
|
|
||||||
class OkxClient(Client):
|
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=False, proxy=None):
|
||||||
super().__init__(base_url=base_api, http2=True, proxy=proxy)
|
super().__init__(base_url=base_api, http2=True, proxy=proxy)
|
||||||
self.API_KEY = api_key
|
self.API_KEY = api_key
|
||||||
self.API_SECRET_KEY = api_secret_key
|
self.API_SECRET_KEY = api_secret_key
|
||||||
self.PASSPHRASE = passphrase
|
self.PASSPHRASE = passphrase
|
||||||
self.use_server_time = use_server_time
|
self.use_server_time = False
|
||||||
self.flag = flag
|
self.flag = flag
|
||||||
self.domain = base_api
|
self.domain = base_api
|
||||||
self.debug = debug
|
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):
|
def _request(self, method, request_path, params):
|
||||||
if method == c.GET:
|
if method == c.GET:
|
||||||
|
|
@ -32,8 +39,9 @@ class OkxClient(Client):
|
||||||
header = utils.get_header_no_sign(self.flag, self.debug)
|
header = utils.get_header_no_sign(self.flag, self.debug)
|
||||||
response = None
|
response = None
|
||||||
if self.debug == True:
|
if self.debug == True:
|
||||||
print('domain:',self.domain)
|
logger.debug(f'domain: {self.domain}')
|
||||||
print('url:',request_path)
|
logger.debug(f'url: {request_path}')
|
||||||
|
logger.debug(f'body:{body}')
|
||||||
if method == c.GET:
|
if method == c.GET:
|
||||||
response = self.get(request_path, headers=header)
|
response = self.get(request_path, headers=header)
|
||||||
elif method == c.POST:
|
elif method == c.POST:
|
||||||
|
|
@ -50,6 +58,7 @@ class OkxClient(Client):
|
||||||
request_path = c.API_URL + c.SERVER_TIMESTAMP_URL
|
request_path = c.API_URL + c.SERVER_TIMESTAMP_URL
|
||||||
response = self.get(request_path)
|
response = self.get(request_path)
|
||||||
if response.status_code == 200:
|
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:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
|
||||||
10
okx/utils.py
10
okx/utils.py
|
|
@ -1,6 +1,9 @@
|
||||||
import hmac
|
import hmac
|
||||||
import base64
|
import base64
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
from . import consts as c
|
from . import consts as c
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -12,7 +15,7 @@ def sign(message, secretKey):
|
||||||
|
|
||||||
def pre_hash(timestamp, method, request_path, body,debug = True):
|
def pre_hash(timestamp, method, request_path, body,debug = True):
|
||||||
if debug == True:
|
if debug == True:
|
||||||
print('body: ',body)
|
logger.debug(f'body: {body}')
|
||||||
return str(timestamp) + str.upper(method) + request_path + body
|
return str(timestamp) + str.upper(method) + request_path + body
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -25,7 +28,7 @@ def get_header(api_key, sign, timestamp, passphrase, flag,debug = True):
|
||||||
header[c.OK_ACCESS_PASSPHRASE] = passphrase
|
header[c.OK_ACCESS_PASSPHRASE] = passphrase
|
||||||
header['x-simulated-trading'] = flag
|
header['x-simulated-trading'] = flag
|
||||||
if debug == True:
|
if debug == True:
|
||||||
print('header: ',header)
|
logger.debug(f'header: {header}')
|
||||||
return header
|
return header
|
||||||
|
|
||||||
def get_header_no_sign(flag,debug = True):
|
def get_header_no_sign(flag,debug = True):
|
||||||
|
|
@ -33,7 +36,7 @@ def get_header_no_sign(flag,debug = True):
|
||||||
header[c.CONTENT_TYPE] = c.APPLICATION_JSON
|
header[c.CONTENT_TYPE] = c.APPLICATION_JSON
|
||||||
header['x-simulated-trading'] = flag
|
header['x-simulated-trading'] = flag
|
||||||
if debug == True:
|
if debug == True:
|
||||||
print('header: ',header)
|
logger.debug(f'header: {header}')
|
||||||
return header
|
return header
|
||||||
|
|
||||||
def parse_params_to_str(params):
|
def parse_params_to_str(params):
|
||||||
|
|
@ -42,7 +45,6 @@ def parse_params_to_str(params):
|
||||||
if(value != ''):
|
if(value != ''):
|
||||||
url = url + str(key) + '=' + str(value) + '&'
|
url = url + str(key) + '=' + str(value) + '&'
|
||||||
url = url[0:-1]
|
url = url[0:-1]
|
||||||
#print('url:',url)
|
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,7 @@ import ssl
|
||||||
import certifi
|
import certifi
|
||||||
import websockets
|
import websockets
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logger = logging.getLogger(__name__)
|
||||||
logger = logging.getLogger("WebSocketFactory")
|
|
||||||
|
|
||||||
|
|
||||||
class WebSocketFactory:
|
class WebSocketFactory:
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,7 @@ import logging
|
||||||
from okx.websocket import WsUtils
|
from okx.websocket import WsUtils
|
||||||
from okx.websocket.WebSocketFactory import WebSocketFactory
|
from okx.websocket.WebSocketFactory import WebSocketFactory
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logger = logging.getLogger(__name__)
|
||||||
logger = logging.getLogger("WsPrivate")
|
|
||||||
|
|
||||||
|
|
||||||
class WsPrivateAsync:
|
class WsPrivateAsync:
|
||||||
|
|
@ -26,7 +25,7 @@ class WsPrivateAsync:
|
||||||
|
|
||||||
async def consume(self):
|
async def consume(self):
|
||||||
async for message in self.websocket:
|
async for message in self.websocket:
|
||||||
logger.info("Received message: {%s}", message)
|
logger.debug("Received message: {%s}", message)
|
||||||
if self.callback:
|
if self.callback:
|
||||||
self.callback(message)
|
self.callback(message)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ import logging
|
||||||
|
|
||||||
from okx.websocket.WebSocketFactory import WebSocketFactory
|
from okx.websocket.WebSocketFactory import WebSocketFactory
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logger = logging.getLogger(__name__)
|
||||||
logger = logging.getLogger("WsPublic")
|
|
||||||
|
|
||||||
|
|
||||||
class WsPublicAsync:
|
class WsPublicAsync:
|
||||||
|
|
@ -21,7 +20,7 @@ class WsPublicAsync:
|
||||||
|
|
||||||
async def consume(self):
|
async def consume(self):
|
||||||
async for message in self.websocket:
|
async for message in self.websocket:
|
||||||
logger.info("Received message: {%s}", message)
|
logger.debug("Received message: {%s}", message)
|
||||||
if self.callback:
|
if self.callback:
|
||||||
self.callback(message)
|
self.callback(message)
|
||||||
|
|
||||||
|
|
|
||||||
1
setup.py
1
setup.py
|
|
@ -22,6 +22,7 @@ setuptools.setup(
|
||||||
"importlib-metadata",
|
"importlib-metadata",
|
||||||
"httpx[http2]",
|
"httpx[http2]",
|
||||||
"keyring",
|
"keyring",
|
||||||
|
"loguru",
|
||||||
"requests",
|
"requests",
|
||||||
"Twisted",
|
"Twisted",
|
||||||
"pyOpenSSL"
|
"pyOpenSSL"
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
from okx import Account
|
from okx import Account
|
||||||
|
|
||||||
|
|
||||||
class AccountTest(unittest.TestCase):
|
class AccountTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
proxy = "http://43.152.113.72:19206"
|
api_key = '52049394-3c72-4c06-8d87-d6399450c264'
|
||||||
api_key = 'your_apiKey'
|
api_secret_key = 'E532EB5AF81E6E50A2875225FEDC9150'
|
||||||
api_secret_key = 'your_secretKey'
|
passphrase = 'Fixedloan2024!'
|
||||||
passphrase = 'your_secretKey'
|
self.AccountAPI = Account.AccountAPI(api_key, api_secret_key, passphrase, flag='1')
|
||||||
self.AccountAPI = Account.AccountAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1', proxy=proxy)
|
|
||||||
|
|
||||||
# '''
|
# '''
|
||||||
# POSITIONS_HISTORY = '/api/v5/account/positions-history' #need add
|
# POSITIONS_HISTORY = '/api/v5/account/positions-history' #need add
|
||||||
|
|
@ -23,6 +24,10 @@ class AccountTest(unittest.TestCase):
|
||||||
# positions-history
|
# positions-history
|
||||||
# def test_get_positions_history(self):
|
# def test_get_positions_history(self):
|
||||||
# print(self.AccountAPI.get_positions_history())
|
# print(self.AccountAPI.get_positions_history())
|
||||||
|
# def test_get_instruments(self):
|
||||||
|
# print(self.AccountAPI.get_instruments(instType='SPOT'))
|
||||||
|
# def test_get_account_bills_archive(self):
|
||||||
|
# print(self.AccountAPI.get_account_bills_archive(begin='1715780962300',end='1716998400000'))
|
||||||
# def test_positions_builder(self):
|
# def test_positions_builder(self):
|
||||||
# print("Both real and virtual positions and assets are calculated")
|
# 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_pos = [{'instId': 'BTC-USDT-SWAP', 'pos': '10'}, {'instId': 'BTC-USDT-SWAP', 'pos': '10'}]
|
||||||
|
|
@ -120,7 +125,27 @@ class AccountTest(unittest.TestCase):
|
||||||
|
|
||||||
# def test_simulated_margin(self):
|
# def test_simulated_margin(self):
|
||||||
# print(self.AccountAPI.get_simulated_margin(spotOffsetType='3'))
|
# print(self.AccountAPI.get_simulated_margin(spotOffsetType='3'))
|
||||||
|
# def test_get_fix_loan_borrowing_limit(self):
|
||||||
|
# logger.debug(f'{self.AccountAPI.get_fix_loan_borrowing_limit()}')
|
||||||
|
# def test_get_fix_loan_borrowing_quote(self):
|
||||||
|
# logger.debug(f'{self.AccountAPI.get_fix_loan_borrowing_quote(type="normal")}')
|
||||||
|
# def test_place_fix_loan_borrowing_order(self):
|
||||||
|
# logger.debug(f'{self.AccountAPI.place_fix_loan_borrowing_order(ccy="BTC", amt="0.1515", maxRate="0.001", term="30D", reborrow=True, reborrowRate="0.01")}')
|
||||||
|
# def test_amend_fix_loan_borrowing_order(self):
|
||||||
|
# logger.debug(f'{self.AccountAPI.amend_fix_loan_borrowing_order(ordId="2407301043344857",reborrow=True,renewMaxRate="0.01")}')
|
||||||
|
# def test_fix_loan_manual_reborrow(self):
|
||||||
|
# logger.debug(f'{self.AccountAPI.fix_loan_manual_reborrow(ordId="2407301043344857",maxRate="0.1")}')
|
||||||
|
# def test_repay_fix_loan_borrowing_order(self):
|
||||||
|
# logger.info(f'{self.AccountAPI.repay_fix_loan_borrowing_order(ordId="2407301054407907")}')
|
||||||
|
# def test_get_fix_loan_borrowing_orders_list(self):
|
||||||
|
# logger.debug(self.AccountAPI.get_fix_loan_borrowing_orders_list(ordId="2407301054407907"))
|
||||||
|
|
||||||
|
# def test_spot_manual_borrow_repay(self):
|
||||||
|
# logger.debug(f'{self.AccountAPI.spot_manual_borrow_repay(ccy="USDT",side="borrow",amt=1)}')
|
||||||
|
# def test_set_auto_repay(self):
|
||||||
|
# logger.info(f'{self.AccountAPI.set_auto_repay(autoRepay=True)}')
|
||||||
|
# def test_spot_borrow_repay_history(self):
|
||||||
|
# logger.debug(self.AccountAPI.spot_borrow_repay_history(ccy="USDT",type="auto_borrow",after="1597026383085"))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,8 @@ class FundingTest(unittest.TestCase):
|
||||||
print(self.FundingAPI.get_lending_rate_summary('BTC'))
|
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):
|
# def test_get_lending_summary(self):
|
||||||
# print(self.FundingAPI.get_lending_rate_summary('BTC'))
|
# print(self.FundingAPI.get_lending_rate_summary('BTC'))
|
||||||
# def test_get_lending_rate_history(self):
|
# def test_get_lending_rate_history(self):
|
||||||
|
|
@ -66,8 +68,8 @@ class FundingTest(unittest.TestCase):
|
||||||
# def test_get_non_tradable_assets(self):
|
# def test_get_non_tradable_assets(self):
|
||||||
# print(self.FundingAPI.get_non_tradable_assets())
|
# print(self.FundingAPI.get_non_tradable_assets())
|
||||||
|
|
||||||
def test_get_deposit_withdraw_status(self):
|
# def test_get_deposit_withdraw_status(self):
|
||||||
print(self.FundingAPI.get_deposit_withdraw_status(wdId='84804812'))
|
# print(self.FundingAPI.get_deposit_withdraw_status(wdId='84804812'))
|
||||||
|
|
||||||
# def test_get_withdrawal_history(self):
|
# def test_get_withdrawal_history(self):
|
||||||
# print(self.FundingAPI.get_withdrawal_history())
|
# print(self.FundingAPI.get_withdrawal_history())
|
||||||
|
|
@ -75,8 +77,8 @@ class FundingTest(unittest.TestCase):
|
||||||
# def test_get_deposit_history(self):
|
# def test_get_deposit_history(self):
|
||||||
# print(self.FundingAPI.get_deposit_history())
|
# print(self.FundingAPI.get_deposit_history())
|
||||||
|
|
||||||
# def test_withdrawal(self):
|
def test_withdrawal(self):
|
||||||
# print(self.FundingAPI.withdrawal(ccy='USDT',amt='1',dest='3',toAddr='18740405107',fee='0',areaCode='86'))
|
print(self.FundingAPI.withdrawal(ccy='USDT',amt='1',dest='3',toAddr='18740405107',areaCode='86'))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
from okx import Account, SimpleEarnFixed
|
||||||
|
|
||||||
|
|
||||||
|
class SimpleEarnFixedTest(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
api_key = '15c0a341-f38c-4bf2-8f86-3c32c8b5d60c'
|
||||||
|
api_secret_key = 'DEBF51E2733E03CE4F2CEB63BB01D983'
|
||||||
|
passphrase = 'hylHYL950525,.'
|
||||||
|
self.SimpleEarnFixedAPI = SimpleEarnFixed.SimpleEarnFixedAPI(api_key, api_secret_key, passphrase, flag='1')
|
||||||
|
|
||||||
|
# def test_get_lending_offers(self):
|
||||||
|
# logger.debug(self.SimpleEarnFixedAPI.get_lending_offers())
|
||||||
|
#
|
||||||
|
# def test_get_instruments(self):
|
||||||
|
# logger.debug(self.SimpleEarnFixedAPI.get_lending_apy_history(ccy="BTC", term='30D'))
|
||||||
|
#
|
||||||
|
# def test_get_pending_lending_volume(self):
|
||||||
|
# logger.debug(self.SimpleEarnFixedAPI.get_pending_lending_volume(ccy="BTC", term='30D'))
|
||||||
|
#
|
||||||
|
# def test_place_lending_order(self):
|
||||||
|
# logger.debug(self.SimpleEarnFixedAPI.place_lending_order(ccy="USDT", amt="33", maxRate="1", term="30D"))
|
||||||
|
#
|
||||||
|
# def test_amend_lending_order(self):
|
||||||
|
# logger.debug(self.SimpleEarnFixedAPI.amend_lending_order(ordId="2407241551594080",changeAmt="30",autoRenewal=True))
|
||||||
|
#
|
||||||
|
# def test_get_lending_orders_list(self):
|
||||||
|
# logger.debug(self.SimpleEarnFixedAPI.get_lending_orders_list())
|
||||||
|
# def test_get_lending_sub_orders(self):
|
||||||
|
# logger.debug(self.SimpleEarnFixedAPI.get_lending_sub_orders(ordId="2407241453209933"))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
@ -125,8 +125,8 @@ class TradeTest(unittest.TestCase):
|
||||||
# print(self.tradeApi.get_orders_history("SPOT"))
|
# print(self.tradeApi.get_orders_history("SPOT"))
|
||||||
# def test_get_order_histry_archive(self):
|
# def test_get_order_histry_archive(self):
|
||||||
# print(self.tradeApi.orders_history_archive("SPOT"))
|
# print(self.tradeApi.orders_history_archive("SPOT"))
|
||||||
# def test_get_fills(self):
|
def test_get_fills(self):
|
||||||
# print(self.tradeApi.get_fills("SPOT"))
|
print(self.tradeApi.get_fills(begin='1717045609000',end='1717045609100'))
|
||||||
# def test_get_fills_history(self):
|
# def test_get_fills_history(self):
|
||||||
# print(self.tradeApi.get_fills_history("SPOT"))
|
# print(self.tradeApi.get_fills_history("SPOT"))
|
||||||
# def test_get_order_algo_pending(self):
|
# def test_get_order_algo_pending(self):
|
||||||
|
|
@ -163,7 +163,6 @@ class TradeTest(unittest.TestCase):
|
||||||
# print(self.tradeApi.get_oneclick_repay_list('cross'))
|
# print(self.tradeApi.get_oneclick_repay_list('cross'))
|
||||||
# def test_oneclick_repay(self):
|
# def test_oneclick_repay(self):
|
||||||
# print(self.tradeApi.oneclick_repay(['BTC'],'USDT'))
|
# print(self.tradeApi.oneclick_repay(['BTC'],'USDT'))
|
||||||
# """
|
|
||||||
# 485903392536264704
|
# 485903392536264704
|
||||||
# 485936482235191296
|
# 485936482235191296
|
||||||
# def test_oneclick_repay_history(self):
|
# def test_oneclick_repay_history(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue