update version
This commit is contained in:
parent
b414a60057
commit
e3fa532aed
|
|
@ -2,4 +2,4 @@
|
||||||
Python SDK for the OKX API v5
|
Python SDK for the OKX API v5
|
||||||
|
|
||||||
"""
|
"""
|
||||||
__version__="0.1.5"
|
__version__="0.1.6"
|
||||||
|
|
@ -1,18 +1,17 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import httpx
|
|
||||||
|
|
||||||
from . import consts as c, utils, exceptions
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
import httpx
|
||||||
from httpx import _client
|
from httpx import _client
|
||||||
|
|
||||||
|
from . import consts as c, utils
|
||||||
|
|
||||||
|
|
||||||
class Client(object):
|
class Client(object):
|
||||||
|
|
||||||
def __init__(self, api_key = '-1', api_secret_key = '-1', passphrase = '-1', use_server_time=False, flag='1', base_api = 'https://www.okx.com',debug = False):
|
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1',
|
||||||
|
base_api=c.DOMAIN, debug=False):
|
||||||
|
|
||||||
self.API_KEY = api_key
|
self.API_KEY = api_key
|
||||||
self.API_SECRET_KEY = api_secret_key
|
self.API_SECRET_KEY = api_secret_key
|
||||||
|
|
@ -32,25 +31,24 @@ class Client(object):
|
||||||
timestamp = self._get_timestamp()
|
timestamp = self._get_timestamp()
|
||||||
body = json.dumps(params) if method == c.POST else ""
|
body = json.dumps(params) if method == c.POST else ""
|
||||||
if self.API_KEY != '-1':
|
if self.API_KEY != '-1':
|
||||||
sign = utils.sign(utils.pre_hash(timestamp, method, request_path, str(body), self.debug), self.API_SECRET_KEY)
|
sign = utils.sign(utils.pre_hash(timestamp, method, request_path, str(body), self.debug),
|
||||||
|
self.API_SECRET_KEY)
|
||||||
header = utils.get_header(self.API_KEY, sign, timestamp, self.PASSPHRASE, self.flag, self.debug)
|
header = utils.get_header(self.API_KEY, sign, timestamp, self.PASSPHRASE, self.flag, self.debug)
|
||||||
else:
|
else:
|
||||||
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:
|
||||||
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.client.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.client.post(request_path, data=body, headers=header)
|
||||||
self.request_times += 1
|
self.request_times += 1
|
||||||
# print('request times:', self.request_times)
|
if self.request_times > 512:
|
||||||
if (self.request_times > 512):
|
|
||||||
self.client.close()
|
self.client.close()
|
||||||
self.client._state = _client.ClientState.UNOPENED
|
self.client._state = _client.ClientState.UNOPENED
|
||||||
self.request_times = 0
|
self.request_times = 0
|
||||||
# print('close the current tcp connection while request times larger than 512.')
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def _request_until_success(self, method, request_path, params):
|
def _request_until_success(self, method, request_path, params):
|
||||||
|
|
@ -67,13 +65,11 @@ class Client(object):
|
||||||
continue
|
continue
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = traceback.format_exc()
|
traceback.format_exc()
|
||||||
print(e)
|
print(e)
|
||||||
retry_times += 1
|
retry_times += 1
|
||||||
print('http request retry in 1 seconds, retry times:', retry_times)
|
print('http request retry in 1 seconds, retry times:', retry_times)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
# if not str(response.status_code).startswith('2'):
|
|
||||||
# raise exceptions.OkxAPIException(response)
|
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
def _request_without_params(self, method, request_path):
|
def _request_without_params(self, method, request_path):
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
# http header
|
# http header
|
||||||
#API_URL = 'https://www.okx.com'
|
DOMAIN = 'https://www.okx.com'
|
||||||
|
|
||||||
CONTENT_TYPE = 'Content-Type'
|
CONTENT_TYPE = 'Content-Type'
|
||||||
OK_ACCESS_KEY = 'OK-ACCESS-KEY'
|
OK_ACCESS_KEY = 'OK-ACCESS-KEY'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue