feat: upgrade for proxy
This commit is contained in:
parent
db0bbb5546
commit
068c63d5c5
|
|
@ -4,8 +4,8 @@ from .consts import *
|
||||||
|
|
||||||
class AccountAPI(Client):
|
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):
|
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)
|
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy,timeout)
|
||||||
|
|
||||||
# Get Positions
|
# Get Positions
|
||||||
def get_position_risk(self, instType=''):
|
def get_position_risk(self, instType=''):
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ from .consts import *
|
||||||
|
|
||||||
|
|
||||||
class BlockTradingAPI(Client):
|
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):
|
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)
|
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||||
|
|
||||||
def counterparties(self):
|
def counterparties(self):
|
||||||
params = {}
|
params = {}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ from .consts import *
|
||||||
|
|
||||||
|
|
||||||
class ConvertAPI(Client):
|
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):
|
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)
|
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||||
|
|
||||||
def get_currencies(self):
|
def get_currencies(self):
|
||||||
params = {}
|
params = {}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,9 @@ from .consts import *
|
||||||
|
|
||||||
class CopyTradingAPI(Client):
|
class CopyTradingAPI(Client):
|
||||||
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):
|
domain='https://www.okx.com', debug=True, proxy=None):
|
||||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug)
|
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,
|
||||||
|
proxy=proxy)
|
||||||
|
|
||||||
# Get existing leading positions
|
# Get existing leading positions
|
||||||
def get_existing_leading_positions(self, instId=''):
|
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)
|
return self._request_with_params(GET, GET_LEADING_POSITIONS_HISTORY, params)
|
||||||
|
|
||||||
# Place leading stop order
|
# 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 = {
|
params = {
|
||||||
'subPosId': subPosId,
|
'subPosId': subPosId,
|
||||||
'tpTriggerPx': tpTriggerPx,
|
'tpTriggerPx': tpTriggerPx,
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ from .consts import *
|
||||||
|
|
||||||
|
|
||||||
class EarningAPI(Client):
|
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):
|
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)
|
Client.__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 = ''):
|
||||||
params = {
|
params = {
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ from .consts import *
|
||||||
|
|
||||||
|
|
||||||
class FDBrokerAPI(Client):
|
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):
|
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)
|
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 = ''):
|
def generate_rebate_details_download_link(self, begin ='', end = ''):
|
||||||
params = {'begin': begin, 'end': end}
|
params = {'begin': begin, 'end': end}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ from .consts import *
|
||||||
class FundingAPI(Client):
|
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):
|
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)
|
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||||
|
|
||||||
# Get Deposit Address
|
# Get Deposit Address
|
||||||
def get_deposit_address(self, ccy):
|
def get_deposit_address(self, ccy):
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ from .consts import *
|
||||||
|
|
||||||
|
|
||||||
class GridAPI(Client):
|
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):
|
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)
|
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='',
|
def grid_order_algo(self, instId='', algoOrdType='', maxPx='', minPx='', gridNum='', runType='', tpTriggerPx='',
|
||||||
slTriggerPx='', tag='', quoteSz='', baseSz='', sz='', direction='', lever='', basePos=''):
|
slTriggerPx='', tag='', quoteSz='', baseSz='', sz='', direction='', lever='', basePos=''):
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ from .consts import *
|
||||||
|
|
||||||
class MarketAPI(Client):
|
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):
|
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)
|
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||||
|
|
||||||
|
|
||||||
# Get Tickers
|
# Get Tickers
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
from .client import Client
|
from .client import Client
|
||||||
from .consts import *
|
from .consts import *
|
||||||
class NDBrokerAPI(Client):
|
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):
|
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)
|
Client.__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
|
||||||
def get_broker_info(self):
|
def get_broker_info(self):
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ from .consts import *
|
||||||
|
|
||||||
class PublicAPI(Client):
|
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):
|
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)
|
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||||
|
|
||||||
# Get Instruments
|
# Get Instruments
|
||||||
def get_instruments(self, instType, uly='', instId='',instFamily = ''):
|
def get_instruments(self, instType, uly='', instId='',instFamily = ''):
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ from .consts import *
|
||||||
|
|
||||||
class SpreadTradingAPI(Client):
|
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):
|
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)
|
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||||
|
|
||||||
# Place Order
|
# Place Order
|
||||||
def place_order(self, sprdId='', clOrdId='', tag='', side='', ordType='', sz='', px=''):
|
def place_order(self, sprdId='', clOrdId='', tag='', side='', ordType='', sz='', px=''):
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ from .consts import *
|
||||||
|
|
||||||
|
|
||||||
class StatusAPI(Client):
|
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):
|
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)
|
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||||
|
|
||||||
def status(self, state=''):
|
def status(self, state=''):
|
||||||
params = {'state': state}
|
params = {'state': state}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ from .consts import *
|
||||||
|
|
||||||
|
|
||||||
class SubAccountAPI(Client):
|
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):
|
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)
|
Client.__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):
|
||||||
params = {"subAcct": subAcct}
|
params = {"subAcct": subAcct}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ from .consts import *
|
||||||
|
|
||||||
class TradeAPI(Client):
|
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):
|
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)
|
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||||
|
|
||||||
# Place Order
|
# Place Order
|
||||||
def place_order(self, instId, tdMode, side, ordType, sz, ccy='', clOrdId='', tag='', posSide='', px='',
|
def place_order(self, instId, tdMode, side, ordType, sz, ccy='', clOrdId='', tag='', posSide='', px='',
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ from .consts import *
|
||||||
|
|
||||||
class TradingDataAPI(Client):
|
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):
|
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)
|
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||||
|
|
||||||
|
|
||||||
def get_support_coin(self):
|
def get_support_coin(self):
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
from httpx import Client
|
||||||
|
|
||||||
from . import consts as c, utils, exceptions
|
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_KEY = api_key
|
||||||
self.API_SECRET_KEY = api_secret_key
|
self.API_SECRET_KEY = api_secret_key
|
||||||
self.PASSPHRASE = passphrase
|
self.PASSPHRASE = passphrase
|
||||||
|
|
@ -15,7 +17,6 @@ class Client(object):
|
||||||
self.flag = flag
|
self.flag = flag
|
||||||
self.domain = base_api
|
self.domain = base_api
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.client = httpx.Client(base_url=base_api, http2=True)
|
|
||||||
|
|
||||||
def _request(self, method, request_path, params):
|
def _request(self, method, request_path, params):
|
||||||
if method == c.GET:
|
if method == c.GET:
|
||||||
|
|
@ -34,9 +35,9 @@ class Client(object):
|
||||||
print('domain:',self.domain)
|
print('domain:',self.domain)
|
||||||
print('url:',request_path)
|
print('url:',request_path)
|
||||||
if method == c.GET:
|
if method == c.GET:
|
||||||
response = self.client.get(request_path, headers=header)
|
response = self.get(request_path, headers=header)
|
||||||
elif method == c.POST:
|
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()
|
return response.json()
|
||||||
|
|
||||||
def _request_without_params(self, method, request_path):
|
def _request_without_params(self, method, request_path):
|
||||||
|
|
@ -47,7 +48,7 @@ class Client(object):
|
||||||
|
|
||||||
def _get_timestamp(self):
|
def _get_timestamp(self):
|
||||||
request_path = c.API_URL + c.SERVER_TIMESTAMP_URL
|
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:
|
if response.status_code == 200:
|
||||||
return response.json()['data'][0]['ts']
|
return response.json()['data'][0]['ts']
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,20 @@ from okx import Account
|
||||||
|
|
||||||
class AccountTest(unittest.TestCase):
|
class AccountTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
api_key = 'your_apiKey'
|
proxy = "http://125.106.203.126:10423";
|
||||||
api_secret_key = 'your_secretKey'
|
api_key = 'aee24256-7393-422f-90d9-47cc4028ce39'
|
||||||
passphrase = 'your_secretKey'
|
api_secret_key = 'FF517E627F6A702E2BF50F311F245D2A'
|
||||||
self.AccountAPI = Account.AccountAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1')
|
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
|
POSITIONS_HISTORY = '/api/v5/account/positions-history' #need add
|
||||||
GET_PM_LIMIT = '/api/v5/account/position-tiers' #need add
|
GET_PM_LIMIT = '/api/v5/account/position-tiers' #need add
|
||||||
ACCOUNT_RISK = '/api/v5/account/risk-state' #need add
|
ACCOUNT_RISK = '/api/v5/account/risk-state' #need add
|
||||||
def test_account_risk(self):
|
# def test_account_risk(self):
|
||||||
print(self.AccountAPI.get_account_risk())
|
# print(self.AccountAPI.get_account_risk())
|
||||||
|
#
|
||||||
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())
|
||||||
|
|
@ -72,7 +73,7 @@ class AccountTest(unittest.TestCase):
|
||||||
print(self.AccountAPI.get_simulated_margin())
|
print(self.AccountAPI.get_simulated_margin())
|
||||||
def test_get_greeks(self):
|
def test_get_greeks(self):
|
||||||
print(self.AccountAPI.get_greeks())
|
print(self.AccountAPI.get_greeks())
|
||||||
'''
|
# '''
|
||||||
# def test_simulated_margin(self):
|
# def test_simulated_margin(self):
|
||||||
# print(self.AccountAPI.get_simulated_margin())
|
# print(self.AccountAPI.get_simulated_margin())
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue