Advertisement
altoidnerd

python coinbase api fetch

Apr 30th, 2014
1,586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. import hashlib
  2. import hmac
  3. import urllib2
  4. import time
  5.  
  6.  
  7. API_KEY = 'xxx'
  8. # I obviously supressed the key and secret
  9. API_SECRET = 'xxx'
  10.  
  11. def get_http(url, body=None):
  12.   opener = urllib2.build_opener()
  13.   nonce = int(time.time() * 1e6)
  14.   message = str(nonce) + url + ('' if body is None else body)
  15.   signature = hmac.new(API_SECRET, message, hashlib.sha256).hexdigest()
  16.   opener.addheaders = [('ACCESS_KEY', API_KEY),
  17.                        ('ACCESS_SIGNATURE', signature),
  18.                        ('ACCESS_NONCE', nonce)]
  19.   try:
  20.     return opener.open(urllib2.Request(url, body))
  21.   except urllib2.HTTPError as e:
  22.     print e
  23.     return e
  24.  
  25. transdata =  get_http('https://coinbase.com/api/v1/transfers').read()
  26.  
  27. f1 = open('./DUMP.txt' , 'w+')
  28.  
  29. # this is where the program creates a file DUMP.txt and writes the relevant data fetched.  Re running the program
  30. # overwrites DUMP.txt
  31.  
  32. f1.write( transdata )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement