Kraken交换私人休息呼叫返回';无效参数';python
我一直在尝试使用Kraken Exchange REST私有API,但在获得非“内部错误”的响应时遇到了问题 以下是用于发送请求的代码:Kraken交换私人休息呼叫返回';无效参数';python,python,api,rest,exchange-server,kraken.com,Python,Api,Rest,Exchange Server,Kraken.com,我一直在尝试使用Kraken Exchange REST私有API,但在获得非“内部错误”的响应时遇到了问题 以下是用于发送请求的代码: class Kraken_Harness: def __init__(self, apiPublicKey="", apiPrivateKey="", timeout=10): self.apiPath = 'https://api.kraken.com' self.apiPubl
class Kraken_Harness:
def __init__(self, apiPublicKey="", apiPrivateKey="", timeout=10):
self.apiPath = 'https://api.kraken.com'
self.apiPublicKey = apiPublicKey
self.apiPrivateKey = apiPrivateKey
self.timeout = timeout
self.nonce = 0
def sign_message(self, endpoint, postData, nonce=""):
apiPostData = 'nonce=' + nonce + '&' + postData
# Decode API private key from base64 format displayed in account management
api_secret = base64.b64decode(self.apiPrivateKey)
# Cryptographic hash algorithms
sha256_hash = hashlib.sha256(nonce.encode('utf-8') + apiPostData.encode('utf-8')).digest()
hmac_sha256_data = endpoint.encode('utf-8') + sha256_hash
hmac_sha256_hash = hmac.new(api_secret, hmac_sha256_data, hashlib.sha512)
# Encode signature into base64 format used in API-Sign value
api_signature = base64.b64encode(hmac_sha256_hash.digest())
# pdb.set_trace()
# API authentication signature for use in API-Sign HTTP header
return api_signature
# creates a unique nonce
def get_nonce(self):
# https://en.wikipedia.org/wiki/Modulo_operation
self.nonce = (self.nonce + 1) & 8191
return str(int(time.time() * 1000)) + str(self.nonce).zfill(4)
# sends an HTTP request
def make_request(self, endpoint, postUrl=""):
# create authentication headers
# krakent requires the header to have an
# APIKey
# Nonce
# Authenticator
nonce = self.get_nonce()
signature = self.sign_message(endpoint, postUrl, nonce=nonce)
authentHeaders = {"API-Key": self.apiPublicKey,
"nonce": nonce, "API-Sign": signature}
authentHeaders["User-Agent"] = "Kraken REST API"
# create request
if postUrl != "":
url = self.apiPath + endpoint + "?" + postUrl
else:
url = self.apiPath + endpoint
request = urllib2.Request(url, str.encode(postUrl), authentHeaders)
response = urllib2.urlopen(request, timeout=self.timeout)
# return
return response.read().decode("utf-8")
def get_accountbalance(self):
"""
Returns:
array of asset names and balance amount
"""
endpoint = '/0/private/Balance'
return self.make_request(endpoint)
我的留言签名可能是错的吗?你知道内部错误是什么意思吗