Advertisement
altoidnerd

coinbase api python unique output

Apr 30th, 2014
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import hashlib
  2. import hmac
  3. import urllib2
  4. import time
  5. from datetime import datetime
  6.  
  7.  
  8. #keys are obviously redacted
  9.  
  10. API_KEY = 'xxx'
  11. API_SECRET = 'xxx'
  12.  
  13. def get_http(url, body=None):
  14.   opener = urllib2.build_opener()
  15.   nonce = int(time.time() * 1e6)
  16.   message = str(nonce) + url + ('' if body is None else body)
  17.   signature = hmac.new(API_SECRET, message, hashlib.sha256).hexdigest()
  18.   opener.addheaders = [('ACCESS_KEY', API_KEY),
  19.                        ('ACCESS_SIGNATURE', signature),
  20.                        ('ACCESS_NONCE', nonce)]
  21.   try:
  22.     return opener.open(urllib2.Request(url, body))
  23.   except urllib2.HTTPError as e:
  24.     print e
  25.     return e
  26.  
  27. #this resulted in a timestamped unique output, thanks to msvalkon!
  28.  
  29. transdata =  get_http('https://coinbase.com/api/v1/transfers').read()
  30.  
  31. f1 = open('{}_DUMP.txt'.format(int(time.time())), 'w+')
  32.  
  33. f1.write( transdata )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement