Bittrex Api上有一个名为getbalance的端点,该端点将一种货币作为字符串,并返回该货币的当前余额。在函数中执行请求时,
balance = get_balance('BTC')
请求返回:
{'message':'INVALID_SIGNATURE',
'result':无,
'success':False}
功能:
def get_balance(currency):
endpoint = '/account/getbalance'
params = {
'currency' : currency
}
return call_endpoint(endpoint, False, params)
call_endpoint:
def call_endpoint(endpoint, isPublic, params = None):
base_url = 'https://bittrex.com/api/v1.1'
url = (base_url + endpoint +
'?apikey=' + API_KEY +
'&nonce=' + str(time.time())).encode('utf-8')
signature = hmac.new(SECRET_KEY, url, hashlib.sha512).hexdigest()
headers = {'apisign' : signature}
r = requests.get(url, headers = headers, params=params)
return r
但是,如果我要在函数外部请求它:
url = ('https://bittrex.com/api/v1.1/account/getbalance' +
'?apikey=' + API_KEY +
'&nonce=' + str(time.time()) +
'¤cy=BTC').encode('utf-8')
signature = hmac.new(SECRET_KEY, url, hashlib.sha512).hexdigest()
headers = {'apisign' : signature}
r = requests.get(url, headers = headers)
有用。
{'message':'',
'result':{'Available':
...,
'success':True}
这两种方法具有相同的代码,那么关于python函数或请求库的某些内容会导致此错误吗?
这两种方法不会做相同的事情。
您的call_endpoint
函数会在没有currency
参数的情况下为url输入上的标头计算签名,然后requests
在currency
参数中添加。
您的其他代码段将在包含currency
参数的URL上计算签名。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句