1

Help me log in to the api poloniex. Below is written my code with which I am trying to log in, but it gives me an error! Python version 3.5. Help me please understand what I'm doing wrong!

import urllib
import requests
import json
import time
import hmac,hashlib

api_secret ="111111111111111111111111111111111111111111111111111111111"
api_key="YYYYYYYY-IIIIIIII-PPPPPPPP-LLLLLLLL"

nonce = int(time.time() * 1000)
parms = {"nonce": nonce,"command":'returnBalances'}
post_data = urllib.parse.urlencode(parms)

sign = hmac.new( api_secret.encode(),post_data.encode(), hashlib.sha512).hexdigest()
print(sign)
headers = {"Sign":sign,"Key":api_key}
public = requests.post('https://poloniex.com/tradingApi',post_data,headers)

print(public.text)

The result of the program is the following: {"error":"Invalid API key/secret pair."}

Scott Mermelstein
  • 15,174
  • 4
  • 48
  • 76

1 Answers1

0

Try this:

import urllib
import urllib2
import requests
import json
import time
import hmac,hashlib

api_secret ="111111111111111111111111111111111111111111111111111111111"
api_key="YYYYYYYY-IIIIIIII-PPPPPPPP-LLLLLLLL"

nonce = int(time.time() * 1000)
parms = {"nonce": nonce,"command":'returnBalances'}
post_data = urllib.parse.urlencode(parms)

sign = hmac.new( api_secret,post_data, hashlib.sha512).hexdigest()
print(sign)
headers = {"Sign":sign,"Key":api_key}
ret = urllib2.urlopen(urllib2.Request('https://poloniex.com/tradingApi', post_data, headers))
jsonRet = json.loads(ret.read())

print(jsonRet)
A. STEFANI
  • 6,707
  • 1
  • 23
  • 48