I'm trying to access the Poloniex API using requests.
The returnBalances code works, but the returnTradeHistory code does not.
The returnTradeHistory is commented out in the example.
Data is returned for returnBalances but not for returnTradeHistory.
I know the whole APIKey and secret code is working because I am getting accurate returnBalances data.
So why is returnTradeHistory not working?
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)
According to the official poloniex API documentation:
so it is required to specify the
startandendparametere.g:
https://poloniex.com/public?command=returnTradeHistory¤cyPair=BTC_NXT&start=1410158341&end=1410499372