From b27c8256f44eefeed1c0e1f179c2fa2b0f5e4fbc Mon Sep 17 00:00:00 2001 From: Jean-Baptiste LE STANG Date: Tue, 30 Jan 2018 21:34:26 +0100 Subject: [PATCH] Adding cancel buy/sell events --- freqtrade/main.py | 4 ++++ freqtrade/strategy/default_strategy.py | 14 ++++++++++++-- freqtrade/strategy/interface.py | 14 ++++++++++++++ freqtrade/strategy/strategy.py | 14 ++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/freqtrade/main.py b/freqtrade/main.py index 7e78a3864..494ddf4f7 100755 --- a/freqtrade/main.py +++ b/freqtrade/main.py @@ -158,6 +158,8 @@ def handle_timedout_limit_buy(trade: Trade, order: Dict) -> bool: logger.info('Buy order timeout for %s.', trade) rpc.send_msg('*Timeout:* Unfilled buy order for {} cancelled'.format( trade.pair.replace('_', '/'))) + strategy = Strategy() + strategy.did_cancel_buy(trade.pair) return True # if trade is partially complete, edit the stake details for the trade @@ -188,6 +190,8 @@ def handle_timedout_limit_sell(trade: Trade, order: Dict) -> bool: rpc.send_msg('*Timeout:* Unfilled sell order for {} cancelled'.format( trade.pair.replace('_', '/'))) logger.info('Sell order timeout for %s.', trade) + strategy = Strategy() + strategy.did_cancel_sell(trade.pair) return True # TODO: figure out how to handle partially complete sell orders diff --git a/freqtrade/strategy/default_strategy.py b/freqtrade/strategy/default_strategy.py index 3ac72d127..ba5bca404 100644 --- a/freqtrade/strategy/default_strategy.py +++ b/freqtrade/strategy/default_strategy.py @@ -244,11 +244,21 @@ class DefaultStrategy(IStrategy): we are notified that a given pair was bought :param pair: the pair that was is concerned by the dataframe """ - assert False is not True def did_sold(self, pair: str): """ we are notified that a given pair was sold :param pair: the pair that was is concerned by the dataframe """ - assert False is not True + + def did_cancel_buy(self, pair: str): + """ + we are notified that a given pair was bought + :param pair: the pair that was is concerned by the dataframe + """ + + def did_cancel_sell(self, pair: str): + """ + we are notified that a given pair was sold + :param pair: the pair that was is concerned by the dataframe + """ diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 73614f376..4ea3173c1 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -59,3 +59,17 @@ class IStrategy(ABC): we are notified that a given pair was sold :param pair: the pair that was is concerned by the dataframe """ + + @abstractmethod + def did_cancel_buy(self, pair: str): + """ + we are notified that a given buy for a pair was cancelled + :param pair: the pair that was is concerned by the dataframe + """ + + @abstractmethod + def did_cancel_sell(self, pair: str): + """ + we are notified that a given sell for a pair was cancelled + :param pair: the pair that was is concerned by the dataframe + """ diff --git a/freqtrade/strategy/strategy.py b/freqtrade/strategy/strategy.py index e94320aa2..85b8657c8 100644 --- a/freqtrade/strategy/strategy.py +++ b/freqtrade/strategy/strategy.py @@ -181,3 +181,17 @@ class Strategy(object): :param pair: the pair that was is concerned by the dataframe """ return self.custom_strategy.did_sold(pair) + + def did_cancel_buy(self, pair: str): + """ + we are notified that a given pair was bought + :param pair: the pair that was is concerned by the dataframe + """ + return self.custom_strategy.did_cancel_buy(pair) + + def did_cancel_sell(self, pair: str): + """ + we are notified that a given pair was sold + :param pair: the pair that was is concerned by the dataframe + """ + return self.custom_strategy.did_cancel_sell(pair)