def default_parse_list_dict(inner_data, inner_class_name=object, default_value=None): from huobi.utils.print_mix_object import TypeCheck new_value = default_value if inner_data and len(inner_data): if (TypeCheck.is_list(inner_data)): new_value = fill_obj_list(inner_data, inner_class_name) elif (TypeCheck.is_dict(inner_data)): new_value = fill_obj(inner_data, inner_class_name) else: new_value = default_value return new_value
def check_response(dict_data): status = dict_data.get("status", None) code = dict_data.get("code", None) success = dict_data.get("success", None) if status and len(status): if TypeCheck.is_basic(status): # for normal case if status == "error": err_code = dict_data.get("err-code", 0) err_msg = dict_data.get("err-msg", "") raise HuobiApiException( HuobiApiException.EXEC_ERROR, "[Executing] " + str(err_code) + ": " + err_msg) elif status != "ok": raise HuobiApiException( HuobiApiException.RUNTIME_ERROR, "[Invoking] Response is not expected: " + status) elif TypeCheck.is_dict( status ): # for https://status.huobigroup.com/api/v2/summary.json in example example/generic/get_system_status.py if dict_data.get("page") and dict_data.get("components"): pass else: raise HuobiApiException( HuobiApiException.EXEC_ERROR, "[Executing] System is in maintenances") elif code: code_int = int(code) if code_int != 200: err_code = dict_data.get("code", 0) err_msg = dict_data.get("message", "") raise HuobiApiException( HuobiApiException.EXEC_ERROR, "[Executing] " + str(err_code) + ": " + err_msg) elif success is not None: if bool(success) is False: err_code = etf_result_check(dict_data.get("code")) err_msg = dict_data.get("message", "") if err_code == "": raise HuobiApiException(HuobiApiException.EXEC_ERROR, "[Executing] " + err_msg) else: raise HuobiApiException( HuobiApiException.EXEC_ERROR, "[Executing] " + str(err_code) + ": " + err_msg) else: raise HuobiApiException( HuobiApiException.RUNTIME_ERROR, "[Invoking] Status cannot be found in response.")
def default_parse(dict_data, outer_class_name=object, inner_class_name=object): from huobi.utils.print_mix_object import TypeCheck rsp_obj = outer_class_name() for outer_key, outer_value in dict_data.items(): obj_key = key_trans(outer_key) #print("===", outer_key, obj_key, str(outer_value)) #PrintBasic.print_basic_bool(hasattr(rsp_obj, obj_key)) if hasattr(rsp_obj, obj_key): new_value = outer_value #print("==========", type(outer_value), outer_value) if (TypeCheck.is_list(outer_value)): new_value = fill_obj_list(outer_value, inner_class_name) elif (TypeCheck.is_dict(outer_value)): new_value = fill_obj(outer_value, inner_class_name) setattr(rsp_obj, obj_key, new_value) continue return rsp_obj