Rename process_maybe_execute_buys() --> enter_positions()

This commit is contained in:
hroff-1902 2019-12-30 22:50:56 +03:00
parent 84918ad424
commit fd7af587da
6 changed files with 96 additions and 88 deletions

View File

@ -137,7 +137,7 @@ class FreqtradeBot:
# Then looking for buy opportunities
if self.get_free_open_trades():
self.process_maybe_execute_buys()
self.enter_positions()
# Check and handle any timed out open orders
self.check_handle_timedout()
@ -460,9 +460,9 @@ class FreqtradeBot:
return True
def process_maybe_execute_buys(self) -> int:
def enter_positions(self) -> int:
"""
Tries to execute buy orders for trades in a safe way
Tries to execute buy orders for new trades (positions)
"""
trades_created = 0

View File

@ -41,7 +41,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
with pytest.raises(RPCException, match=r'.*no active trade*'):
rpc._rpc_trade_status()
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
results = rpc._rpc_trade_status()
assert {
'trade_id': 1,
@ -116,7 +116,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
with pytest.raises(RPCException, match=r'.*no active order*'):
rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
result, headers = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
assert "Since" in headers
@ -162,7 +162,7 @@ def test_rpc_daily_profit(default_conf, update, ticker, fee,
rpc = RPC(freqtradebot)
rpc._fiat_converter = CryptoToFiatConverter()
# Create some test data
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
trade = Trade.query.first()
assert trade
@ -217,7 +217,7 @@ def test_rpc_trade_statistics(default_conf, ticker, ticker_sell_up, fee,
rpc._rpc_trade_statistics(stake_currency, fiat_display_currency)
# Create some test data
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
trade = Trade.query.first()
# Simulate fulfilled LIMIT_BUY order for trade
trade.update(limit_buy_order)
@ -231,7 +231,7 @@ def test_rpc_trade_statistics(default_conf, ticker, ticker_sell_up, fee,
trade.close_date = datetime.utcnow()
trade.is_open = False
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
trade = Trade.query.first()
# Simulate fulfilled LIMIT_BUY order for trade
trade.update(limit_buy_order)
@ -299,7 +299,7 @@ def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, fee,
rpc = RPC(freqtradebot)
# Create some test data
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
trade = Trade.query.first()
# Simulate fulfilled LIMIT_BUY order for trade
trade.update(limit_buy_order)
@ -529,7 +529,7 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker) -> None:
msg = rpc._rpc_forcesell('all')
assert msg == {'result': 'Created sell orders for all open trades.'}
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
msg = rpc._rpc_forcesell('all')
assert msg == {'result': 'Created sell orders for all open trades.'}
@ -563,7 +563,7 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker) -> None:
assert cancel_order_mock.call_count == 1
assert trade.amount == filled_amount
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
trade = Trade.query.filter(Trade.id == '2').first()
amount = trade.amount
# make an limit-buy open trade, if there is no 'filled', don't sell it
@ -582,7 +582,7 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker) -> None:
assert cancel_order_mock.call_count == 2
assert trade.amount == amount
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
# make an limit-sell open trade
mocker.patch(
'freqtrade.exchange.Exchange.get_order',
@ -613,7 +613,7 @@ def test_performance_handle(default_conf, ticker, limit_buy_order, fee,
rpc = RPC(freqtradebot)
# Create some test data
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
trade = Trade.query.first()
assert trade
@ -649,7 +649,7 @@ def test_rpc_count(mocker, default_conf, ticker, fee) -> None:
assert counts["current"] == 0
# Create some test data
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
counts = rpc._rpc_count()
assert counts["current"] == 1

View File

@ -267,7 +267,7 @@ def test_api_count(botclient, mocker, ticker, fee, markets):
assert rc.json["max"] == 1.0
# Create some test data
ftbot.process_maybe_execute_buys()
ftbot.enter_positions()
rc = client_get(client, f"{BASE_URI}/count")
assert_response(rc)
assert rc.json["current"] == 1.0
@ -333,7 +333,7 @@ def test_api_profit(botclient, mocker, ticker, fee, markets, limit_buy_order, li
assert len(rc.json) == 1
assert rc.json == {"error": "Error querying _profit: no closed trade"}
ftbot.process_maybe_execute_buys()
ftbot.enter_positions()
trade = Trade.query.first()
# Simulate fulfilled LIMIT_BUY order for trade
@ -422,7 +422,7 @@ def test_api_status(botclient, mocker, ticker, fee, markets):
assert_response(rc, 200)
assert rc.json == []
ftbot.process_maybe_execute_buys()
ftbot.enter_positions()
rc = client_get(client, f"{BASE_URI}/status")
assert_response(rc)
assert len(rc.json) == 1
@ -552,7 +552,7 @@ def test_api_forcesell(botclient, mocker, ticker, fee, markets):
assert_response(rc, 502)
assert rc.json == {"error": "Error querying _forcesell: invalid argument"}
ftbot.process_maybe_execute_buys()
ftbot.enter_positions()
rc = client_post(client, f"{BASE_URI}/forcesell",
data='{"tradeid": "1"}')

View File

@ -188,8 +188,8 @@ def test_status(default_conf, update, mocker, fee, ticker,) -> None:
telegram = Telegram(freqtradebot)
# Create some test data
for _ in range(3):
freqtradebot.process_maybe_execute_buys()
n = freqtradebot.enter_positions()
assert n == 1
telegram._status(update=update, context=MagicMock())
assert msg_mock.call_count == 1
@ -236,7 +236,7 @@ def test_status_handle(default_conf, update, ticker, fee, mocker) -> None:
msg_mock.reset_mock()
# Create some test data
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
# Trigger status while we have a fulfilled order for the open trade
telegram._status(update=update, context=MagicMock())
@ -285,7 +285,7 @@ def test_status_table_handle(default_conf, update, ticker, fee, mocker) -> None:
msg_mock.reset_mock()
# Create some test data
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
telegram._status_table(update=update, context=MagicMock())
@ -322,7 +322,7 @@ def test_daily_handle(default_conf, update, ticker, limit_buy_order, fee,
telegram = Telegram(freqtradebot)
# Create some test data
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
trade = Trade.query.first()
assert trade
@ -352,7 +352,8 @@ def test_daily_handle(default_conf, update, ticker, limit_buy_order, fee,
msg_mock.reset_mock()
freqtradebot.config['max_open_trades'] = 2
# Add two other trades
freqtradebot.process_maybe_execute_buys()
n = freqtradebot.enter_positions()
assert n == 2
trades = Trade.query.all()
for trade in trades:
@ -431,7 +432,7 @@ def test_profit_handle(default_conf, update, ticker, ticker_sell_up, fee,
msg_mock.reset_mock()
# Create some test data
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
trade = Trade.query.first()
# Simulate fulfilled LIMIT_BUY order for trade
@ -709,7 +710,7 @@ def test_forcesell_handle(default_conf, update, ticker, fee,
telegram = Telegram(freqtradebot)
# Create some test data
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
trade = Trade.query.first()
assert trade
@ -764,7 +765,7 @@ def test_forcesell_down_handle(default_conf, update, ticker, fee,
telegram = Telegram(freqtradebot)
# Create some test data
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
# Decrease the price and sell it
mocker.patch.multiple(
@ -821,7 +822,7 @@ def test_forcesell_all_handle(default_conf, update, ticker, fee, mocker) -> None
telegram = Telegram(freqtradebot)
# Create some test data
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
rpc_mock.reset_mock()
# /forcesell all
@ -971,7 +972,7 @@ def test_performance_handle(default_conf, update, ticker, fee,
telegram = Telegram(freqtradebot)
# Create some test data
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
trade = Trade.query.first()
assert trade
@ -1014,7 +1015,7 @@ def test_count_handle(default_conf, update, ticker, fee, mocker) -> None:
freqtradebot.state = State.RUNNING
# Create some test data
freqtradebot.process_maybe_execute_buys()
freqtradebot.enter_positions()
msg_mock.reset_mock()
telegram._count(update=update, context=MagicMock())

View File

@ -247,7 +247,7 @@ def test_edge_overrides_stoploss(limit_buy_order, fee, caplog, mocker, edge_conf
freqtrade.active_pair_whitelist = ['NEO/BTC']
patch_get_signal(freqtrade)
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.update(limit_buy_order)
#############################################
@ -287,7 +287,7 @@ def test_edge_should_ignore_strategy_stoploss(limit_buy_order, fee,
freqtrade.active_pair_whitelist = ['NEO/BTC']
patch_get_signal(freqtrade)
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.update(limit_buy_order)
#############################################
@ -310,7 +310,7 @@ def test_total_open_trades_stakes(mocker, default_conf, ticker,
)
freqtrade = FreqtradeBot(default_conf)
patch_get_signal(freqtrade)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
assert trade is not None
@ -318,7 +318,7 @@ def test_total_open_trades_stakes(mocker, default_conf, ticker,
assert trade.is_open
assert trade.open_date is not None
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.order_by(Trade.id.desc()).first()
assert trade is not None
@ -573,9 +573,8 @@ def test_create_trade_limit_reached(default_conf, ticker, limit_buy_order,
assert freqtrade.get_trade_stake_amount('ETH/BTC') is None
def test_process_maybe_execute_buys_no_pairs_let(default_conf, ticker,
limit_buy_order, fee,
mocker, caplog) -> None:
def test_enter_positions_no_pairs_left(default_conf, ticker, limit_buy_order, fee,
mocker, caplog) -> None:
patch_RPCManager(mocker)
patch_exchange(mocker)
mocker.patch.multiple(
@ -589,15 +588,16 @@ def test_process_maybe_execute_buys_no_pairs_let(default_conf, ticker,
freqtrade = FreqtradeBot(default_conf)
patch_get_signal(freqtrade)
freqtrade.process_maybe_execute_buys()
n = freqtrade.enter_positions()
assert n == 1
assert not log_has_re(r"No currency pair in active pair whitelist.*", caplog)
freqtrade.process_maybe_execute_buys()
n = freqtrade.enter_positions()
assert n == 0
assert log_has_re(r"No currency pair in active pair whitelist.*", caplog)
def test_process_maybe_execute_buys_no_pairs_in_whitelist(default_conf, ticker,
limit_buy_order, fee,
mocker, caplog) -> None:
def test_enter_positions_no_pairs_in_whitelist(default_conf, ticker, limit_buy_order, fee,
mocker, caplog) -> None:
patch_RPCManager(mocker)
patch_exchange(mocker)
mocker.patch.multiple(
@ -610,7 +610,8 @@ def test_process_maybe_execute_buys_no_pairs_in_whitelist(default_conf, ticker,
freqtrade = FreqtradeBot(default_conf)
patch_get_signal(freqtrade)
freqtrade.process_maybe_execute_buys()
n = freqtrade.enter_positions()
assert n == 0
assert log_has("Active pair whitelist is empty.", caplog)
@ -648,7 +649,8 @@ def test_create_trades_multiple_trades(default_conf, ticker,
freqtrade = FreqtradeBot(default_conf)
patch_get_signal(freqtrade)
freqtrade.process_maybe_execute_buys()
n = freqtrade.enter_positions()
assert n == max_open
trades = Trade.get_open_trades()
assert len(trades) == max_open
@ -1059,7 +1061,7 @@ def test_handle_stoploss_on_exchange(mocker, default_conf, fee, caplog,
# should unset stoploss_order_id and return true
# as a trade actually happened
caplog.clear()
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.is_open = True
trade.open_order_id = None
@ -1117,7 +1119,7 @@ def test_handle_sle_cancel_cant_recreate(mocker, default_conf, fee, caplog,
freqtrade = FreqtradeBot(default_conf)
patch_get_signal(freqtrade)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.is_open = True
trade.open_order_id = '12345'
@ -1152,7 +1154,7 @@ def test_create_stoploss_order_invalid_order(mocker, default_conf, caplog, fee,
patch_get_signal(freqtrade)
freqtrade.strategy.order_types['stoploss_on_exchange'] = True
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
caplog.clear()
freqtrade.create_stoploss_order(trade, 200, 199)
@ -1210,7 +1212,7 @@ def test_handle_stoploss_on_exchange_trailing(mocker, default_conf, fee, caplog,
patch_get_signal(freqtrade)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.is_open = True
trade.open_order_id = None
@ -1298,7 +1300,7 @@ def test_handle_stoploss_on_exchange_trailing_error(mocker, default_conf, fee, c
# setting stoploss_on_exchange_interval to 60 seconds
freqtrade.strategy.order_types['stoploss_on_exchange_interval'] = 60
patch_get_signal(freqtrade)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.is_open = True
trade.open_order_id = None
@ -1379,7 +1381,7 @@ def test_tsl_on_exchange_compatible_with_edge(mocker, edge_conf, fee, caplog,
freqtrade.active_pair_whitelist = freqtrade.edge.adjust(freqtrade.active_pair_whitelist)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.is_open = True
trade.open_order_id = None
@ -1443,23 +1445,25 @@ def test_tsl_on_exchange_compatible_with_edge(mocker, edge_conf, fee, caplog,
stop_price=0.00002344 * 0.99)
def test_process_maybe_execute_buys(mocker, default_conf, caplog) -> None:
def test_enter_positions(mocker, default_conf, caplog) -> None:
caplog.set_level(logging.DEBUG)
freqtrade = get_patched_freqtradebot(mocker, default_conf)
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.create_trade', MagicMock(return_value=False))
freqtrade.process_maybe_execute_buys()
n = freqtrade.enter_positions()
assert n == 0
assert log_has('Found no buy signals for whitelisted currencies. Trying again...', caplog)
def test_process_maybe_execute_buys_exception(mocker, default_conf, caplog) -> None:
def test_enter_positions_exception(mocker, default_conf, caplog) -> None:
freqtrade = get_patched_freqtradebot(mocker, default_conf)
mocker.patch(
'freqtrade.freqtradebot.FreqtradeBot.create_trade',
MagicMock(side_effect=DependencyException)
)
freqtrade.process_maybe_execute_buys()
n = freqtrade.enter_positions()
assert n == 0
assert log_has('Unable to create trade: ', caplog)
@ -1679,7 +1683,7 @@ def test_handle_trade(default_conf, limit_buy_order, limit_sell_order, fee, mock
freqtrade = FreqtradeBot(default_conf)
patch_get_signal(freqtrade)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
assert trade
@ -1702,7 +1706,7 @@ def test_handle_trade(default_conf, limit_buy_order, limit_sell_order, fee, mock
assert trade.close_date is not None
def test_handle_overlpapping_signals(default_conf, ticker, limit_buy_order, fee, mocker) -> None:
def test_handle_overlapping_signals(default_conf, ticker, limit_buy_order, fee, mocker) -> None:
patch_RPCManager(mocker)
patch_exchange(mocker)
mocker.patch.multiple(
@ -1716,7 +1720,7 @@ def test_handle_overlpapping_signals(default_conf, ticker, limit_buy_order, fee,
patch_get_signal(freqtrade, value=(True, True))
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
# Buy and Sell triggering, so doing nothing ...
trades = Trade.query.all()
@ -1725,7 +1729,7 @@ def test_handle_overlpapping_signals(default_conf, ticker, limit_buy_order, fee,
# Buy is triggering, so buying ...
patch_get_signal(freqtrade, value=(True, False))
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trades = Trade.query.all()
nb_trades = len(trades)
assert nb_trades == 1
@ -1769,7 +1773,7 @@ def test_handle_trade_roi(default_conf, ticker, limit_buy_order,
patch_get_signal(freqtrade, value=(True, False))
freqtrade.strategy.min_roi_reached = MagicMock(return_value=True)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.is_open = True
@ -1800,7 +1804,7 @@ def test_handle_trade_use_sell_signal(
freqtrade = get_patched_freqtradebot(mocker, default_conf)
patch_get_signal(freqtrade)
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.is_open = True
@ -1828,7 +1832,7 @@ def test_close_trade(default_conf, ticker, limit_buy_order, limit_sell_order,
patch_get_signal(freqtrade)
# Create trade and sell it
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
assert trade
@ -2188,7 +2192,7 @@ def test_execute_sell_up(default_conf, ticker, fee, ticker_sell_up, mocker) -> N
patch_get_signal(freqtrade)
# Create some test data
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
assert trade
@ -2236,7 +2240,7 @@ def test_execute_sell_down(default_conf, ticker, fee, ticker_sell_down, mocker)
patch_get_signal(freqtrade)
# Create some test data
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
assert trade
@ -2286,7 +2290,7 @@ def test_execute_sell_down_stoploss_on_exchange_dry_run(default_conf, ticker, fe
patch_get_signal(freqtrade)
# Create some test data
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
assert trade
@ -2344,7 +2348,7 @@ def test_execute_sell_sloe_cancel_exception(mocker, default_conf, ticker, fee, c
freqtrade.strategy.order_types['stoploss_on_exchange'] = True
patch_get_signal(freqtrade)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
Trade.session = MagicMock()
@ -2387,7 +2391,7 @@ def test_execute_sell_with_stoploss_on_exchange(default_conf, ticker, fee, ticke
patch_get_signal(freqtrade)
# Create some test data
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
assert trade
@ -2437,7 +2441,7 @@ def test_may_execute_sell_after_stoploss_on_exchange_hit(default_conf, ticker, f
patch_get_signal(freqtrade)
# Create some test data
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trades = [trade]
freqtrade.exit_positions(trades)
@ -2489,7 +2493,7 @@ def test_execute_sell_market_order(default_conf, ticker, fee,
patch_get_signal(freqtrade)
# Create some test data
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
assert trade
@ -2551,7 +2555,7 @@ def test_sell_profit_only_enable_profit(default_conf, limit_buy_order,
patch_get_signal(freqtrade)
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.update(limit_buy_order)
@ -2582,7 +2586,7 @@ def test_sell_profit_only_disable_profit(default_conf, limit_buy_order,
freqtrade = FreqtradeBot(default_conf)
patch_get_signal(freqtrade)
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.update(limit_buy_order)
@ -2613,7 +2617,7 @@ def test_sell_profit_only_enable_loss(default_conf, limit_buy_order, fee, mocker
patch_get_signal(freqtrade)
freqtrade.strategy.stop_loss_reached = MagicMock(return_value=SellCheckTuple(
sell_flag=False, sell_type=SellType.NONE))
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.update(limit_buy_order)
@ -2643,7 +2647,7 @@ def test_sell_profit_only_disable_loss(default_conf, limit_buy_order, fee, mocke
patch_get_signal(freqtrade)
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.update(limit_buy_order)
@ -2672,7 +2676,7 @@ def test_sell_not_enough_balance(default_conf, limit_buy_order,
patch_get_signal(freqtrade)
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
amnt = trade.amount
@ -2740,7 +2744,7 @@ def test_locked_pairs(default_conf, ticker, fee, ticker_sell_down, mocker, caplo
patch_get_signal(freqtrade)
# Create some test data
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
assert trade
@ -2759,7 +2763,7 @@ def test_locked_pairs(default_conf, ticker, fee, ticker_sell_down, mocker, caplo
# reinit - should buy other pair.
caplog.clear()
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
assert log_has(f"Pair {trade.pair} is currently locked.", caplog)
@ -2784,7 +2788,7 @@ def test_ignore_roi_if_buy_signal(default_conf, limit_buy_order, fee, mocker) ->
patch_get_signal(freqtrade)
freqtrade.strategy.min_roi_reached = MagicMock(return_value=True)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.update(limit_buy_order)
@ -2817,7 +2821,7 @@ def test_trailing_stop_loss(default_conf, limit_buy_order, fee, caplog, mocker)
patch_get_signal(freqtrade)
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
assert freqtrade.handle_trade(trade) is False
@ -2872,7 +2876,7 @@ def test_trailing_stop_loss_positive(default_conf, limit_buy_order, fee,
freqtrade = FreqtradeBot(default_conf)
patch_get_signal(freqtrade)
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.update(limit_buy_order)
@ -2929,7 +2933,7 @@ def test_trailing_stop_loss_offset(default_conf, limit_buy_order, fee,
freqtrade = FreqtradeBot(default_conf)
patch_get_signal(freqtrade)
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.update(limit_buy_order)
@ -2992,7 +2996,7 @@ def test_tsl_only_offset_reached(default_conf, limit_buy_order, fee,
freqtrade = FreqtradeBot(default_conf)
patch_get_signal(freqtrade)
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.update(limit_buy_order)
@ -3051,7 +3055,7 @@ def test_disable_ignore_roi_if_buy_signal(default_conf, limit_buy_order,
patch_get_signal(freqtrade)
freqtrade.strategy.min_roi_reached = MagicMock(return_value=True)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
trade.update(limit_buy_order)
@ -3382,7 +3386,7 @@ def test_order_book_depth_of_market(default_conf, ticker, limit_buy_order, fee,
whitelist = deepcopy(default_conf['exchange']['pair_whitelist'])
freqtrade = FreqtradeBot(default_conf)
patch_get_signal(freqtrade)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
assert trade is not None
@ -3417,7 +3421,7 @@ def test_order_book_depth_of_market_high_delta(default_conf, ticker, limit_buy_o
# Save state of current whitelist
freqtrade = FreqtradeBot(default_conf)
patch_get_signal(freqtrade)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
assert trade is None
@ -3519,7 +3523,7 @@ def test_order_book_ask_strategy(default_conf, limit_buy_order, limit_sell_order
freqtrade = FreqtradeBot(default_conf)
patch_get_signal(freqtrade)
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
trade = Trade.query.first()
assert trade
@ -3626,12 +3630,14 @@ def test_sync_wallet_dry_run(mocker, default_conf, ticker, fee, limit_buy_order,
patch_get_signal(bot)
assert bot.wallets.get_free('BTC') == 0.002
bot.process_maybe_execute_buys()
n = bot.enter_positions()
assert n == 2
trades = Trade.query.all()
assert len(trades) == 2
bot.config['max_open_trades'] = 3
bot.process_maybe_execute_buys()
n = bot.enter_positions()
assert n == 0
assert log_has_re(r"Unable to create trade: "
r"Available balance \(0 BTC\) is lower than stake amount \(0.001 BTC\)",
caplog)

View File

@ -80,7 +80,7 @@ def test_may_execute_sell_stoploss_on_exchange_multi(default_conf, ticker, fee,
patch_get_signal(freqtrade)
# Create some test data
freqtrade.process_maybe_execute_buys()
freqtrade.enter_positions()
wallets_mock.reset_mock()
Trade.session = MagicMock()
@ -154,7 +154,8 @@ def test_forcebuy_last_unlimited(default_conf, ticker, fee, limit_buy_order, moc
patch_get_signal(freqtrade)
# Create 4 trades
freqtrade.process_maybe_execute_buys()
n = freqtrade.enter_positions()
assert n == 4
trades = Trade.query.all()
assert len(trades) == 4