From d973ba1f5dcf22031bc0463df3e58a968b0673f8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 23 Feb 2022 20:19:52 +0100 Subject: [PATCH] Add leverage callback to advanced template --- freqtrade/strategy/interface.py | 3 +-- .../subtemplates/strategy_methods_advanced.j2 | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 6bfd12851..cc540e368 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -426,8 +426,7 @@ class IStrategy(ABC, HyperStrategyMixin): proposed_leverage: float, max_leverage: float, side: str, **kwargs) -> float: """ - Customize leverage for each new trade. This method is not called when edge module is - enabled. + Customize leverage for each new trade. This method is only called in futures mode. :param pair: Pair that's currently analyzed :param current_time: datetime object, containing the current datetime diff --git a/freqtrade/templates/subtemplates/strategy_methods_advanced.j2 b/freqtrade/templates/subtemplates/strategy_methods_advanced.j2 index f81514b2a..d0b56fe8e 100644 --- a/freqtrade/templates/subtemplates/strategy_methods_advanced.j2 +++ b/freqtrade/templates/subtemplates/strategy_methods_advanced.j2 @@ -232,3 +232,19 @@ def adjust_trade_position(self, trade: 'Trade', current_time: 'datetime', :return float: Stake amount to adjust your trade """ return None + +def leverage(self, pair: str, current_time: datetime, current_rate: float, + proposed_leverage: float, max_leverage: float, side: str, + **kwargs) -> float: + """ + Customize leverage for each new trade. This method is only called in futures mode. + + :param pair: Pair that's currently analyzed + :param current_time: datetime object, containing the current datetime + :param current_rate: Rate, calculated based on pricing settings in ask_strategy. + :param proposed_leverage: A leverage proposed by the bot. + :param max_leverage: Max leverage allowed on this pair + :param side: 'long' or 'short' - indicating the direction of the proposed trade + :return: A leverage amount, which is between 1.0 and max_leverage. + """ + return 1.0