The StrategyAnalysis class is a part of a backtesting website and is used to analyze trading strategies. It extends the IStrategy interface, which provides a set of methods for implementing trading strategies. The confirm_trade_exit method is overridden in the StrategyAnalysis class to include additional analysis and logging functionality.
This method is called when a trade exit is confirmed.
Here are the important parts of the method:
Backtest Analysis:
If the backtesting mode is enabled, the method calculates various statistics related to the trade and logs them in a table format.
The statistics include:
Pair: The trading pair involved in the trade. Min Profit Percentage: The minimum profit percentage achieved during the trade. Max Profit Percentage: The maximum profit percentage achieved during the trade. Duration: The duration of the trade in minutes. Profit: The profit percentage achieved at trade exit. Stoploss: The stop-loss percentage for the trade. If the profit is negative, it logs the table in red color; otherwise, it logs it in green color. Telegram Notification:
If the Telegram integration is enabled and the backtesting mode is 'dry_run' or 'live', the method sends a Telegram message with the following information:
Trading pair
Minimum profit percentage
Maximum profit percentage
Opening fee percentage
Closing fee percentage
Discord Notification:
If the Discord integration is enabled and the backtesting mode is 'dry_run' or 'live', the method sends a Discord message with various trade-related information, including trade ID, exchange, pair, gain (profit or loss), limit rate, order type, amount, open rate, close rate, profit amount, profit ratio, buy tag, sell reason, open date, close date, stake currency, and fiat currency. Utility Functions:
The telegram_send function sends a message to a Telegram chat using the Telegram Bot API. It runs in a separate thread to avoid blocking the execution. The discord_send function sends a message to a Discord webhook using the Discord API. It also runs in a separate thread. The log function logs a parameter with a specified color (red or green) using the logger. Overall, the StrategyAnalysis class enhances the strategy analysis process by providing additional logging, backtest analysis, and integration with Telegram and Discord for real-time notifications.