feat: upgrade for proxy

This commit is contained in:
007live 2024-01-25 15:23:13 +08:00
parent db0bbb5546
commit 068c63d5c5
18 changed files with 54 additions and 50 deletions

View File

@ -4,8 +4,8 @@ from .consts import *
class AccountAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain,debug)
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,timeout = 30):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy,timeout)
# Get Positions
def get_position_risk(self, instType=''):

View File

@ -3,8 +3,8 @@ from .consts import *
class BlockTradingAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain,debug)
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
def counterparties(self):
params = {}

View File

@ -3,8 +3,8 @@ from .consts import *
class ConvertAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain,debug)
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
def get_currencies(self):
params = {}

View File

@ -4,8 +4,9 @@ from .consts import *
class CopyTradingAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug)
domain='https://www.okx.com', debug=True, proxy=None):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,
proxy=proxy)
# Get existing leading positions
def get_existing_leading_positions(self, instId=''):
@ -25,7 +26,8 @@ class CopyTradingAPI(Client):
return self._request_with_params(GET, GET_LEADING_POSITIONS_HISTORY, params)
# Place leading stop order
def place_leading_stop_order(self, subPosId='', tpTriggerPx='', slTriggerPx='', tpTriggerPxType='', slTriggerPxType=''):
def place_leading_stop_order(self, subPosId='', tpTriggerPx='', slTriggerPx='', tpTriggerPxType='',
slTriggerPxType=''):
params = {
'subPosId': subPosId,
'tpTriggerPx': tpTriggerPx,

View File

@ -3,8 +3,8 @@ from .consts import *
class EarningAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug)
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
def get_offers(self,productId = '',protocolType = '',ccy = ''):
params = {

View File

@ -3,8 +3,8 @@ from .consts import *
class FDBrokerAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain,debug)
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
def generate_rebate_details_download_link(self, begin ='', end = ''):
params = {'begin': begin, 'end': end}

View File

@ -5,8 +5,8 @@ from .consts import *
class FundingAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain,debug)
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
# Get Deposit Address
def get_deposit_address(self, ccy):

View File

@ -3,8 +3,8 @@ from .consts import *
class GridAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain,debug)
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):
Client.__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='',
slTriggerPx='', tag='', quoteSz='', baseSz='', sz='', direction='', lever='', basePos=''):

View File

@ -4,8 +4,8 @@ from .consts import *
class MarketAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain,debug)
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
# Get Tickers

View File

@ -1,8 +1,8 @@
from .client import Client
from .consts import *
class NDBrokerAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain,debug)
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
#GET /api/v5/broker/nd/info
def get_broker_info(self):

View File

@ -4,8 +4,8 @@ from .consts import *
class PublicAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain,debug)
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
# Get Instruments
def get_instruments(self, instType, uly='', instId='',instFamily = ''):

View File

@ -4,8 +4,8 @@ from .consts import *
class SpreadTradingAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain,debug)
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
# Place Order
def place_order(self, sprdId='', clOrdId='', tag='', side='', ordType='', sz='', px=''):

View File

@ -3,8 +3,8 @@ from .consts import *
class StatusAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain,debug)
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
def status(self, state=''):
params = {'state': state}

View File

@ -3,8 +3,8 @@ from .consts import *
class SubAccountAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain,debug)
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
def get_account_balance(self, subAcct):
params = {"subAcct": subAcct}

View File

@ -4,8 +4,8 @@ from .consts import *
class TradeAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain,debug)
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
# Place Order
def place_order(self, instId, tdMode, side, ordType, sz, ccy='', clOrdId='', tag='', posSide='', px='',

View File

@ -4,8 +4,8 @@ from .consts import *
class TradingDataAPI(Client):
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain,debug)
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):
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
def get_support_coin(self):

View File

@ -1,13 +1,15 @@
import json
import httpx
from httpx import Client
from . import consts as c, utils, exceptions
class Client(object):
class Client(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'):
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):
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
@ -15,7 +17,6 @@ class Client(object):
self.flag = flag
self.domain = base_api
self.debug = debug
self.client = httpx.Client(base_url=base_api, http2=True)
def _request(self, method, request_path, params):
if method == c.GET:
@ -34,9 +35,9 @@ class Client(object):
print('domain:',self.domain)
print('url:',request_path)
if method == c.GET:
response = self.client.get(request_path, headers=header)
response = self.get(request_path, headers=header)
elif method == c.POST:
response = self.client.post(request_path, data=body, headers=header)
response = self.post(request_path, data=body, headers=header)
return response.json()
def _request_without_params(self, method, request_path):
@ -47,7 +48,7 @@ class Client(object):
def _get_timestamp(self):
request_path = c.API_URL + c.SERVER_TIMESTAMP_URL
response = self.client.get(request_path)
response = self.get(request_path)
if response.status_code == 200:
return response.json()['data'][0]['ts']
else:

View File

@ -4,19 +4,20 @@ from okx import Account
class AccountTest(unittest.TestCase):
def setUp(self):
api_key = 'your_apiKey'
api_secret_key = 'your_secretKey'
passphrase = 'your_secretKey'
self.AccountAPI = Account.AccountAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1')
'''
proxy = "http://125.106.203.126:10423";
api_key = 'aee24256-7393-422f-90d9-47cc4028ce39'
api_secret_key = 'FF517E627F6A702E2BF50F311F245D2A'
passphrase = 'hylHYL950525,.'
self.AccountAPI = Account.AccountAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1',proxy=proxy,timeout=30)
# '''
POSITIONS_HISTORY = '/api/v5/account/positions-history' #need add
GET_PM_LIMIT = '/api/v5/account/position-tiers' #need add
ACCOUNT_RISK = '/api/v5/account/risk-state' #need add
def test_account_risk(self):
print(self.AccountAPI.get_account_risk())
def test_get_pm_limit(self):
print(self.AccountAPI.get_pm_limit("SWAP","BTC-USDT"))
# def test_account_risk(self):
# print(self.AccountAPI.get_account_risk())
#
# 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())
@ -72,7 +73,7 @@ class AccountTest(unittest.TestCase):
print(self.AccountAPI.get_simulated_margin())
def test_get_greeks(self):
print(self.AccountAPI.get_greeks())
'''
# '''
# def test_simulated_margin(self):
# print(self.AccountAPI.get_simulated_margin())