Bitcoin Forum

Economy => Exchanges => Topic started by: Bitlele on September 29, 2016, 12:11:47 AM



Title: Poloniex Api "invalid command"
Post by: Bitlele on September 29, 2016, 12:11:47 AM
Hello i am developing a bot in python using the polonix api
I am trying to make request to private api the server reply my this error message: {'error': 'Invalid command.'}

this is my code someone coudl help me to fix it? is all the day that i try but It still dosent works!!!
def getOpenOrders(self,url,comand, market):

    nonce = int(time.time())
    print(comand)
    urlrequest = url  + '?apikey=' + self.apiKey +'&command='+comand + '&nonce=' +str(nonce) + '&market=' + str(market)
    print(urlrequest)
    param =  'command='+comand + 'nonce=' +str(nonce) +str(market)

    signature =  hmac.new(self.Secret.encode(),param.encode(), hashlib.sha512).hexdigest()
    headers = {
            'Sign':signature,
            'Key': self.apiKey
        }

    self.r = requests.post(urlrequest,headers= headers,)
    print(self.r)
    print(self.r.json())




I think there is problem with the signature but i dont know where.

ps this is the official documentation https://temp.poloniex.com/support/api/


Title: Re: Poloniex Api "invalid command"
Post by: buxlover on September 29, 2016, 08:38:59 AM
I think the correct def would be

def getOpenOrders(self,url,comand, market):

    nonce = int(time.time())
    print(comand)
    urlrequest = url  + '?apikey=' + self.apiKey +'&command='+comand + '&nonce=' +str(nonce) + '&currencyPair=' + str(market)
    print(urlrequest)
    param =  'command='+comand + 'nonce=' +str(nonce) +str(market)
    param =  'command='+comand + '&nonce=' +str(nonce) + "&currencyPair=" +str(market)

    signature =  hmac.new(self.Secret.encode(),param.encode(), hashlib.sha512).hexdigest()
    headers = {
            'Sign':signature,
            'Key': self.apiKey
        }

    self.r = requests.post(urlrequest,headers= headers,)
    print(self.r)
    print(self.r.json())

You must remove the striked line and add the line below mentioned above.

WHY?

Simple! It seems that you have not formatted the post data correctly in your param variable.

Hope this helps!
If not, just pm me ;)