unwitting / bitstampy

Bitstamp API wrapper for Python
MIT License
55 stars 21 forks source link

What type to use for client_id, api_key, api_secret #14

Open Salan54 opened 6 years ago

Salan54 commented 6 years ago
c = '12345'
k = 'xxxxx'
s = 'yyyyy'
api.account_balance(c, k, s)
~/.virtualenvs/bitstamp/lib/python3.6/site-packages/bitstampy/api.py in account_balance(client_id, api_key, api_secret)
     38 def account_balance(client_id, api_key, api_secret):
     39     return (
---> 40         calls.APIAccountBalanceCall(client_id, api_key, api_secret)
     41         .call()
     42     )

~/.virtualenvs/bitstamp/lib/python3.6/site-packages/bitstampy/calls.py in call(self, **params)
     79         message = nonce + self.client_id + self.api_key
     80         signature = hmac.new(
---> 81             self.api_secret, msg=message, digestmod=hashlib.sha256)
     82         signature = signature.hexdigest().upper()
     83         params.update({

~/.virtualenvs/bitstamp/lib/python3.6/hmac.py in new(key, msg, digestmod)
    142     method.
    143     """
--> 144     return HMAC(key, msg, digestmod)

~/.virtualenvs/bitstamp/lib/python3.6/hmac.py in __init__(self, key, msg, digestmod)
     40 
     41         if not isinstance(key, (bytes, bytearray)):
---> 42             raise TypeError("key: expected bytes or bytearray, but got %r" % type(key).__name__)
     43 
     44         if digestmod is None:

TypeError: key: expected bytes or bytearray, but got 'str'

Changed key to bytes :

k = b'xxxxx' Then :

api.account_balance(c, k, s)

TypeError                                 Traceback (most recent call last)
<ipython-input-27-35f3ae0e7115> in <module>()
----> 1 api.account_balance(c, k, s)

~/.virtualenvs/bitstamp/lib/python3.6/site-packages/bitstampy/api.py in account_balance(client_id, api_key, api_secret)
     38 def account_balance(client_id, api_key, api_secret):
     39     return (
---> 40         calls.APIAccountBalanceCall(client_id, api_key, api_secret)
     41         .call()
     42     )

~/.virtualenvs/bitstamp/lib/python3.6/site-packages/bitstampy/calls.py in call(self, **params)
     77     def call(self, **params):
     78         nonce = self._get_nonce()
---> 79         message = nonce + self.client_id + self.api_key
     80         signature = hmac.new(
     81             self.api_secret, msg=message, digestmod=hashlib.sha256)

TypeError: must be str, not bytes

I am rather confused. Could you please clarify the argument types to use for client_id, api_key, api_secret ? Thanks

iqdecay commented 6 years ago

Have you found how to make this work ?