Bob Clarke
Bob Clarke

Reputation: 1

Poloniex API using requests, returnBalances works, but returnTradeHistory does not

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)

Upvotes: -1

Views: 298

Answers (1)

A. STEFANI
A. STEFANI

Reputation: 6737

According to the official poloniex API documentation:

returnTradeHistory

Returns the past 200 trades for a given market, or up to 50,000 trades between a range specified in UNIX timestamps by the "start" and "end" GET parameters [...]

so it is required to specify the start and end parameter

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

Upvotes: 0

Related Questions