From 7d77aff2894d864f3f32417434a58606da2b05da Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 21 Nov 2021 09:24:20 +0100 Subject: [PATCH] Add some compatibility around buy_tag --- docs/strategy-advanced.md | 6 +++--- docs/strategy-customization.md | 2 +- docs/webhook-config.md | 6 +++--- freqtrade/freqtradebot.py | 5 +++++ freqtrade/persistence/models.py | 1 + freqtrade/rpc/api_server/api_schemas.py | 1 + freqtrade/rpc/telegram.py | 8 ++++---- tests/test_persistence.py | 2 ++ 8 files changed, 20 insertions(+), 11 deletions(-) diff --git a/docs/strategy-advanced.md b/docs/strategy-advanced.md index 573d184ff..908165fc7 100644 --- a/docs/strategy-advanced.md +++ b/docs/strategy-advanced.md @@ -77,7 +77,7 @@ class AwesomeStrategy(IStrategy): *** -## Buy Tag +## Enter Tag When your strategy has multiple buy signals, you can name the signal that triggered. Then you can access you buy signal on `custom_sell` @@ -89,7 +89,7 @@ def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: (dataframe['rsi'] < 35) & (dataframe['volume'] > 0) ), - ['buy', 'buy_tag']] = (1, 'buy_signal_rsi') + ['buy', 'enter_tag']] = (1, 'buy_signal_rsi') return dataframe @@ -104,7 +104,7 @@ def custom_sell(self, pair: str, trade: Trade, current_time: datetime, current_r ``` !!! Note - `buy_tag` is limited to 100 characters, remaining data will be truncated. + `enter_tag` is limited to 100 characters, remaining data will be truncated. ## Exit tag diff --git a/docs/strategy-customization.md b/docs/strategy-customization.md index 178ed108b..e90d87c4a 100644 --- a/docs/strategy-customization.md +++ b/docs/strategy-customization.md @@ -498,7 +498,7 @@ for more information. & (dataframe['volume'] > 0) ), - ['buy', 'buy_tag']] = (1, 'buy_signal_rsi') + ['buy', 'enter_tag']] = (1, 'buy_signal_rsi') return dataframe ``` diff --git a/docs/webhook-config.md b/docs/webhook-config.md index ec944cb50..43aa0502c 100644 --- a/docs/webhook-config.md +++ b/docs/webhook-config.md @@ -83,7 +83,7 @@ Possible parameters are: * `fiat_currency` * `order_type` * `current_rate` -* `buy_tag` +* `enter_tag` ### Webhookbuycancel @@ -101,7 +101,7 @@ Possible parameters are: * `fiat_currency` * `order_type` * `current_rate` -* `buy_tag` +* `enter_tag` ### Webhookbuyfill @@ -117,7 +117,7 @@ Possible parameters are: * `stake_amount` * `stake_currency` * `fiat_currency` -* `buy_tag` +* `enter_tag` ### Webhooksell diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index d234ebb07..237c07060 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -755,6 +755,7 @@ class FreqtradeBot(LoggingMixin): 'trade_id': trade.id, 'type': RPCMessageType.SHORT if trade.is_short else RPCMessageType.BUY, 'buy_tag': trade.buy_tag, + 'enter_tag': trade.buy_tag, 'exchange': self.exchange.name.capitalize(), 'pair': trade.pair, 'limit': trade.open_rate, @@ -780,6 +781,7 @@ class FreqtradeBot(LoggingMixin): 'trade_id': trade.id, 'type': msg_type, 'buy_tag': trade.buy_tag, + 'enter_tag': trade.buy_tag, 'exchange': self.exchange.name.capitalize(), 'pair': trade.pair, 'limit': trade.open_rate, @@ -802,6 +804,7 @@ class FreqtradeBot(LoggingMixin): 'trade_id': trade.id, 'type': msg_type, 'buy_tag': trade.buy_tag, + 'enter_tag': trade.buy_tag, 'exchange': self.exchange.name.capitalize(), 'pair': trade.pair, 'open_rate': trade.open_rate, @@ -1384,6 +1387,7 @@ class FreqtradeBot(LoggingMixin): 'current_rate': current_rate, 'profit_amount': profit_trade, 'profit_ratio': profit_ratio, + 'enter_tag': trade.buy_tag, 'buy_tag': trade.buy_tag, 'sell_reason': trade.sell_reason, 'open_date': trade.open_date, @@ -1428,6 +1432,7 @@ class FreqtradeBot(LoggingMixin): 'current_rate': current_rate, 'profit_amount': profit_trade, 'profit_ratio': profit_ratio, + 'enter_tag': trade.buy_tag, 'buy_tag': trade.buy_tag, 'sell_reason': trade.sell_reason, 'open_date': trade.open_date, diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index f9df45111..f73edbe02 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -390,6 +390,7 @@ class LocalTrade(): 'stake_amount': round(self.stake_amount, 8), 'strategy': self.strategy, 'buy_tag': self.buy_tag, + 'enter_tag': self.buy_tag, 'timeframe': self.timeframe, 'fee_open': self.fee_open, diff --git a/freqtrade/rpc/api_server/api_schemas.py b/freqtrade/rpc/api_server/api_schemas.py index d6a861011..db4378a51 100644 --- a/freqtrade/rpc/api_server/api_schemas.py +++ b/freqtrade/rpc/api_server/api_schemas.py @@ -185,6 +185,7 @@ class TradeSchema(BaseModel): stake_amount: float strategy: str buy_tag: Optional[str] + enter_tag: Optional[str] timeframe: int fee_open: Optional[float] fee_open_cost: Optional[float] diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 0e1a6fe27..3bcc6adf2 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -226,7 +226,7 @@ class Telegram(RPCHandler): f"{emoji} *{msg['exchange']}:* {'Bought' if is_fill else 'Buying'} {msg['pair']}" f" (#{msg['trade_id']})\n" ) - message += f"*Buy Tag:* `{msg['buy_tag']}`\n" if msg.get('buy_tag', None) else "" + message += f"*Enter Tag:* `{msg['enter_tag']}`\n" if msg.get('enter_tag', None) else "" message += f"*Amount:* `{msg['amount']:.8f}`\n" if msg['type'] == RPCMessageType.BUY_FILL: @@ -251,7 +251,7 @@ class Telegram(RPCHandler): microsecond=0) - msg['open_date'].replace(microsecond=0) msg['duration_min'] = msg['duration'].total_seconds() / 60 - msg['buy_tag'] = msg['buy_tag'] if "buy_tag" in msg.keys() else None + msg['enter_tag'] = msg['enter_tag'] if "enter_tag" in msg.keys() else None msg['emoji'] = self._get_sell_emoji(msg) # Check if all sell properties are available. @@ -397,7 +397,7 @@ class Telegram(RPCHandler): "*Trade ID:* `{trade_id}` `(since {open_date_hum})`", "*Current Pair:* {pair}", "*Amount:* `{amount} ({stake_amount} {base_currency})`", - "*Buy Tag:* `{buy_tag}`" if r['buy_tag'] else "", + "*Enter Tag:* `{enter_tag}`" if r['enter_tag'] else "", "*Open Rate:* `{open_rate:.8f}`", "*Close Rate:* `{close_rate}`" if r['close_rate'] else "", "*Current Rate:* `{current_rate:.8f}`", @@ -989,7 +989,7 @@ class Telegram(RPCHandler): output = "Buy Tag Performance:\n" for i, trade in enumerate(trades): stat_line = ( - f"{i+1}.\t {trade['buy_tag']}\t" + f"{i+1}.\t {trade['enter_tag']}\t" f"{round_coin_value(trade['profit_abs'], self._config['stake_currency'])} " f"({trade['profit_ratio']:.2%}) " f"({trade['count']})\n") diff --git a/tests/test_persistence.py b/tests/test_persistence.py index 2f5f61a15..9df4f511a 100644 --- a/tests/test_persistence.py +++ b/tests/test_persistence.py @@ -1602,6 +1602,7 @@ def test_to_json(default_conf, fee): 'max_rate': None, 'strategy': None, 'buy_tag': None, + 'enter_tag': None, 'timeframe': None, 'exchange': 'binance', 'leverage': None, @@ -1675,6 +1676,7 @@ def test_to_json(default_conf, fee): 'sell_order_status': None, 'strategy': None, 'buy_tag': 'buys_signal_001', + 'enter_tag': 'buys_signal_001', 'timeframe': None, 'exchange': 'binance', 'leverage': None,