Bitcoin Forum
June 17, 2024, 10:19:10 AM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Poloniex Api "invalid command"  (Read 1431 times)
Bitlele (OP)
Newbie
*
Offline Offline

Activity: 8
Merit: 0


View Profile
September 29, 2016, 12:11:47 AM
 #1

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/
buxlover
Full Member
***
Offline Offline

Activity: 224
Merit: 100



View Profile
September 29, 2016, 08:38:59 AM
Last edit: September 29, 2016, 12:14:12 PM by buxlover
 #2

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 Wink
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!