supported new features, fixed loan & earn

This commit is contained in:
007live 2024-08-07 10:03:32 +08:00
parent 2a796ab74d
commit f983c5bc2d
9 changed files with 307 additions and 62 deletions

View File

@ -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=None, 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) 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='',begin='',end=''): 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,'begin':begin,'end':end} '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
@ -80,18 +83,19 @@ class AccountAPI(OkxClient):
return self._request_with_params(GET, MAX_AVAIL_SIZE, params) return self._request_with_params(GET, MAX_AVAIL_SIZE, params)
# Increase / Decrease margin # Increase / Decrease margin
def adjustment_margin(self, instId, posSide, type, amt,loanTrans=''): def adjustment_margin(self, instId, posSide, type, amt, loanTrans=''):
params = {'instId': instId, 'posSide': posSide, 'type': type, 'amt': amt,'loanTrans':loanTrans} params = {'instId': instId, 'posSide': posSide, 'type': type, 'amt': amt, 'loanTrans': loanTrans}
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, instId, mgnMode):
params = {'instId': instId, 'mgnMode': mgnMode} params = {'instId': instId, 'mgnMode': mgnMode}
return self._request_with_params(GET, GET_LEVERAGE, params) return self._request_with_params(GET, GET_LEVERAGE, params)
# Get instruments # Get instruments
def get_instruments(self, instType='', ugly = '',instFamily='',instId=''): def get_instruments(self, instType='', ugly='', instFamily='', instId=''):
params = {'instType': instType, 'ugly': ugly, 'instFamily': instFamily, 'instId': instId} params = {'instType': instType, 'ugly': ugly, 'instFamily': instFamily, 'instId': instId}
return self._request_with_params(GET,GET_INSTRUMENTS,params) 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):
@ -99,8 +103,8 @@ class AccountAPI(OkxClient):
return self._request_with_params(GET, MAX_LOAN, params) return self._request_with_params(GET, MAX_LOAN, params)
# Get Fee Rates # Get Fee Rates
def get_fee_rates(self, instType, instId='', uly='', category='',instFamily = ''): def get_fee_rates(self, instType, instId='', uly='', category='', instFamily=''):
params = {'instType': instType, 'instId': instId, 'uly': uly, 'category': category,'instFamily':instFamily} params = {'instType': instType, 'instId': instId, 'uly': uly, 'category': category, 'instFamily': instFamily}
return self._request_with_params(GET, FEE_RATES, params) return self._request_with_params(GET, FEE_RATES, params)
# Get interest-accrued # Get interest-accrued
@ -119,8 +123,8 @@ class AccountAPI(OkxClient):
return self._request_with_params(POST, SET_GREEKS, params) return self._request_with_params(POST, SET_GREEKS, params)
# Set Isolated Mode # Set Isolated Mode
def set_isolated_mode(self, isoMode,type): def set_isolated_mode(self, isoMode, type):
params = {'isoMode': isoMode, 'type':type} params = {'isoMode': isoMode, 'type': type}
return self._request_with_params(POST, ISOLATED_MODE, params) return self._request_with_params(POST, ISOLATED_MODE, params)
# Get Maximum Withdrawals # Get Maximum Withdrawals
@ -135,11 +139,11 @@ class AccountAPI(OkxClient):
# Get borrow repay history # Get borrow repay history
def get_borrow_repay_history(self, ccy='', after='', before='', limit=''): def get_borrow_repay_history(self, ccy='', after='', before='', limit=''):
params = {'ccy': ccy, 'after': after, 'before': before, 'limit':limit} params = {'ccy': ccy, 'after': after, 'before': before, 'limit': limit}
return self._request_with_params(GET, BORROW_REPAY_HISTORY, params) return self._request_with_params(GET, BORROW_REPAY_HISTORY, params)
# Get Obtain borrowing rate and limit # Get Obtain borrowing rate and limit
def get_interest_limits(self, type='',ccy=''): def get_interest_limits(self, type='', ccy=''):
params = {'type': type, 'ccy': ccy} params = {'type': type, 'ccy': ccy}
return self._request_with_params(GET, INTEREST_LIMITS, params) return self._request_with_params(GET, INTEREST_LIMITS, params)
@ -153,57 +157,58 @@ class AccountAPI(OkxClient):
params = {'ccy': ccy} params = {'ccy': ccy}
return self._request_with_params(GET, GREEKS, params) return self._request_with_params(GET, GREEKS, params)
#GET /api/v5/account/risk-state # GET /api/v5/account/risk-state
def get_account_position_risk(self): def get_account_position_risk(self):
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,
'mgnMode':mgnMode, 'mgnMode': mgnMode,
'type':type, 'type': type,
'posId':posId, 'posId': posId,
'after':after, 'after': after,
'before':before, 'before': before,
'limit':limit 'limit': limit
} }
return self._request_with_params(GET,POSITIONS_HISTORY,params) return self._request_with_params(GET, POSITIONS_HISTORY, params)
#GET /api/v5/account/position-tiers # GET /api/v5/account/position-tiers
def get_account_position_tiers(self,instType = '', uly = '',instFamily = ''): def get_account_position_tiers(self, instType='', uly='', instFamily=''):
params = { params = {
'instType':instType, 'instType': instType,
'uly':uly, 'uly': uly,
'instFamily':instFamily 'instFamily': instFamily
} }
return self._request_with_params(GET,GET_PM_LIMIT,params) return self._request_with_params(GET, GET_PM_LIMIT, params)
#- Get VIP interest accrued data # - Get VIP interest accrued data
def get_VIP_interest_accrued_data(self, ccy='', ordId='', after='', before='', limit=''): def get_VIP_interest_accrued_data(self, ccy='', ordId='', after='', before='', limit=''):
params = {'ccy': ccy, 'ordId': ordId, 'after': after, 'before': before, 'limit': limit} params = {'ccy': ccy, 'ordId': ordId, 'after': after, 'before': before, 'limit': limit}
return self._request_with_params(GET, GET_VIP_INTEREST_ACCRUED_DATA, params) return self._request_with_params(GET, GET_VIP_INTEREST_ACCRUED_DATA, params)
#- Get VIP interest deducted data # - Get VIP interest deducted data
def get_VIP_interest_deducted_data(self, ccy='', ordId='', after='', before='', limit=''): def get_VIP_interest_deducted_data(self, ccy='', ordId='', after='', before='', limit=''):
params = {'ccy': ccy, 'ordId': ordId, 'after': after, 'before': before, 'limit': limit} params = {'ccy': ccy, 'ordId': ordId, 'after': after, 'before': before, 'limit': limit}
return self._request_with_params(GET, GET_VIP_INTEREST_DEDUCTED_DATA, params) return self._request_with_params(GET, GET_VIP_INTEREST_DEDUCTED_DATA, params)
# - Get VIP loan order list # - Get VIP loan order list
def get_VIP_loan_order_list(self, ordId='',state='', ccy='', after='', before='', limit=''): def get_VIP_loan_order_list(self, ordId='', state='', ccy='', after='', before='', limit=''):
params = {'ordId': ordId, 'state': state, 'ccy': ccy,'after': after, 'before': before, 'limit': limit} params = {'ordId': ordId, 'state': state, 'ccy': ccy, 'after': after, 'before': before, 'limit': limit}
return self._request_with_params(GET, GET_VIP_LOAN_ORDER_LIST, params) return self._request_with_params(GET, GET_VIP_LOAN_ORDER_LIST, params)
#- Get VIP loan order detail # - Get VIP loan order detail
def get_VIP_loan_order_detail(self, ccy='', ordId='', after='', before='', limit=''): def get_VIP_loan_order_detail(self, ccy='', ordId='', after='', before='', limit=''):
params = {'ccy': ccy, 'ordId': ordId, 'after': after, 'before': before, 'limit': limit} params = {'ccy': ccy, 'ordId': ordId, 'after': after, 'before': before, 'limit': limit}
return self._request_with_params(GET, GET_VIP_LOAN_ORDER_DETAIL, params) return self._request_with_params(GET, GET_VIP_LOAN_ORDER_DETAIL, params)
#- Set risk offset type # - Set risk offset type
def set_risk_offset_typel(self, type=''): def set_risk_offset_typel(self, type=''):
params = {'type': type} params = {'type': type}
return self._request_with_params(POST, SET_RISK_OFFSET_TYPE,params) return self._request_with_params(POST, SET_RISK_OFFSET_TYPE, params)
# - Set auto loan # - Set auto loan
def set_auto_loan(self, autoLoan=''): def set_auto_loan(self, autoLoan=''):
@ -212,6 +217,80 @@ class AccountAPI(OkxClient):
} }
return self._request_with_params(POST, SET_AUTO_LOAN, params) return self._request_with_params(POST, SET_AUTO_LOAN, params)
#- 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)

