remove maybe_update_amount and tests

This commit is contained in:
Matthias Voppichler 2018-04-23 20:03:10 +02:00
parent 93a7c46977
commit f580fbb91d
2 changed files with 1 additions and 73 deletions

View File

@ -375,6 +375,7 @@ class FreqtradeBot(object):
logger.info("Updating amount for Trade {} from {} to {}".format(
trade, order['amount'], new_amount))
order['amount'] = new_amount
# Fee was applied, so set to 0
trade.fee_open = 0
except OperationalException as exception:
@ -413,29 +414,6 @@ class FreqtradeBot(object):
real_amount = amount - fee_abs
return real_amount
def maybe_update_real_amount(self, trade: Trade) -> bool:
"""
Updates trade-amount with real amount
:return: True if real-amount has been changed.
"""
if trade.is_open and trade.open_order_id is None:
# Trade is not open anymore
logger.warning("could not open trade amount - Trade is not open anymore")
return False
try:
new_amount = self.get_real_amount(trade)
except OperationalException as exception:
logger.warning("could not update trade amount: %s", exception)
return False
# updating amount
if trade.amount != new_amount:
logger.info("Updating amount for Trade {} from {} to {}".format(
trade, trade.amount, new_amount))
trade.amount = new_amount
trade.fee_open = 0 # Fee was applied - set to 0 for buy
Trade.session.flush()
return True
def handle_trade(self, trade: Trade) -> bool:
"""
Sells the current pair if the threshold is reached and updates the trade record.

View File

@ -1410,53 +1410,3 @@ def test_get_real_amount_multi(default_conf, trades_for_order2, mocker):
freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://'))
# Amount is reduced by "fee"
assert freqtrade.get_real_amount(trade) == amount - (amount * 0.001)
def test_maybe_update_real_amount(default_conf, trades_for_order, mocker):
"""
Test get_real_amount with split trades (multiple trades for this order)
"""
patch_get_signal(mocker)
patch_RPCManager(mocker)
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.exchange.validate_pairs', MagicMock(return_value=True))
mocker.patch('freqtrade.exchange.get_trades_for_order', return_value=trades_for_order)
amount = float(sum(x['amount'] for x in trades_for_order))
trade = Trade(
pair='LTC/ETH',
amount=amount,
exchange='binance',
open_rate=0.245441,
open_order_id="123456"
)
freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://'))
# Amount is reduced by "fee"
assert freqtrade.maybe_update_real_amount(trade) is True
assert trade.amount == amount - (amount * 0.001)
def test_maybe_update_real_amount_stake(default_conf, trades_for_order, mocker):
"""
Test get_real_amount with split trades (multiple trades for this order)
"""
trades_for_order[0]['fee']['currency'] = 'ETH'
patch_get_signal(mocker)
patch_RPCManager(mocker)
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.exchange.validate_pairs', MagicMock(return_value=True))
mocker.patch('freqtrade.exchange.get_trades_for_order', return_value=trades_for_order)
amount = float(sum(x['amount'] for x in trades_for_order))
trade = Trade(
pair='LTC/ETH',
amount=amount,
exchange='binance',
open_rate=0.245441,
open_order_id="123456"
)
freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://'))
# Amount is reduced by "fee"
assert freqtrade.maybe_update_real_amount(trade) is True
assert trade.amount == amount