Пример #1
0
def check_symbol(symbol):
    if not isinstance(symbol, str):
        raise BinanceApiException(BinanceApiException.INPUT_ERROR,
                                  "[Input] symbol must be string")
    if re.match(reg_ex, symbol):
        raise BinanceApiException(BinanceApiException.INPUT_ERROR,
                                  "[Input] " + symbol + "  is invalid symbol")
Пример #2
0
def check_currency(currency):
    if not isinstance(currency, str):
        raise BinanceApiException(BinanceApiException.INPUT_ERROR,
                                  "[Input] currency must be string")
    if re.match(reg_ex, currency) is not None:
        raise BinanceApiException(
            BinanceApiException.INPUT_ERROR,
            "[Input] " + currency + "  is invalid currency")
Пример #3
0
def check_list(list_value, min_value, max_value, name):
    if list_value is None:
        return
    if len(list_value) > max_value:
        raise BinanceApiException(BinanceApiException.INPUT_ERROR,
                                "[Input] " + name + " is out of bound, the max size is " + str(max_value))
    if len(list_value) < min_value:
        raise BinanceApiException(BinanceApiException.INPUT_ERROR,
                                "[Input] " + name + " should contain " + str(min_value) + " item(s) at least")
Пример #4
0
def format_date(value, name):
    if value is None:
        return None
    if not isinstance(value, str):
        raise BinanceApiException(BinanceApiException.INPUT_ERROR, "[Input] " + name + " must be string")
    try:
        new_time = time.strptime(value, "%Y-%m-%d")
        return time.strftime("%Y-%m-%d", new_time)
    except:
        raise BinanceApiException(BinanceApiException.INPUT_ERROR, "[Input] " + name + " is not invalid date format")
def check_response(json_wrapper):
    if json_wrapper.contain_key("success"):
        success = json_wrapper.get_boolean("success")
        if success is False:
            err_code = json_wrapper.get_int_or_default("code", "")
            err_msg = json_wrapper.get_string_or_default("msg", "")
            if err_code == "":
                raise BinanceApiException(BinanceApiException.EXEC_ERROR, "[Executing] " + err_msg)
            else:
                raise BinanceApiException(BinanceApiException.EXEC_ERROR, "[Executing] " + str(err_code) + ": " + err_msg)
    elif json_wrapper.contain_key("code"):
        code = json_wrapper.get_int("code")
        msg = json_wrapper.get_string_or_default("msg", "")
        if code != 200 and code != -2011:
            raise BinanceApiException(BinanceApiException.EXEC_ERROR, "[Executing] " + str(code) + ": " + msg)
Пример #6
0
 def on_error(self, error_message):
     if self.request.error_handler is not None:
         print('error')
         exception = BinanceApiException(
             BinanceApiException.SUBSCRIPTION_ERROR, error_message)
         self.request.error_handler(exception)
     self.logger.error("[Sub][" + str(self.id) + "] " + str(error_message))
Пример #7
0
def check_range(value, min_value, max_value, name):
    if value is None:
        return
    if min_value > value or value > max_value:
        raise BinanceApiException(BinanceApiException.INPUT_ERROR,
                                "[Input] " + name + " is out of bound. " + str(value) + " is not in [" + str(
                                    min_value) + "," + str(max_value) + "]")
Пример #8
0
def check_symbol_list(symbols):
    if not isinstance(symbols, list):
        raise BinanceApiException(
            BinanceApiException.INPUT_ERROR,
            "[Input] symbols in subscription is not a list")
    for symbol in symbols:
        check_symbol(symbol)
Пример #9
0
def create_signature_with_query(secret_key, query):
    if secret_key is None or secret_key == "":
        raise BinanceApiException(BinanceApiException.KEY_MISSING,  "Secret key are required")

    signature = hmac.new(secret_key.encode(), msg=query.encode(), digestmod=hashlib.sha256).hexdigest()
    
    return signature
Пример #10
0
def create_signature(secret_key, builder):
    if secret_key is None or secret_key == "":
        raise BinanceApiException(BinanceApiException.KEY_MISSING,  "Secret key are required")

#    keys = builder.param_map.keys()
#    query_string = '&'.join(['%s=%s' % (key, parse.quote(builder.param_map[key], safe='')) for key in keys])
    query_string = builder.build_url()
    signature = hmac.new(secret_key.encode(), msg=query_string.encode(), digestmod=hashlib.sha256).hexdigest()
    builder.put_url("signature", signature)
Пример #11
0
def greater_or_equal(value, base, name):
    if value is not None and value < base:
        raise BinanceApiException(BinanceApiException.INPUT_ERROR,
                                "[Input] " + name + " should be greater than " + base)
Пример #12
0
def check_should_none(value, name):
    if value is not None:
        raise BinanceApiException(BinanceApiException.INPUT_ERROR, "[Input] " + name + " should be null")
Пример #13
0
 def __check_mandatory_field(self, name):
     if name not in self.json_object:
         raise BinanceApiException(
             BinanceApiException.RUNTIME_ERROR,
             "[Json] Get json item field: " + name + " does not exist")