

import httplib
import urllib
import json
import hashlib
import hmac
# Replace these with your own API key data
BTC_api_key = "xxxxxxxxxxxxxxx" //填入在bter上注册后的获得的key和secret码。
BTC_api_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Come up with your own method for choosing an incrementing nonce
nonce = 13
# method name and nonce go into the POST parameters
params = {"nonce": nonce}
params = urllib.urlencode(params)
# Hash the params string to produce the Sign header value
H = hmac.new(BTC_api_secret, digestmod=hashlib.sha512)
H.update(params)
sign = H.hexdigest()
headers = {"Content-type": "application/x-www-form-urlencoded",
"Key":BTC_api_key,
"Sign":sign}
conn = httplib.HTTPSConnection("bter.com")
conn.request("POST", "/api/1/private/getfunds", params, headers)
response = conn.getresponse()
print response.status, response.reason
print json.load(response)
conn.close()
此例用于获取自己在bter网站上的帐户余额。
原创文章,作者:苏葳,如需转载,请注明出处:https://www.swmemo.com/491.html