91
okx/SimpleEarnFixed.py Normal file
View File

@ -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=True, 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)

View File

@ -2,4 +2,4 @@
Python SDK for the OKX API v5 Python SDK for the OKX API v5
""" """
__version__="0.3.0" __version__="0.3.2"

View File

@ -55,6 +55,13 @@ 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' 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'
# funding-complete-testcomplete # funding-complete-testcomplete
NON_TRADABLE_ASSETS = '/api/v5/asset/non-tradable-assets' NON_TRADABLE_ASSETS = '/api/v5/asset/non-tradable-assets'
@ -292,3 +299,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'

View File

@ -6,6 +6,8 @@ import httpx
from httpx import Client from httpx import Client
from datetime import datetime, timezone from datetime import datetime, timezone
from loguru import logger
from . import consts as c, utils, exceptions from . import consts as c, utils, exceptions
@ -37,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:

View File

@ -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

View File

@ -22,6 +22,7 @@ setuptools.setup(
"importlib-metadata", "importlib-metadata",
"httpx[http2]", "httpx[http2]",
"keyring", "keyring",
"loguru",
"requests", "requests",
"Twisted", "Twisted",
"pyOpenSSL" "pyOpenSSL"

View File

@ -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
@ -21,12 +22,12 @@ class AccountTest(unittest.TestCase):
# def test_get_pm_limit(self): # def test_get_pm_limit(self):
# print(self.AccountAPI.get_pm_limit("SWAP","BTC-USDT")) # print(self.AccountAPI.get_pm_limit("SWAP","BTC-USDT"))
# 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): # def test_get_instruments(self):
print(self.AccountAPI.get_instruments(instType='SPOT')) # print(self.AccountAPI.get_instruments(instType='SPOT'))
def test_get_account_bills_archive(self): # def test_get_account_bills_archive(self):
print(self.AccountAPI.get_account_bills_archive(begin='1715780962300',end='1716998400000')) # 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'}]
@ -124,7 +125,20 @@ 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"))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -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()