程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Kraken Exchange 私有 REST 调用返回“无效参数”Python大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Kraken Exchange 私有 REST 调用返回“无效参数”Python?

开发过程中遇到Kraken Exchange 私有 REST 调用返回“无效参数”Python的问题如何解决?下面主要结合日常开发的经验,给出你关于Kraken Exchange 私有 REST 调用返回“无效参数”Python的解决方法建议,希望对你解决Kraken Exchange 私有 REST 调用返回“无效参数”Python有所启发或帮助;

我一直在尝试使用 Kraken Exchange REST 私有 API,但一直无法获得不是“内部错误”的响应。

以下是用于发送请求的代码:

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,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)

我的消息签名可能有误吗?您知道内部错误可能意味着什么吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的Kraken Exchange 私有 REST 调用返回“无效参数”Python全部内容,希望文章能够帮你解决Kraken Exchange 私有 REST 调用返回“无效参数”Python所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。