raise ContentDecodingError if bittrex responds with NO_API_RESPONSE (#183)
This commit is contained in:
parent
89ee0654f4
commit
bfb3e09d1d
@ -39,6 +39,15 @@ class Bittrex(Exchange):
|
|||||||
api_version=API_V2_0,
|
api_version=API_V2_0,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _validate_response(response) -> None:
|
||||||
|
"""
|
||||||
|
Validates the given bittrex response
|
||||||
|
and raises a ContentDecodingError if a non-fatal issue happened.
|
||||||
|
"""
|
||||||
|
if response['message'] == 'NO_API_RESPONSE':
|
||||||
|
raise ContentDecodingError('Unable to decode bittrex response')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fee(self) -> float:
|
def fee(self) -> float:
|
||||||
# See https://bittrex.com/fees
|
# See https://bittrex.com/fees
|
||||||
@ -47,6 +56,7 @@ 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)
|
||||||
raise OperationalException('{message} params=({pair}, {rate}, {amount})'.format(
|
raise OperationalException('{message} params=({pair}, {rate}, {amount})'.format(
|
||||||
message=data['message'],
|
message=data['message'],
|
||||||
pair=pair,
|
pair=pair,
|
||||||
@ -57,6 +67,7 @@ class Bittrex(Exchange):
|
|||||||
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)
|
||||||
raise OperationalException('{message} params=({pair}, {rate}, {amount})'.format(
|
raise OperationalException('{message} params=({pair}, {rate}, {amount})'.format(
|
||||||
message=data['message'],
|
message=data['message'],
|
||||||
pair=pair,
|
pair=pair,
|
||||||
@ -67,6 +78,7 @@ class Bittrex(Exchange):
|
|||||||
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)
|
||||||
raise OperationalException('{message} params=({currency})'.format(
|
raise OperationalException('{message} params=({currency})'.format(
|
||||||
message=data['message'],
|
message=data['message'],
|
||||||
currency=currency))
|
currency=currency))
|
||||||
@ -75,12 +87,14 @@ class Bittrex(Exchange):
|
|||||||
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)
|
||||||
raise OperationalException('{message}'.format(message=data['message']))
|
raise OperationalException('{message}'.format(message=data['message']))
|
||||||
return data['result']
|
return data['result']
|
||||||
|
|
||||||
def get_ticker(self, pair: str) -> dict:
|
def get_ticker(self, pair: str) -> dict:
|
||||||
data = _API.get_ticker(pair.replace('_', '-'))
|
data = _API.get_ticker(pair.replace('_', '-'))
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
|
Bittrex._validate_response(data)
|
||||||
raise OperationalException('{message} params=({pair})'.format(
|
raise OperationalException('{message} params=({pair})'.format(
|
||||||
message=data['message'],
|
message=data['message'],
|
||||||
pair=pair))
|
pair=pair))
|
||||||
@ -122,6 +136,7 @@ class Bittrex(Exchange):
|
|||||||
pair=pair))
|
pair=pair))
|
||||||
|
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
|
Bittrex._validate_response(data)
|
||||||
raise OperationalException('{message} params=({pair})'.format(
|
raise OperationalException('{message} params=({pair})'.format(
|
||||||
message=data['message'],
|
message=data['message'],
|
||||||
pair=pair))
|
pair=pair))
|
||||||
@ -131,6 +146,7 @@ class Bittrex(Exchange):
|
|||||||
def get_order(self, order_id: str) -> Dict:
|
def get_order(self, order_id: str) -> Dict:
|
||||||
data = _API.get_order(order_id)
|
data = _API.get_order(order_id)
|
||||||
if not data['success']:
|
if not data['success']:
|
||||||
|
Bittrex._validate_response(data)
|
||||||
raise OperationalException('{message} params=({order_id})'.format(
|
raise OperationalException('{message} params=({order_id})'.format(
|
||||||
message=data['message'],
|
message=data['message'],
|
||||||
order_id=order_id))
|
order_id=order_id))
|
||||||
@ -149,6 +165,7 @@ 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)
|
||||||
raise OperationalException('{message} params=({order_id})'.format(
|
raise OperationalException('{message} params=({order_id})'.format(
|
||||||
message=data['message'],
|
message=data['message'],
|
||||||
order_id=order_id))
|
order_id=order_id))
|
||||||
@ -159,18 +176,21 @@ 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)
|
||||||
raise OperationalException('{message}'.format(message=data['message']))
|
raise OperationalException('{message}'.format(message=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)
|
||||||
raise OperationalException('{message}'.format(message=data['message']))
|
raise OperationalException('{message}'.format(message=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)
|
||||||
raise OperationalException('{message}'.format(message=data['message']))
|
raise OperationalException('{message}'.format(message=data['message']))
|
||||||
return [{
|
return [{
|
||||||
'Currency': entry['Health']['Currency'],
|
'Currency': entry['Health']['Currency'],
|
||||||
|
Loading…
Reference in New Issue
Block a user