API key error handling.
This commit is contained in:
parent
1c7daa713b
commit
c352c9b293
@ -62,49 +62,64 @@ class Bittrex(Exchange):
|
|||||||
def buy(self, pair: str, rate: float, amount: float) -> str:
|
def buy(self, pair: str, rate: float, amount: float) -> str:
|
||||||
data = _API.buy_limit(pair.replace('_', '-'), amount, rate)
|
data = _API.buy_limit(pair.replace('_', '-'), amount, rate)
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
Bittrex._validate_response(data)
|
if 'APIKEY_INVALID' in str(data['message']):
|
||||||
raise OperationalException('{message} params=({pair}, {rate}, {amount})'.format(
|
print('Api Key...')
|
||||||
message=data['message'],
|
else:
|
||||||
pair=pair,
|
Bittrex._validate_response(data)
|
||||||
rate=rate,
|
raise OperationalException('{message} params=({pair}, {rate}, {amount})'.format(
|
||||||
amount=amount))
|
message=data['message'],
|
||||||
|
pair=pair,
|
||||||
|
rate=rate,
|
||||||
|
amount=amount))
|
||||||
return data['result']['uuid']
|
return data['result']['uuid']
|
||||||
|
|
||||||
def sell(self, pair: str, rate: float, amount: float) -> str:
|
def sell(self, pair: str, rate: float, amount: float) -> str:
|
||||||
data = _API.sell_limit(pair.replace('_', '-'), amount, rate)
|
data = _API.sell_limit(pair.replace('_', '-'), amount, rate)
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
Bittrex._validate_response(data)
|
if 'APIKEY_INVALID' in str(data['message']):
|
||||||
raise OperationalException('{message} params=({pair}, {rate}, {amount})'.format(
|
print('Api Key...')
|
||||||
message=data['message'],
|
else:
|
||||||
pair=pair,
|
Bittrex._validate_response(data)
|
||||||
rate=rate,
|
raise OperationalException('{message} params=({pair}, {rate}, {amount})'.format(
|
||||||
amount=amount))
|
message=data['message'],
|
||||||
|
pair=pair,
|
||||||
|
rate=rate,
|
||||||
|
amount=amount))
|
||||||
return data['result']['uuid']
|
return data['result']['uuid']
|
||||||
|
|
||||||
def get_balance(self, currency: str) -> float:
|
def get_balance(self, currency: str) -> float:
|
||||||
data = _API.get_balance(currency)
|
data = _API.get_balance(currency)
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
Bittrex._validate_response(data)
|
if 'APIKEY_INVALID' in str(data['message']):
|
||||||
raise OperationalException('{message} params=({currency})'.format(
|
print('Api Key...')
|
||||||
message=data['message'],
|
else:
|
||||||
currency=currency))
|
Bittrex._validate_response(data)
|
||||||
|
raise OperationalException('{message} params=({currency})'.format(
|
||||||
|
message=data['message'],
|
||||||
|
currency=currency))
|
||||||
return float(data['result']['Balance'] or 0.0)
|
return float(data['result']['Balance'] or 0.0)
|
||||||
|
|
||||||
def get_balances(self):
|
def get_balances(self):
|
||||||
data = _API.get_balances()
|
data = _API.get_balances()
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
Bittrex._validate_response(data)
|
if 'APIKEY_INVALID' in str(data['message']):
|
||||||
raise OperationalException('{message}'.format(message=data['message']))
|
print('Api Key...')
|
||||||
|
else:
|
||||||
|
Bittrex._validate_response(data)
|
||||||
|
raise OperationalException('{message}'.format(message=data['message']))
|
||||||
return data['result']
|
return data['result']
|
||||||
|
|
||||||
def get_ticker(self, pair: str, refresh: Optional[bool] = True) -> dict:
|
def get_ticker(self, pair: str, refresh: Optional[bool] = True) -> dict:
|
||||||
if refresh or pair not in self.cached_ticker.keys():
|
if refresh or pair not in self.cached_ticker.keys():
|
||||||
data = _API.get_ticker(pair.replace('_', '-'))
|
data = _API.get_ticker(pair.replace('_', '-'))
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
Bittrex._validate_response(data)
|
if 'APIKEY_INVALID' in str(data['message']):
|
||||||
raise OperationalException('{message} params=({pair})'.format(
|
print('Api Key...')
|
||||||
message=data['message'],
|
else:
|
||||||
pair=pair))
|
Bittrex._validate_response(data)
|
||||||
|
raise OperationalException('{message} params=({pair})'.format(
|
||||||
|
message=data['message'],
|
||||||
|
pair=pair))
|
||||||
keys = ['Bid', 'Ask', 'Last']
|
keys = ['Bid', 'Ask', 'Last']
|
||||||
if not data.get('result') or\
|
if not data.get('result') or\
|
||||||
not all(key in data.get('result', {}) for key in keys) or\
|
not all(key in data.get('result', {}) for key in keys) or\
|
||||||
@ -147,10 +162,13 @@ class Bittrex(Exchange):
|
|||||||
'in response params=({})'.format(prop, pair))
|
'in response params=({})'.format(prop, pair))
|
||||||
|
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
Bittrex._validate_response(data)
|
if 'APIKEY_INVALID' in str(data['message']):
|
||||||
raise OperationalException('{message} params=({pair})'.format(
|
print('Api Key...')
|
||||||
message=data['message'],
|
else:
|
||||||
pair=pair))
|
Bittrex._validate_response(data)
|
||||||
|
raise OperationalException('{message} params=({pair})'.format(
|
||||||
|
message=data['message'],
|
||||||
|
pair=pair))
|
||||||
|
|
||||||
return data['result']
|
return data['result']
|
||||||
|
|
||||||
@ -176,10 +194,13 @@ class Bittrex(Exchange):
|
|||||||
def cancel_order(self, order_id: str) -> None:
|
def cancel_order(self, order_id: str) -> None:
|
||||||
data = _API.cancel(order_id)
|
data = _API.cancel(order_id)
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
Bittrex._validate_response(data)
|
if 'APIKEY_INVALID' in str(data['message']):
|
||||||
raise OperationalException('{message} params=({order_id})'.format(
|
print('Api Key...')
|
||||||
message=data['message'],
|
else:
|
||||||
order_id=order_id))
|
Bittrex._validate_response(data)
|
||||||
|
raise OperationalException('{message} params=({order_id})'.format(
|
||||||
|
message=data['message'],
|
||||||
|
order_id=order_id))
|
||||||
|
|
||||||
def get_pair_detail_url(self, pair: str) -> str:
|
def get_pair_detail_url(self, pair: str) -> str:
|
||||||
return self.PAIR_DETAIL_METHOD + '?MarketName={}'.format(pair.replace('_', '-'))
|
return self.PAIR_DETAIL_METHOD + '?MarketName={}'.format(pair.replace('_', '-'))
|
||||||
@ -187,22 +208,31 @@ class Bittrex(Exchange):
|
|||||||
def get_markets(self) -> List[str]:
|
def get_markets(self) -> List[str]:
|
||||||
data = _API.get_markets()
|
data = _API.get_markets()
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
Bittrex._validate_response(data)
|
if 'APIKEY_INVALID' in str(data['message']):
|
||||||
raise OperationalException(data['message'])
|
print('Api Key...')
|
||||||
|
else:
|
||||||
|
Bittrex._validate_response(data)
|
||||||
|
raise OperationalException(data['message'])
|
||||||
return [m['MarketName'].replace('-', '_') for m in data['result']]
|
return [m['MarketName'].replace('-', '_') for m in data['result']]
|
||||||
|
|
||||||
def get_market_summaries(self) -> List[Dict]:
|
def get_market_summaries(self) -> List[Dict]:
|
||||||
data = _API.get_market_summaries()
|
data = _API.get_market_summaries()
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
Bittrex._validate_response(data)
|
if 'APIKEY_INVALID' in str(data['message']):
|
||||||
raise OperationalException(data['message'])
|
print('Api Key...')
|
||||||
|
else:
|
||||||
|
Bittrex._validate_response(data)
|
||||||
|
raise OperationalException(data['message'])
|
||||||
return data['result']
|
return data['result']
|
||||||
|
|
||||||
def get_wallet_health(self) -> List[Dict]:
|
def get_wallet_health(self) -> List[Dict]:
|
||||||
data = _API_V2.get_wallet_health()
|
data = _API_V2.get_wallet_health()
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
Bittrex._validate_response(data)
|
if 'APIKEY_INVALID' in str(data['message']):
|
||||||
raise OperationalException(data['message'])
|
print('Api Key...')
|
||||||
|
else:
|
||||||
|
Bittrex._validate_response(data)
|
||||||
|
raise OperationalException(data['message'])
|
||||||
return [{
|
return [{
|
||||||
'Currency': entry['Health']['Currency'],
|
'Currency': entry['Health']['Currency'],
|
||||||
'IsActive': entry['Health']['IsActive'],
|
'IsActive': entry['Health']['IsActive'],
|
||||||
|
Loading…
Reference in New Issue
Block a user