From 1bba2a5f216d3d1e3863442e0ec57c1b9dd5f0f5 Mon Sep 17 00:00:00 2001 From: Axel-CH Date: Mon, 3 Mar 2025 14:32:39 -0400 Subject: [PATCH 1/6] chore: add a warning log if custom_price_max_distance_ratio change the price --- freqtrade/freqtradebot.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 8b9d4ed31..d3d2cc081 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -2587,4 +2587,12 @@ class FreqtradeBot(LoggingMixin): max_custom_price_allowed = proposed_price + (proposed_price * cust_p_max_dist_r) # Bracket between min_custom_price_allowed and max_custom_price_allowed - return max(min(valid_custom_price, max_custom_price_allowed), min_custom_price_allowed) + final_price = max(min(valid_custom_price, max_custom_price_allowed), min_custom_price_allowed) + + # Log a warning if the custom price was adjusted by clamping. + if final_price != valid_custom_price: + logger.warning( + f"Custom price adjusted from {valid_custom_price} to {final_price} based on custom_price_max_distance_ratio of {cust_p_max_dist_r}." + ) + + return final_price From facfdfd85c72e243be2ba1103adedcd2b7ebdea0 Mon Sep 17 00:00:00 2001 From: Axel-CH Date: Mon, 3 Mar 2025 14:42:16 -0400 Subject: [PATCH 2/6] chore: add price in execute_entry logs --- freqtrade/freqtradebot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index d3d2cc081..4626cb3e1 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -903,14 +903,14 @@ class FreqtradeBot(LoggingMixin): msg = ( f"Position adjust: about to create a new order for {pair} with stake_amount: " - f"{stake_amount} for {trade}" + f"{stake_amount} and price: {enter_limit_requested} for {trade}" if mode == "pos_adjust" else ( f"Replacing {side} order: about create a new order for {pair} with stake_amount: " - f"{stake_amount} ..." + f"{stake_amount} and price: {enter_limit_requested} ..." if mode == "replace" else f"{name} signal found: about create a new trade for {pair} with stake_amount: " - f"{stake_amount} ..." + f"{stake_amount} and price: {enter_limit_requested} ..." ) ) logger.info(msg) From ad2aef09c40c0cf23e013b1d5e3bf18eed7dee74 Mon Sep 17 00:00:00 2001 From: Axel-CH Date: Mon, 3 Mar 2025 14:55:15 -0400 Subject: [PATCH 3/6] chore: fix format --- freqtrade/freqtradebot.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 4626cb3e1..cfe789af7 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -2587,12 +2587,15 @@ class FreqtradeBot(LoggingMixin): max_custom_price_allowed = proposed_price + (proposed_price * cust_p_max_dist_r) # Bracket between min_custom_price_allowed and max_custom_price_allowed - final_price = max(min(valid_custom_price, max_custom_price_allowed), min_custom_price_allowed) - + final_price = max( + min(valid_custom_price, max_custom_price_allowed), min_custom_price_allowed + ) + # Log a warning if the custom price was adjusted by clamping. if final_price != valid_custom_price: logger.warning( - f"Custom price adjusted from {valid_custom_price} to {final_price} based on custom_price_max_distance_ratio of {cust_p_max_dist_r}." + f"Custom price adjusted from {valid_custom_price} to {final_price} based on " + "custom_price_max_distance_ratio of {cust_p_max_dist_r}." ) - + return final_price From dfe698209950035cf4ac5317e8077e4154cbe0bd Mon Sep 17 00:00:00 2001 From: Axel-CH Date: Mon, 3 Mar 2025 15:18:04 -0400 Subject: [PATCH 4/6] chore: change log level of get_valid_price log from warning to info --- freqtrade/freqtradebot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index cfe789af7..4af00ebaa 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -2593,7 +2593,7 @@ class FreqtradeBot(LoggingMixin): # Log a warning if the custom price was adjusted by clamping. if final_price != valid_custom_price: - logger.warning( + logger.info( f"Custom price adjusted from {valid_custom_price} to {final_price} based on " "custom_price_max_distance_ratio of {cust_p_max_dist_r}." ) From e055feb1d3d0408e3a964c4f355376f00a6ca19d Mon Sep 17 00:00:00 2001 From: Axel-CH Date: Mon, 3 Mar 2025 15:32:41 -0400 Subject: [PATCH 5/6] chore: update test_process_trade_creation test --- tests/freqtradebot/test_freqtradebot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/freqtradebot/test_freqtradebot.py b/tests/freqtradebot/test_freqtradebot.py index e66e5065c..e9a1082d2 100644 --- a/tests/freqtradebot/test_freqtradebot.py +++ b/tests/freqtradebot/test_freqtradebot.py @@ -701,11 +701,11 @@ def test_process_trade_creation( assert pytest.approx(trade.amount) == 0 assert pytest.approx(trade.amount_requested) == 60 / ticker_usdt.return_value[ticker_side] - assert log_has( + expected_log = ( f"{'Short' if is_short else 'Long'} signal found: about create a new trade for ETH/USDT " - "with stake_amount: 60.0 ...", - caplog, + "with stake_amount: 60.0" ) + assert expected_log in caplog.text mocker.patch("freqtrade.freqtradebot.FreqtradeBot._check_and_execute_exit") # Fill trade. From f785f9ff009a5a186d7a7a5e4208b32e4921138f Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 4 Mar 2025 06:46:13 +0100 Subject: [PATCH 6/6] chore: use log_has_re for test log assertion --- tests/freqtradebot/test_freqtradebot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/freqtradebot/test_freqtradebot.py b/tests/freqtradebot/test_freqtradebot.py index e9a1082d2..3ff8fcb5e 100644 --- a/tests/freqtradebot/test_freqtradebot.py +++ b/tests/freqtradebot/test_freqtradebot.py @@ -701,11 +701,11 @@ def test_process_trade_creation( assert pytest.approx(trade.amount) == 0 assert pytest.approx(trade.amount_requested) == 60 / ticker_usdt.return_value[ticker_side] - expected_log = ( + assert log_has_re( f"{'Short' if is_short else 'Long'} signal found: about create a new trade for ETH/USDT " - "with stake_amount: 60.0" + r"with stake_amount: 60.0 and price: .*", + caplog, ) - assert expected_log in caplog.text mocker.patch("freqtrade.freqtradebot.FreqtradeBot._check_and_execute_exit") # Fill trade.