Remove support for order_book_max

This commit is contained in:
Matthias 2021-06-25 20:36:39 +02:00
parent 1440b2f7fe
commit d59a38665c
10 changed files with 40 additions and 57 deletions

View File

@ -22,8 +22,7 @@
}, },
"ask_strategy": { "ask_strategy": {
"use_order_book": false, "use_order_book": false,
"order_book_min": 1, "order_book_top": 1,
"order_book_max": 1,
"use_sell_signal": true, "use_sell_signal": true,
"sell_profit_only": false, "sell_profit_only": false,
"ignore_roi_if_buy_signal": false "ignore_roi_if_buy_signal": false

View File

@ -22,8 +22,7 @@
}, },
"ask_strategy":{ "ask_strategy":{
"use_order_book": false, "use_order_book": false,
"order_book_min": 1, "order_book_top": 1,
"order_book_max": 1,
"use_sell_signal": true, "use_sell_signal": true,
"sell_profit_only": false, "sell_profit_only": false,
"ignore_roi_if_buy_signal": false "ignore_roi_if_buy_signal": false

View File

@ -22,8 +22,7 @@
}, },
"ask_strategy": { "ask_strategy": {
"use_order_book": false, "use_order_book": false,
"order_book_min": 1, "order_book_top": 1,
"order_book_max": 1,
"use_sell_signal": true, "use_sell_signal": true,
"sell_profit_only": false, "sell_profit_only": false,
"ignore_roi_if_buy_signal": false "ignore_roi_if_buy_signal": false

View File

@ -39,8 +39,7 @@
"ask_strategy":{ "ask_strategy":{
"price_side": "ask", "price_side": "ask",
"use_order_book": false, "use_order_book": false,
"order_book_min": 1, "order_book_top": 1,
"order_book_max": 1,
"use_sell_signal": true, "use_sell_signal": true,
"sell_profit_only": false, "sell_profit_only": false,
"sell_profit_offset": 0.0, "sell_profit_offset": 0.0,

View File

@ -22,8 +22,7 @@
}, },
"ask_strategy":{ "ask_strategy":{
"use_order_book": false, "use_order_book": false,
"order_book_min": 1, "order_book_top": 1,
"order_book_max": 1,
"use_sell_signal": true, "use_sell_signal": true,
"sell_profit_only": false, "sell_profit_only": false,
"ignore_roi_if_buy_signal": false "ignore_roi_if_buy_signal": false

View File

@ -79,6 +79,7 @@ def validate_config_consistency(conf: Dict[str, Any]) -> None:
_validate_whitelist(conf) _validate_whitelist(conf)
_validate_protections(conf) _validate_protections(conf)
_validate_unlimited_amount(conf) _validate_unlimited_amount(conf)
_validate_ask_orderbook(conf)
# validate configuration before returning # validate configuration before returning
logger.info('Validating configuration ...') 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" "Protections must specify either `lookback_period` or `lookback_period_candles`.\n"
f"Please fix the protection {prot.get('method')}" 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."
)

View File

@ -154,7 +154,7 @@ CONF_SCHEMA = {
}, },
'price_side': {'type': 'string', 'enum': ORDERBOOK_SIDES, 'default': 'bid'}, 'price_side': {'type': 'string', 'enum': ORDERBOOK_SIDES, 'default': 'bid'},
'use_order_book': {'type': 'boolean'}, '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': { 'check_depth_of_market': {
'type': 'object', 'type': 'object',
'properties': { 'properties': {
@ -176,8 +176,7 @@ CONF_SCHEMA = {
'exclusiveMaximum': False, 'exclusiveMaximum': False,
}, },
'use_order_book': {'type': 'boolean'}, 'use_order_book': {'type': 'boolean'},
'order_book_min': {'type': 'integer', 'minimum': 1}, 'order_book_top': {'type': 'integer', 'minimum': 1, 'maximum': 50, },
'order_book_max': {'type': 'integer', 'minimum': 1, 'maximum': 50},
'use_sell_signal': {'type': 'boolean'}, 'use_sell_signal': {'type': 'boolean'},
'sell_profit_only': {'type': 'boolean'}, 'sell_profit_only': {'type': 'boolean'},
'sell_profit_offset': {'type': 'number'}, 'sell_profit_offset': {'type': 'number'},

View File

@ -997,15 +997,6 @@ class Exchange:
except ccxt.BaseError as e: except ccxt.BaseError as e:
raise OperationalException(e) from 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: def get_buy_rate(self, pair: str, refresh: bool) -> float:
""" """
Calculates bid target between current ask price and last price Calculates bid target between current ask price and last price
@ -1074,10 +1065,15 @@ class Exchange:
logger.info( logger.info(
f"Getting price from order book {ask_strategy['price_side'].capitalize()} side." 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: 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: 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 raise PricingError from e
else: else:
ticker = self.fetch_ticker(pair) ticker = self.fetch_ticker(pair)

View File

@ -692,33 +692,6 @@ class FreqtradeBot(LoggingMixin):
(buy, sell) = self.strategy.get_signal(trade.pair, self.strategy.timeframe, analyzed_df) (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') logger.debug('checking sell')
sell_rate = self.exchange.get_sell_rate(trade.pair, True) sell_rate = self.exchange.get_sell_rate(trade.pair, True)
if self._check_and_execute_sell(trade, sell_rate, buy, sell): if self._check_and_execute_sell(trade, sell_rate, buy, sell):

View File

@ -25,8 +25,7 @@
"ask_strategy": { "ask_strategy": {
"price_side": "ask", "price_side": "ask",
"use_order_book": false, "use_order_book": false,
"order_book_min": 1, "order_book_top": 1,
"order_book_max": 1,
"use_sell_signal": true, "use_sell_signal": true,
"sell_profit_only": false, "sell_profit_only": false,
"ignore_roi_if_buy_signal": false "ignore_roi_if_buy_signal": false