Skip to content

Instantly share code, notes, and snippets.

@claytantor
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claytantor/11331191 to your computer and use it in GitHub Desktop.
Save claytantor/11331191 to your computer and use it in GitHub Desktop.
python coinbase http call
# there is a problem with the coinbase python example
# at https://coinbase.com/docs/api/authentication where they
# fail to add the content type header to the POST action
# this is the actual implementation
def get_http(self, url, body=None):
opener = urllib2.build_opener()
nonce = int(time.time() * 1e6)
message = str(nonce) + url + ('' if body is None else body)
signature = hmac.new(settings.COINBASE_API_SECRET, message, hashlib.sha256).hexdigest()
opener.addheaders = [('ACCESS_KEY', settings.COINBASE_API_KEY),
('ACCESS_SIGNATURE', signature),
('ACCESS_NONCE', nonce)]
try:
response = opener.open(urllib2.Request(url,body,{'Content-Type': 'application/json'}))
return response
except urllib2.HTTPError as e:
print e
return e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment