diff --git a/config_binance.json.example b/config_binance.json.example index 4fa615d6d..ef0f43873 100644 --- a/config_binance.json.example +++ b/config_binance.json.example @@ -22,8 +22,7 @@ }, "ask_strategy": { "use_order_book": false, - "order_book_min": 1, - "order_book_max": 1, + "order_book_top": 1, "use_sell_signal": true, "sell_profit_only": false, "ignore_roi_if_buy_signal": false diff --git a/config_bittrex.json.example b/config_bittrex.json.example index 172cfcfc3..3c7f2bceb 100644 --- a/config_bittrex.json.example +++ b/config_bittrex.json.example @@ -22,8 +22,7 @@ }, "ask_strategy":{ "use_order_book": false, - "order_book_min": 1, - "order_book_max": 1, + "order_book_top": 1, "use_sell_signal": true, "sell_profit_only": false, "ignore_roi_if_buy_signal": false diff --git a/config_ftx.json.example b/config_ftx.json.example index facd54b25..803fa5899 100644 --- a/config_ftx.json.example +++ b/config_ftx.json.example @@ -22,8 +22,7 @@ }, "ask_strategy": { "use_order_book": false, - "order_book_min": 1, - "order_book_max": 1, + "order_book_top": 1, "use_sell_signal": true, "sell_profit_only": false, "ignore_roi_if_buy_signal": false diff --git a/config_full.json.example b/config_full.json.example index bc9f33f96..7f6a53710 100644 --- a/config_full.json.example +++ b/config_full.json.example @@ -39,8 +39,7 @@ "ask_strategy":{ "price_side": "ask", "use_order_book": false, - "order_book_min": 1, - "order_book_max": 1, + "order_book_top": 1, "use_sell_signal": true, "sell_profit_only": false, "sell_profit_offset": 0.0, diff --git a/config_kraken.json.example b/config_kraken.json.example index 3cd90e5d3..6ebf10403 100644 --- a/config_kraken.json.example +++ b/config_kraken.json.example @@ -22,8 +22,7 @@ }, "ask_strategy":{ "use_order_book": false, - "order_book_min": 1, - "order_book_max": 1, + "order_book_top": 1, "use_sell_signal": true, "sell_profit_only": false, "ignore_roi_if_buy_signal": false diff --git a/freqtrade/configuration/config_validation.py b/freqtrade/configuration/config_validation.py index 3004d6bf7..72c299bed 100644 --- a/freqtrade/configuration/config_validation.py +++ b/freqtrade/configuration/config_validation.py @@ -79,6 +79,7 @@ def validate_config_consistency(conf: Dict[str, Any]) -> None: _validate_whitelist(conf) _validate_protections(conf) _validate_unlimited_amount(conf) + _validate_ask_orderbook(conf) # validate configuration before returning logger.info('Validating configuration ...') @@ -186,3 +187,23 @@ def _validate_protections(conf: Dict[str, Any]) -> None: "Protections must specify either `lookback_period` or `lookback_period_candles`.\n" f"Please fix the protection {prot.get('method')}" ) + + +def _validate_ask_orderbook(conf: Dict[str, Any]) -> None: + ask_strategy = conf.get('ask_strategy', {}) + ob_min = ask_strategy.get('order_book_min') + ob_max = ask_strategy.get('order_book_max') + if ob_min is not None and ob_max is not None: + if ob_min != ob_max: + raise OperationalException( + "Using order_book_max != order_book_min in ask_strategy is no longer supported." + "Please pick one value and use `order_book_top` in the future." + ) + else: + # Move value to order_book_top + ask_strategy['order_book_top'] = ob_min + logger.warning( + "DEPRECATED: " + "Please use `order_book_top` instead of `order_book_min` and `order_book_max` " + "for your `ask_strategy` configuration." + ) diff --git a/freqtrade/constants.py b/freqtrade/constants.py index 6ee4047d2..f8d1100fe 100644 --- a/freqtrade/constants.py +++ b/freqtrade/constants.py @@ -154,7 +154,7 @@ CONF_SCHEMA = { }, 'price_side': {'type': 'string', 'enum': ORDERBOOK_SIDES, 'default': 'bid'}, 'use_order_book': {'type': 'boolean'}, - 'order_book_top': {'type': 'integer', 'maximum': 20, 'minimum': 1}, + 'order_book_top': {'type': 'integer', 'minimum': 1, 'maximum': 50, }, 'check_depth_of_market': { 'type': 'object', 'properties': { @@ -176,8 +176,7 @@ CONF_SCHEMA = { 'exclusiveMaximum': False, }, 'use_order_book': {'type': 'boolean'}, - 'order_book_min': {'type': 'integer', 'minimum': 1}, - 'order_book_max': {'type': 'integer', 'minimum': 1, 'maximum': 50}, + 'order_book_top': {'type': 'integer', 'minimum': 1, 'maximum': 50, }, 'use_sell_signal': {'type': 'boolean'}, 'sell_profit_only': {'type': 'boolean'}, 'sell_profit_offset': {'type': 'number'}, diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 2db89d707..53a451174 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -997,15 +997,6 @@ class Exchange: except ccxt.BaseError as e: raise OperationalException(e) from e - def _order_book_gen(self, pair: str, side: str, order_book_max: int = 1, - order_book_min: int = 1): - """ - Helper generator to query orderbook in loop (used for early sell-order placing) - """ - order_book = self.fetch_l2_order_book(pair, order_book_max) - for i in range(order_book_min, order_book_max + 1): - yield order_book[side][i - 1][0] - def get_buy_rate(self, pair: str, refresh: bool) -> float: """ Calculates bid target between current ask price and last price @@ -1074,10 +1065,15 @@ class Exchange: logger.info( f"Getting price from order book {ask_strategy['price_side'].capitalize()} side." ) + order_book_top = ask_strategy.get('order_book_top', 1) + order_book = self.fetch_l2_order_book(pair, order_book_top) try: - rate = next(self._order_book_gen(pair, f"{ask_strategy['price_side']}s")) + rate = order_book[f"{ask_strategy['price_side']}s"][order_book_top - 1][0] except (IndexError, KeyError) as e: - logger.warning("Sell Price at location from orderbook could not be determined.") + logger.warning( + "Sell Price at location from orderbook could not be determined." + f"Orderbook: {order_book}" + ) raise PricingError from e else: ticker = self.fetch_ticker(pair) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index ec07d4d63..59a615843 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -692,37 +692,10 @@ class FreqtradeBot(LoggingMixin): (buy, sell) = self.strategy.get_signal(trade.pair, self.strategy.timeframe, analyzed_df) - if config_ask_strategy.get('use_order_book', False): - order_book_min = config_ask_strategy.get('order_book_min', 1) - order_book_max = config_ask_strategy.get('order_book_max', 1) - logger.debug(f'Using order book between {order_book_min} and {order_book_max} ' - f'for selling {trade.pair}...') - - order_book = self.exchange._order_book_gen( - trade.pair, f"{config_ask_strategy['price_side']}s", - order_book_min=order_book_min, order_book_max=order_book_max) - for i in range(order_book_min, order_book_max + 1): - try: - sell_rate = next(order_book) - except (IndexError, KeyError) as e: - logger.warning( - f"Sell Price at location {i} from orderbook could not be determined." - ) - raise PricingError from e - logger.debug(f" order book {config_ask_strategy['price_side']} top {i}: " - f"{sell_rate:0.8f}") - # Assign sell-rate to cache - otherwise sell-rate is never updated in the cache, - # resulting in outdated RPC messages - self.exchange._sell_rate_cache[trade.pair] = sell_rate - - if self._check_and_execute_sell(trade, sell_rate, buy, sell): - return True - - else: - logger.debug('checking sell') - sell_rate = self.exchange.get_sell_rate(trade.pair, True) - if self._check_and_execute_sell(trade, sell_rate, buy, sell): - return True + logger.debug('checking sell') + sell_rate = self.exchange.get_sell_rate(trade.pair, True) + if self._check_and_execute_sell(trade, sell_rate, buy, sell): + return True logger.debug('Found no sell signal for %s.', trade) return False diff --git a/freqtrade/templates/base_config.json.j2 b/freqtrade/templates/base_config.json.j2 index 8933ebc6a..5e6890b90 100644 --- a/freqtrade/templates/base_config.json.j2 +++ b/freqtrade/templates/base_config.json.j2 @@ -25,8 +25,7 @@ "ask_strategy": { "price_side": "ask", "use_order_book": false, - "order_book_min": 1, - "order_book_max": 1, + "order_book_top": 1, "use_sell_signal": true, "sell_profit_only": false, "ignore_roi_if_buy_signal": false