working on catching the 'sell insufficient funds error'

This commit is contained in:
Gert Wohlgemuth 2018-05-02 12:56:33 -07:00
parent 00aa1bee9d
commit 4322d40967
2 changed files with 68 additions and 56 deletions

View File

@ -82,6 +82,13 @@ class Bittrex(Exchange):
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) Bittrex._validate_response(data)
if data['message'] == "INSUFFICIENT_FUNDS":
raise NotEnoughFundsExeption('{message} params=({pair}, {rate}, {amount})'.format(
message=data['message'],
pair=pair,
rate=rate,
amount=amount))
else:
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,

View File

@ -472,6 +472,9 @@ class FreqtradeBot(object):
:return: None :return: None
""" """
# Execute sell and update trade record # Execute sell and update trade record
# check if we have these funds first
try:
order_id = exchange.sell(str(trade.pair), limit, trade.amount) order_id = exchange.sell(str(trade.pair), limit, trade.amount)
trade.open_order_id = order_id trade.open_order_id = order_id
@ -528,3 +531,5 @@ class FreqtradeBot(object):
# Send the message # Send the message
self.rpc.send_msg(message) self.rpc.send_msg(message)
Trade.session.flush() Trade.session.flush()
except NotEnoughFundsExeption:
logger.warning('Sell order failed, due to not having enough funds for %s.', trade)