forked from danpaquin/coinbasepro-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request danpaquin#139 from kevinszielinski/ISSUE-128
ISSUE-128: fixed auth keys and encoding issues with websocket client
- Loading branch information
Showing
3 changed files
with
47 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import hmac | ||
import hashlib | ||
import time | ||
import base64 | ||
from requests.auth import AuthBase | ||
|
||
|
||
class GdaxAuth(AuthBase): | ||
# Provided by gdax: https://docs.gdax.com/#signing-a-message | ||
def __init__(self, api_key, secret_key, passphrase): | ||
self.api_key = api_key | ||
self.secret_key = secret_key | ||
self.passphrase = passphrase | ||
|
||
def __call__(self, request): | ||
timestamp = str(time.time()) | ||
message = timestamp + request.method + request.path_url + (request.body or '') | ||
request.headers.update(get_auth_headers(timestamp, message, self.api_key, self.secret_key, | ||
self.passphrase)) | ||
return request | ||
|
||
|
||
def get_auth_headers(timestamp, message, api_key, secret_key, passphrase): | ||
message = message.encode('ascii') | ||
hmac_key = base64.b64decode(secret_key) | ||
signature = hmac.new(hmac_key, message, hashlib.sha256) | ||
signature_b64 = base64.b64encode(signature.digest()).decode('utf-8') | ||
return { | ||
'Content-Type': 'Application/JSON', | ||
'CB-ACCESS-SIGN': signature_b64, | ||
'CB-ACCESS-TIMESTAMP': timestamp, | ||
'CB-ACCESS-KEY': api_key, | ||
'CB-ACCESS-PASSPHRASE': passphrase | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters