From ac93eea58534734cacce2a986fff25d9a4dafd12 Mon Sep 17 00:00:00 2001 From: Stefano Ariestasia Date: Wed, 19 Jan 2022 21:58:24 +0900 Subject: [PATCH] update --- docs/configuration.md | 2 +- freqtrade/freqtradebot.py | 10 ++++++++++ freqtrade/strategy/interface.py | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 3b7ae3c86..8723f51da 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -173,7 +173,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi | `dataformat_ohlcv` | Data format to use to store historical candle (OHLCV) data.
*Defaults to `json`*.
**Datatype:** String | `dataformat_trades` | Data format to use to store historical trades data.
*Defaults to `jsongz`*.
**Datatype:** String | `position_adjustment_enable` | Enables the strategy to use position adjustments (additional buys or sells). [More information here](strategy-callbacks.md#adjust-trade-position).
[Strategy Override](#parameters-in-the-strategy).
*Defaults to `false`.*
**Datatype:** Boolean -| `max_buy_position_adjustment` | Maximum additional buy(s) for each open trades on top of the first buy. [More information here](strategy-callbacks.md#adjust-trade-position).
[Strategy Override](#parameters-in-the-strategy).
*Defaults to `1`.*
**Datatype:** Positive Integer +| `max_buy_position_adjustment` | Maximum additional buy(s) for each open trades on top of the first buy. Set it to `-1` for unlimited additional buys. [More information here](strategy-callbacks.md#adjust-trade-position).
[Strategy Override](#parameters-in-the-strategy).
*Defaults to `-1`.*
**Datatype:** Positive Integer or -1 ### Parameters in the strategy diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 8980fb91c..f45a49d81 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -473,6 +473,16 @@ class FreqtradeBot(LoggingMixin): If the strategy triggers the adjustment, a new order gets issued. Once that completes, the existing trade is modified to match new data. """ + if self.strategy.max_buy_position_adjustment > -1: + logger.info(f"Max adjustment buy is set to {self.strategy.max_buy_position_adsjutment}.") + + filled_buys = trade.select_filled_orders('buy') + count_of_buys = len(filled_buys) + if count_of_buys > self.strategy.max_buy_position_adjustment: + logger.info(f"Max adjustment buy for {trade.pair} has been reached.") + return + else: + logger.info(f"Max adjustment buy is set to unlimited.") current_rate = self.exchange.get_rate(trade.pair, refresh=True, side="buy") current_profit = trade.calc_profit_ratio(current_rate) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 5a095aed3..41023cc6a 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -108,7 +108,7 @@ class IStrategy(ABC, HyperStrategyMixin): # Position adjustment is disabled by default position_adjustment_enable: bool = False - max_buy_position_adjustment: int = 1 + max_buy_position_adjustment: int = -1 # Number of seconds after which the candle will no longer result in a buy on expired candles ignore_buying_expired_candle_after: int = 0