Trade API Poloniex Python 3.5

时间:2017-12-27 23:05:26

标签: python poloniex

帮我登录api poloniex。下面写的是我试图登录的代码,但它给了我一个错误! Python版3.5。请帮助我理解我做错了什么!

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)

该计划的结果如下: {"错误":"无效的API密钥/密钥对。"}

1 个答案:

答案 0 :(得分:0)

试试这个:

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)