I am trying to write a script to place an order for me on GDAX. In ordered to do that, I needed a base64 signature. I encoded it with the base64 library but the next part states the base64 signature isn’t defined.
This is the error msg that it gives:
“Traceback (most recent call last): File “first.py”, line 39, in ‘CB-ACCESS-SIGN’: signature_b64, NameError: name ‘signature_b64’ is not defined
Thanks in advance!
Code is below(passwords are omitted for security reasons :P):
import requests import json import base64 import hashlib import hmac import time from requests.auth import AuthBase class GDAXRequestAuth(AuthBase): def _init_(self, api_key, secret_key, passphrase):< self.api_key = api_key self.secret_key = sec`enter code here`ret_key self.passphrase = passphrase def _call_(self, request): timestamp = str(time.time()) message = timestamp + request.method + request.path_url + (request.body or '') hmac_key = base64.b64decode(self.secret_key) signature = hmac.new(hmac_key, message.encode('utf-8'), hashlib.sha256) signature_b64 = base64.b64encode(signature.digest()) request.headers.update({ 'CB-ACCESS-SIGN': signature_b64, 'CB-ACCESS-TIMESTAMP': timestamp, 'CB-ACCESS-KEY': self.api_key, 'CB-ACCESS-PASSPHRASE': self.passphrase, 'Content-Type': 'application/json' }) return request
omitted part
api_base = api_key = api_secret = passphrase = headers = { 'CB-ACCESS-SIGN': signature_b64, 'CB-ACCESS-TIMESTAMP': timestamp, 'CB-ACCESS-KEY': api_key, 'CB-ACCESS-PASSPHRASE': passphrase, 'Content-Type': 'application/json' } requests.post(order_url, data=data, headers=headers) auth = GDAXRequestAuth(api_key, api_secret, passphrase) order_url = api_base + '/orders' order_data = { 'type': 'market', 'side': 'buy', 'product_id': 'BTC-USD', 'size': '0.01' } response = requests.post(order_url, data= json.dumps(order_data), auth =auth) print(response.json())