|
|
|
@@ -185,7 +185,7 @@ def test_check_available_stake_amount(default_conf, ticker, mocker, fee, limit_b
|
|
|
|
|
limit_buy_order_open['id'] = str(i)
|
|
|
|
|
result = freqtrade.wallets.get_trade_stake_amount('ETH/BTC')
|
|
|
|
|
assert pytest.approx(result) == expected[i]
|
|
|
|
|
freqtrade.execute_buy('ETH/BTC', result)
|
|
|
|
|
freqtrade.execute_entry('ETH/BTC', result)
|
|
|
|
|
else:
|
|
|
|
|
with pytest.raises(DependencyException):
|
|
|
|
|
freqtrade.wallets.get_trade_stake_amount('ETH/BTC')
|
|
|
|
@@ -584,8 +584,8 @@ def test_create_trades_preopen(default_conf, ticker, fee, mocker, limit_buy_orde
|
|
|
|
|
patch_get_signal(freqtrade)
|
|
|
|
|
|
|
|
|
|
# Create 2 existing trades
|
|
|
|
|
freqtrade.execute_buy('ETH/BTC', default_conf['stake_amount'])
|
|
|
|
|
freqtrade.execute_buy('NEO/BTC', default_conf['stake_amount'])
|
|
|
|
|
freqtrade.execute_entry('ETH/BTC', default_conf['stake_amount'])
|
|
|
|
|
freqtrade.execute_entry('NEO/BTC', default_conf['stake_amount'])
|
|
|
|
|
|
|
|
|
|
assert len(Trade.get_open_trades()) == 2
|
|
|
|
|
# Change order_id for new orders
|
|
|
|
@@ -776,7 +776,7 @@ def test_process_informative_pairs_added(default_conf, ticker, mocker) -> None:
|
|
|
|
|
assert ("ETH/BTC", default_conf["timeframe"]) in refresh_mock.call_args[0][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order_open) -> None:
|
|
|
|
|
def test_execute_entry(mocker, default_conf, fee, limit_buy_order, limit_buy_order_open) -> None:
|
|
|
|
|
patch_RPCManager(mocker)
|
|
|
|
|
patch_exchange(mocker)
|
|
|
|
|
freqtrade = FreqtradeBot(default_conf)
|
|
|
|
@@ -799,7 +799,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|
|
|
|
)
|
|
|
|
|
pair = 'ETH/BTC'
|
|
|
|
|
|
|
|
|
|
assert not freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
assert not freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
assert buy_rate_mock.call_count == 1
|
|
|
|
|
assert buy_mm.call_count == 0
|
|
|
|
|
assert freqtrade.strategy.confirm_trade_entry.call_count == 1
|
|
|
|
@@ -807,7 +807,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|
|
|
|
|
|
|
|
|
limit_buy_order_open['id'] = '22'
|
|
|
|
|
freqtrade.strategy.confirm_trade_entry = MagicMock(return_value=True)
|
|
|
|
|
assert freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
assert freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
assert buy_rate_mock.call_count == 1
|
|
|
|
|
assert buy_mm.call_count == 1
|
|
|
|
|
call_args = buy_mm.call_args_list[0][1]
|
|
|
|
@@ -826,7 +826,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|
|
|
|
# Test calling with price
|
|
|
|
|
limit_buy_order_open['id'] = '33'
|
|
|
|
|
fix_price = 0.06
|
|
|
|
|
assert freqtrade.execute_buy(pair, stake_amount, fix_price)
|
|
|
|
|
assert freqtrade.execute_entry(pair, stake_amount, fix_price)
|
|
|
|
|
# Make sure get_rate wasn't called again
|
|
|
|
|
assert buy_rate_mock.call_count == 0
|
|
|
|
|
|
|
|
|
@@ -844,7 +844,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|
|
|
|
|
|
|
|
|
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
|
|
|
|
MagicMock(return_value=limit_buy_order))
|
|
|
|
|
assert freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
assert freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
trade = Trade.query.all()[2]
|
|
|
|
|
assert trade
|
|
|
|
|
assert trade.open_order_id is None
|
|
|
|
@@ -861,7 +861,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|
|
|
|
limit_buy_order['id'] = '555'
|
|
|
|
|
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
|
|
|
|
MagicMock(return_value=limit_buy_order))
|
|
|
|
|
assert freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
assert freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
trade = Trade.query.all()[3]
|
|
|
|
|
assert trade
|
|
|
|
|
assert trade.open_order_id == '555'
|
|
|
|
@@ -873,7 +873,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|
|
|
|
limit_buy_order['id'] = '556'
|
|
|
|
|
|
|
|
|
|
freqtrade.strategy.custom_stake_amount = lambda **kwargs: 150.0
|
|
|
|
|
assert freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
assert freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
trade = Trade.query.all()[4]
|
|
|
|
|
assert trade
|
|
|
|
|
assert trade.stake_amount == 150
|
|
|
|
@@ -881,7 +881,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|
|
|
|
# Exception case
|
|
|
|
|
limit_buy_order['id'] = '557'
|
|
|
|
|
freqtrade.strategy.custom_stake_amount = lambda **kwargs: 20 / 0
|
|
|
|
|
assert freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
assert freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
trade = Trade.query.all()[5]
|
|
|
|
|
assert trade
|
|
|
|
|
assert trade.stake_amount == 2.0
|
|
|
|
@@ -896,20 +896,20 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|
|
|
|
limit_buy_order['id'] = '66'
|
|
|
|
|
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
|
|
|
|
MagicMock(return_value=limit_buy_order))
|
|
|
|
|
assert not freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
assert not freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
|
|
|
|
|
# Fail to get price...
|
|
|
|
|
mocker.patch('freqtrade.exchange.Exchange.get_rate', MagicMock(return_value=0.0))
|
|
|
|
|
|
|
|
|
|
with pytest.raises(PricingError, match="Could not determine buy price."):
|
|
|
|
|
freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
|
|
|
|
|
# In case of custom entry price
|
|
|
|
|
mocker.patch('freqtrade.exchange.Exchange.get_rate', return_value=0.50)
|
|
|
|
|
limit_buy_order['status'] = 'open'
|
|
|
|
|
limit_buy_order['id'] = '5566'
|
|
|
|
|
freqtrade.strategy.custom_entry_price = lambda **kwargs: 0.508
|
|
|
|
|
assert freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
assert freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
trade = Trade.query.all()[6]
|
|
|
|
|
assert trade
|
|
|
|
|
assert trade.open_rate_requested == 0.508
|
|
|
|
@@ -924,7 +924,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|
|
|
|
get_rate=MagicMock(return_value=10),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
assert freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
trade = Trade.query.all()[7]
|
|
|
|
|
assert trade
|
|
|
|
|
assert trade.open_rate_requested == 10
|
|
|
|
@@ -933,13 +933,13 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|
|
|
|
limit_buy_order['status'] = 'open'
|
|
|
|
|
limit_buy_order['id'] = '5568'
|
|
|
|
|
freqtrade.strategy.custom_entry_price = lambda **kwargs: "string price"
|
|
|
|
|
assert freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
assert freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
trade = Trade.query.all()[8]
|
|
|
|
|
assert trade
|
|
|
|
|
assert trade.open_rate_requested == 10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_execute_buy_confirm_error(mocker, default_conf, fee, limit_buy_order) -> None:
|
|
|
|
|
def test_execute_entry_confirm_error(mocker, default_conf, fee, limit_buy_order) -> None:
|
|
|
|
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
|
|
|
|
mocker.patch.multiple(
|
|
|
|
|
'freqtrade.exchange.Exchange',
|
|
|
|
@@ -957,18 +957,18 @@ def test_execute_buy_confirm_error(mocker, default_conf, fee, limit_buy_order) -
|
|
|
|
|
pair = 'ETH/BTC'
|
|
|
|
|
|
|
|
|
|
freqtrade.strategy.confirm_trade_entry = MagicMock(side_effect=ValueError)
|
|
|
|
|
assert freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
assert freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
|
|
|
|
|
limit_buy_order['id'] = '222'
|
|
|
|
|
freqtrade.strategy.confirm_trade_entry = MagicMock(side_effect=Exception)
|
|
|
|
|
assert freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
assert freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
|
|
|
|
|
limit_buy_order['id'] = '2223'
|
|
|
|
|
freqtrade.strategy.confirm_trade_entry = MagicMock(return_value=True)
|
|
|
|
|
assert freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
assert freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
|
|
|
|
|
freqtrade.strategy.confirm_trade_entry = MagicMock(return_value=False)
|
|
|
|
|
assert not freqtrade.execute_buy(pair, stake_amount)
|
|
|
|
|
assert not freqtrade.execute_entry(pair, stake_amount)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_stoploss_on_exchange(mocker, default_conf, limit_buy_order) -> None:
|
|
|
|
|