SHARE
TWEET

BTC-e API Python sample

miracle_max Aug 2nd, 2012 32,307 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # If you find this sample useful, please feel free to donate :)
  2. # LTC: LePiC6JKohb7w6PdFL2KDV1VoZJPFwqXgY
  3. # BTC: 1BzHpzqEVKjDQNCqV67Ju4dYL68aR8jTEe
  4.  
  5. import httplib
  6. import urllib
  7. import json
  8. import hashlib
  9. import hmac
  10.  
  11. # Replace these with your own API key data
  12. BTC_api_key = "your-api-key-here"
  13. BTC_api_secret = "your-api-secret-here"
  14. # Come up with your own method for choosing an incrementing nonce
  15. nonce = 13
  16.  
  17. # method name and nonce go into the POST parameters
  18. params = {"method":"getInfo",
  19.           "nonce": nonce}
  20. params = urllib.urlencode(params)
  21.  
  22. # Hash the params string to produce the Sign header value
  23. H = hmac.new(BTC_api_secret, digestmod=hashlib.sha512)
  24. H.update(params)
  25. sign = H.hexdigest()
  26.  
  27. headers = {"Content-type": "application/x-www-form-urlencoded",
  28.                    "Key":BTC_api_key,
  29.                    "Sign":sign}
  30. conn = httplib.HTTPSConnection("btc-e.com")
  31. conn.request("POST", "/tapi", params, headers)
  32. response = conn.getresponse()
  33.  
  34. print response.status, response.reason
  35. print json.load(response)
  36.  
  37. conn.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top