Closed Rixter145 closed 6 years ago
Hi, how do you import bitstamp client? My code which works is here:
import bitstamp.client
try:
bc = bitstamp.client.Trading(username=os.environ['bs_user'],
key=os.environ['bs_key'],
secret=os.environ['bs_secret'])
except bitstamp.client.BitstampError:
pass
print(bc.account_balance())
So I changed the exception to the higher class (Looking from your class diagram) and it seemed to be fine now
import bitstamp.client
bitstampz = bitstamp.client.Trading(username=bitstamp_username, key=bitstamp_api_key, secret=bitstamp_secret_key)
while bitstamp_ltcbtc == None:
try:
bitstamp_ltcbtc = bitstampz.ticker(base='ltc', quote='btc')
#print(bitstamp_ltcbtc)
except Exception:
print("error at", json.JSONDecodeError)
bitstamp_ltcbtc = None
continue
I'm glad I could help.
I am making ticker calls to bitstamp through your method ticker() but some times bitstamp returns a null.
It appears that the raise BitstampError causes my code to halt. Here's my snippet and hoping to have a better understanding:
while bitstamp_ltcbtc == None:
try: bitstamp_ltcbtc = bitstampz.ticker(base='ltc', quote='btc')
print(bitstamp_ltcbtc)
The json_response is none I tried to catch the error by using a try except bitstampz.BitstampError
but only to be caught with AttributeError: 'Trading' object has no attribute 'BitstampError' ...
I would like to do a retry if it failed but not sure how to do so
Traceback (most recent call last):
File "", line 4, in
bitstamp_ltcbtc = bitstampz.ticker(base='ltc', quote='btc')
File "H:\Anaconda\Anaconda3\lib\site-packages\bitstamp\client.py", line 111, in ticker return self._get(url, return_json=True, version=2)
File "H:\Anaconda\Anaconda3\lib\site-packages\bitstamp\client.py", line 39, in _get return self._request(requests.get, *args, **kwargs)
File "H:\Anaconda\Anaconda3\lib\site-packages\bitstamp\client.py", line 98, in _request
"Could not decode json for: " + response.text)
BitstampError: Could not decode json for: