簡體   English   中英

Python-Poloniex交易API問題

[英]Python - Poloniex trading api problems

盡管有關Poloniex / Python交易api訪問的文章很多,但我仍然不知道如何在Python 3.6上實現這一功能。 在我看來,這是一個版本,應該措辭完美,但不能:

req['command'] = 'requestBalances'
req['nonce'] = int(time.time() * 1000)
post_data = urllib.parse.urlencode(req).encode('utf-8')
hmac_key = self.Secret.encode('utf-8')

sign = hmac.new(hmac_key, post_data, hashlib.sha512)
sign = sign.hexdigest()

 headers = {
    'Sign': sign,
     'Key': self.APIKey
  }

  res = requests.post('https://poloniex.com/tradingApi', data=post_data, headers=headers)

如果我使用正確的api /密碼運行上述命令,則會收到“無效命令”錯誤。

有趣的是,如果我將request.post函數替換為:

req = urllib.request.Request(url='https://poloniex.com/tradingApi', data=post_data, headers=headers)
res = urllib.request.urlopen(req,timeout=5)

那么我沒有收到錯誤,只是一個空字節數組(在res.read()之后)

如何使這項工作的任何提示將不勝感激。

解決方案包括:

"Content-type": "application/x-www-form-urlencoded"

在標題中,即:

headers = {
    "Content-type": "application/x-www-form-urlencoded",
    'Sign': sign,
    'Key': self.APIKey
}

奇怪的是,我所見過的其他解決方案都沒有包含這個額外的領域,但是我們走了。

PS。 使用urllib.request的替代方法仍然只返回一個空字節字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM