gpt4 book ai didi

Python 3 哈希 HMAC-SHA512

转载 作者:太空狗 更新时间:2023-10-30 02:55:06 28 4
gpt4 key购买 nike

<分区>

我正在为 https://poloniex.com/support/api/ 编写一个机器人

公共(public)方法都可以正常工作,但交易 API 方法需要一些额外的技巧:

All calls to the trading API are sent via HTTP POST to https://poloniex.com/tradingApi and must contain the following headers:
Key - Your API key.
Sign - The query's POST data signed by your key's "secret" according to the HMAC-SHA512 method.
Additionally, all queries must include a "nonce" POST parameter. The nonce parameter is an integer which must always be greater than the previous nonce used.
All responses from the trading API are in JSON format.

我的 returnBalances 代码如下所示:

import hashlib
import hmac
from time import time

import requests


class Poloniex:
def __init__(self, APIKey, Secret):
self.APIKey = APIKey
self.Secret = Secret

def returnBalances(self):
url = 'https://poloniex.com/tradingApi'
payload = {
'command': 'returnBalances',
'nonce': int(time() * 1000),
}

headers = {
'Key': self.APIKey,
'Sign': hmac.new(self.Secret, payload, hashlib.sha512).hexdigest(),
}

r = requests.post(url, headers=headers, data=payload)
return r.json()

交易.py:

APIkey = 'AAA-BBB-CCC'
secret = b'123abc'

polo = Poloniex(APIkey, secret)
print(polo.returnBalances())

我得到了以下错误:

Traceback (most recent call last):
File "C:/Python/Poloniex/trading.py", line 5, in <module>
print(polo.returnBalances())
File "C:\Python\Poloniex\poloniex.py", line 22, in returnBalances
'Sign': hmac.new(self.Secret, payload, hashlib.sha512).hexdigest(),
File "C:\Users\Balazs91\AppData\Local\Programs\Python\Python35-32\lib\hmac.py", line 144, in new
return HMAC(key, msg, digestmod)
File "C:\Users\Balazs91\AppData\Local\Programs\Python\Python35-32\lib\hmac.py", line 84, in __init__
self.update(msg)
File "C:\Users\Balazs91\AppData\Local\Programs\Python\Python35-32\lib\hmac.py", line 93, in update
self.inner.update(msg)
TypeError: object supporting the buffer API required

Process finished with exit code 1

我也尝试过执行以下操作,但没有帮助: https://stackoverflow.com/a/25111089/7317891

非常感谢任何帮助!

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com