From 5284112b69828b91d42a398c2d6cad9c1a151121 Mon Sep 17 00:00:00 2001 From: axel Date: Sun, 1 Aug 2021 02:09:59 -0400 Subject: [PATCH] fix in custom entry function output,remove changes related to outdated prices, doc exemple minor changes --- docs/strategy-advanced.md | 4 +- freqtrade/freqtradebot.py | 65 --------------------------------- freqtrade/strategy/interface.py | 10 ++--- 3 files changed, 5 insertions(+), 74 deletions(-) diff --git a/docs/strategy-advanced.md b/docs/strategy-advanced.md index 8c99f1d2e..a8e54bbcf 100644 --- a/docs/strategy-advanced.md +++ b/docs/strategy-advanced.md @@ -373,7 +373,7 @@ class AwesomeStrategy(IStrategy): # ... populate_* methods def custom_entry_price(self, pair: str, current_time: datetime, - current_rate, **kwargs) -> float: + proposed_rate, **kwargs) -> float: dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe) @@ -393,7 +393,7 @@ However, freqtrade also offers a custom callback for both order types, which all !!! Note Unfilled order timeouts are not relevant during backtesting or hyperopt, and are only relevant during real (live) trading. Therefore these methods are only called in these circumstances. -## Custom order timeout example +### Custom order timeout example A simple example, which applies different unfilled-timeouts depending on the price of the asset can be seen below. It applies a tight timeout for higher priced assets, while allowing more time to fill on cheap coins. diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 4abc7e508..c8e930a36 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -169,7 +169,6 @@ class FreqtradeBot(LoggingMixin): with self._sell_lock: # Check and handle any timed out open orders self.check_handle_timedout() - self.check_handle_custom_entryprice_outdated() # Protect from collisions with forcesell. # Without this, freqtrade my try to recreate stoploss_on_exchange orders @@ -920,70 +919,6 @@ class FreqtradeBot(LoggingMixin): order=order))): self.handle_cancel_sell(trade, order, constants.CANCEL_REASON['TIMEOUT']) - def _check_entryprice_outdated(self, side: str, order: dict) -> bool: - """ - Check if entry price is outdated by comparing it to the new prefered entry price - , and if the order is still open and price outdated - """ - #print("check_entryprice_outdated") - if self.config.get('use_custom_entry_price', False): - order_prefered_entry_price = order['price'] # order['trade'] - - #print(order) - #order_open_rate_requested = order.trade['open_rate_requested'] - #print("order_trade_object : {}".format(order['trade'])) - - # get pep from strategy data provider - pair = order['symbol'] - old_prefered_entry_price = order_prefered_entry_price - #new_prefered_entry_price = self.strategy.custom_info[pair]['pep_long'].iloc[-1] #buy_limit_requested - new_prefered_entry_price = self.strategy.entryprice - - old_prefered_entry_price_rounded = self.exchange.price_to_precision(pair, order_prefered_entry_price) - new_prefered_entry_price_rounded = self.exchange.price_to_precision(pair, new_prefered_entry_price) - - if old_prefered_entry_price_rounded != new_prefered_entry_price_rounded: - print("order['symbol']: {}".format(order['symbol'])) - print("new_prefered_entry_price: {}, old_prefered_entry_price: {}".format(new_prefered_entry_price, old_prefered_entry_price)) - print("rounded new pep: {}, rounded old pep: {}".format(new_prefered_entry_price_rounded, old_prefered_entry_price_rounded)) - print("Delta in prefered entry price, order to cancel") - return True - else: - return False - else: - return False - - def check_handle_custom_entryprice_outdated(self) -> None: - """ - Check if any orders prefered entryprice change and cancel if necessary - :return: None - """ - - for trade in Trade.get_open_order_trades(): - try: - if not trade.open_order_id: - continue - order = self.exchange.fetch_order(trade.open_order_id, trade.pair) - except (ExchangeError): - logger.info('Cannot query order for %s due to %s', trade, traceback.format_exc()) - continue - - fully_cancelled = self.update_trade_state(trade, trade.open_order_id, order) - - # Refresh entryprice value if order is open - if (order['status'] == 'open'): - self.strategy.entryprice = strategy_safe_wrapper(self.strategy.custom_entry_price)( - pair=trade.pair, current_time=datetime.now(timezone.utc), - current_rate=trade.open_rate_requested) - - if (order['side'] == 'buy' and (order['status'] == 'open') and ( - self._check_entryprice_outdated('buy', order))): - self.handle_cancel_buy(trade, order, constants.CANCEL_REASON['ENTRYPRICECHANGED']) - - elif (order['side'] == 'sell' and (order['status'] == 'open') and ( - self._check_entryprice_outdated('sell', order))): - self.handle_cancel_sell(trade, order, constants.CANCEL_REASON['EXITPRICECHANGED']) - def cancel_all_open_orders(self) -> None: """ Cancel all orders that are currently open diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index af5be2711..401934f7a 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -69,10 +69,6 @@ class IStrategy(ABC, HyperStrategyMixin): # associated stoploss stoploss: float - # custom order price - entryprice: Optional[float] = None - exitprice: Optional[float] = None - # trailing stoploss trailing_stop: bool = False trailing_stop_positive: Optional[float] = None @@ -284,7 +280,7 @@ class IStrategy(ABC, HyperStrategyMixin): """ return self.stoploss - def custom_entry_price(self, pair: str, current_time: datetime, current_rate: float, + def custom_entry_price(self, pair: str, current_time: datetime, proposed_rate: float, **kwargs) -> float: """ Custom entry price logic, returning the new entry price. @@ -296,11 +292,11 @@ class IStrategy(ABC, HyperStrategyMixin): :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_rate: Rate, calculated based on pricing settings in ask_strategy. :param **kwargs: Ensure to keep this here so updates to this won't break your strategy. :return float: New entry price value if provided """ - return self.entryprice + return proposed_rate def custom_sell(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, current_profit: float, **kwargs) -> Optional[Union[str, bool]]: