-1

我正在尝试使用请求访问 Poloniex API。

代码有效,returnBalancesreturnTradeHistory代码无效。

示例中returnTradeHistory已注释掉。

returnBalances但不返回数据returnTradeHistory

我知道整个APIKey密码都在工作,因为我得到了准确的returnBalances数据。

那么为什么returnTradeHistory不工作呢?

from time import time
import urllib.parse
import hashlib
import hmac
import requests
import json

APIKey=b"stuff goes in here"
secret=b"stuff goes in here"

url = "https://poloniex.com/tradingApi"

# this works and returns data
payload = {
    'command': 'returnBalances',
    'nonce': int(time() * 1000),
}

# this does not work and does not return data
#payload = {
#    'command': 'returnTradeHistory',
#    'currencyPair': 'BTC_MAID',
#    'nonce': int(time() * 1000),
#}

paybytes = urllib.parse.urlencode(payload).encode('utf8')
sign = hmac.new(secret, paybytes, hashlib.sha512).hexdigest()
headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Key': APIKey,
    'Sign': sign,
}
r = requests.post(url, data=paybytes, headers=headers)
fulldata=r.content
data = json.loads(fulldata)
print(data)
4

1 回答 1

0

根据官方 poloniex API 文档

返回贸易历史

返回给定市场的过去 200 笔交易,或 在 UNIX 时间戳中由“ start ”和“ end ”GET 参数指定的范围内最多 50,000 笔交易 [...]

所以需要指定startandend参数

例如:https://poloniex.com/public?command=returnTradeHistory&currencyPair=BTC_NXT&start=1410158341&end=1410499372

于 2018-06-25T12:00:46.540 回答