I expect this simple script that connects to Binance and gets the details of my account to work using python-binance library (version: 0.7.9) out of the box but it does not seem to. I am able to connect to the API and get the price of bitcoin therefore I am confident the error is not this.
import os
from binance.client import Client
from binance.websockets import BinanceSocketManager
from twisted.internet import reactor
# Get keys
api_key = os.environ.get('binance_api')
api_secret = os.environ.get('binance_secret')
# Connect to Binance
client = Client(api_key, api_secret)
print(client.get_account())
gives the following error.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-9c56ae96674c> in <module>
----> 1 print(client.get_account())
~/.local/lib/python3.8/site-packages/binance/client.py in get_account(self, **params)
1765
1766 """
-> 1767 return self._get('account', True, data=params)
1768
1769 def get_asset_balance(self, asset, **params):
~/.local/lib/python3.8/site-packages/binance/client.py in _get(self, path, signed, version, **kwargs)
235
236 def _get(self, path, signed=False, version=PUBLIC_API_VERSION, **kwargs):
--> 237 return self._request_api('get', path, signed, version, **kwargs)
238
239 def _post(self, path, signed=False, version=PUBLIC_API_VERSION, **kwargs):
~/.local/lib/python3.8/site-packages/binance/client.py in _request_api(self, method, path, signed, version, **kwargs)
200 uri = self._create_api_uri(path, signed, version)
201
--> 202 return self._request(method, uri, signed, **kwargs)
203
204 def _request_withdraw_api(self, method, path, signed=False, **kwargs):
~/.local/lib/python3.8/site-packages/binance/client.py in _request(self, method, uri, signed, force_params, **kwargs)
178 # generate signature
179 kwargs['data']['timestamp'] = int(time.time() * 1000)
--> 180 kwargs['data']['signature'] = self._generate_signature(kwargs['data'])
181
182 # sort get and post params to match signature order
~/.local/lib/python3.8/site-packages/binance/client.py in _generate_signature(self, data)
133 ordered_data = self._order_params(data)
134 query_string = '&'.join(["{}={}".format(d[0], d[1]) for d in ordered_data])
--> 135 m = hmac.new(self.API_SECRET.encode('utf-8'), query_string.encode('utf-8'), hashlib.sha256)
136 return m.hexdigest()
137
AttributeError: 'NoneType' object has no attribute 'encode'
Checking the docs, I don't see what I might be doing wrong. Since the debug logs indicate the error might be in the binance api but I'm not sure because this is a basic feature and should work without any trouble.
I appreciate your help.
Keys were not imported correctly, check with 'binance_api' in os.environ
. Add set -gx ENV_NAME=value
to ~/.config/fish/config.fish