Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3.9 compatible #85

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions huobi/connection/impl/restapi_invoker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

session = requests.Session()


def json_loads(text, encoding='utf-8'):
from sys import version_info
if version_info.major > 3:
return json.loads(text)
if version_info.minor > 7:
return json.loads(text)
return json.loads(text, encoding=encoding)


def check_response(dict_data):
status = dict_data.get("status", None)
code = dict_data.get("code", None)
Expand Down Expand Up @@ -53,30 +63,31 @@ def call_sync(request, is_checked=False):
response = session.get(request.host + request.url, headers=request.header)
if is_checked is True:
return response.text
dict_data = json.loads(response.text, encoding="utf-8")
dict_data = json_loads(response.text)
# print("call_sync === recv data : ", dict_data)
check_response(dict_data)
return request.json_parser(dict_data)

elif request.method == "POST":
response = session.post(request.host + request.url, data=json.dumps(request.post_body), headers=request.header)
dict_data = json.loads(response.text, encoding="utf-8")
dict_data = json_loads(response.text)
# print("call_sync === recv data : ", dict_data)
check_response(dict_data)
return request.json_parser(dict_data)


def call_sync_perforence_test(request, is_checked=False):
if request.method == "GET":
inner_start_time = time.time()
# print("call_sync_perforence_test url : ", request.host + request.url)
response = session.get(request.host + request.url, headers=request.header)
#print("call_sync_perforence_test data :", response.text)
# print("call_sync_perforence_test data :", response.text)
inner_end_time = time.time()
cost_manual = round(inner_end_time - inner_start_time, 6)
req_cost = response.elapsed.total_seconds()
if is_checked is True:
return response.text
dict_data = json.loads(response.text, encoding="utf-8")
dict_data = json_loads(response.text)
# print("call_sync === recv data : ", dict_data)
check_response(dict_data)
return request.json_parser(dict_data), req_cost, cost_manual
Expand All @@ -87,7 +98,7 @@ def call_sync_perforence_test(request, is_checked=False):
inner_end_time = time.time()
cost_manual = round(inner_end_time - inner_start_time, 6)
req_cost = response.elapsed.total_seconds()
dict_data = json.loads(response.text, encoding="utf-8")
dict_data = json_loads(response.text)
# print("call_sync === recv data : ", dict_data)
check_response(dict_data)
return request.json_parser(dict_data), req_cost, cost_manual