day/week options for Telegram '/profit' command
This commit is contained in:
		| @@ -123,7 +123,7 @@ Telegram is not mandatory. However, this is a great way to control your bot. Mor | |||||||
| - `/stop`: Stops the trader. | - `/stop`: Stops the trader. | ||||||
| - `/stopbuy`: Stop entering new trades. | - `/stopbuy`: Stop entering new trades. | ||||||
| - `/status <trade_id>|[table]`: Lists all or specific open trades. | - `/status <trade_id>|[table]`: Lists all or specific open trades. | ||||||
| - `/profit`: Lists cumulative profit from all finished trades | - `/profit [day]|[week]`: Lists cumulative profit from all finished trades | ||||||
| - `/forcesell <trade_id>|all`: Instantly sells the given trade (Ignoring `minimum_roi`). | - `/forcesell <trade_id>|all`: Instantly sells the given trade (Ignoring `minimum_roi`). | ||||||
| - `/performance`: Show performance of each finished trade grouped by pair | - `/performance`: Show performance of each finished trade grouped by pair | ||||||
| - `/balance`: Show account balance per currency. | - `/balance`: Show account balance per currency. | ||||||
|   | |||||||
| @@ -130,7 +130,7 @@ You can create your own keyboard in `config.json`: | |||||||
| !!! Note "Supported Commands" | !!! Note "Supported Commands" | ||||||
|     Only the following commands are allowed. Command arguments are not supported! |     Only the following commands are allowed. Command arguments are not supported! | ||||||
|  |  | ||||||
|     `/start`, `/stop`, `/status`, `/status table`, `/trades`, `/profit`, `/performance`, `/daily`, `/stats`, `/count`, `/locks`, `/balance`, `/stopbuy`, `/reload_config`, `/show_config`, `/logs`, `/whitelist`, `/blacklist`, `/edge`, `/help`, `/version` |     `/start`, `/stop`, `/status`, `/status table`, `/trades`, `/profit`, `/profit day`, `/profit week`, `/performance`, `/daily`, `/stats`, `/count`, `/locks`, `/balance`, `/stopbuy`, `/reload_config`, `/show_config`, `/logs`, `/whitelist`, `/blacklist`, `/edge`, `/help`, `/version` | ||||||
|  |  | ||||||
| ## Telegram commands | ## Telegram commands | ||||||
|  |  | ||||||
| @@ -154,7 +154,7 @@ official commands. You can ask at any moment for help with `/help`. | |||||||
| | `/count` | Displays number of trades used and available | | `/count` | Displays number of trades used and available | ||||||
| | `/locks` | Show currently locked pairs. | | `/locks` | Show currently locked pairs. | ||||||
| | `/unlock <pair or lock_id>` | Remove the lock for this pair (or for this lock id). | | `/unlock <pair or lock_id>` | Remove the lock for this pair (or for this lock id). | ||||||
| | `/profit` | Display a summary of your profit/loss from close trades and some stats about your performance | | `/profit [day]|[week]` | Display a summary of your profit/loss from close trades and some stats about your performance | ||||||
| | `/forcesell <trade_id>` | Instantly sells the given trade  (Ignoring `minimum_roi`). | | `/forcesell <trade_id>` | Instantly sells the given trade  (Ignoring `minimum_roi`). | ||||||
| | `/forcesell all` | Instantly sells all open trades (Ignoring `minimum_roi`). | | `/forcesell all` | Instantly sells all open trades (Ignoring `minimum_roi`). | ||||||
| | `/forcebuy <pair> [rate]` | Instantly buys the given pair. Rate is optional. (`forcebuy_enable` must be set to True) | | `/forcebuy <pair> [rate]` | Instantly buys the given pair. Rate is optional. (`forcebuy_enable` must be set to True) | ||||||
|   | |||||||
| @@ -352,9 +352,10 @@ class RPC: | |||||||
|         return {'sell_reasons': sell_reasons, 'durations': durations} |         return {'sell_reasons': sell_reasons, 'durations': durations} | ||||||
|  |  | ||||||
|     def _rpc_trade_statistics( |     def _rpc_trade_statistics( | ||||||
|             self, stake_currency: str, fiat_display_currency: str) -> Dict[str, Any]: |             self, stake_currency: str, fiat_display_currency: str, | ||||||
|  |             start_date: datetime = datetime.fromtimestamp(0)) -> Dict[str, Any]: | ||||||
|         """ Returns cumulative profit statistics """ |         """ Returns cumulative profit statistics """ | ||||||
|         trades = Trade.get_trades().order_by(Trade.id).all() |         trades = Trade.get_trades([Trade.open_date >= start_date]).order_by(Trade.id).all() | ||||||
|  |  | ||||||
|         profit_all_coin = [] |         profit_all_coin = [] | ||||||
|         profit_all_ratio = [] |         profit_all_ratio = [] | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ This module manage Telegram communication | |||||||
| """ | """ | ||||||
| import json | import json | ||||||
| import logging | import logging | ||||||
| from datetime import timedelta | from datetime import datetime, timedelta | ||||||
| from html import escape | from html import escape | ||||||
| from itertools import chain | from itertools import chain | ||||||
| from typing import Any, Callable, Dict, List, Union | from typing import Any, Callable, Dict, List, Union | ||||||
| @@ -98,7 +98,8 @@ class Telegram(RPCHandler): | |||||||
|         #       this needs refacoring of the whole telegram module (same |         #       this needs refacoring of the whole telegram module (same | ||||||
|         #       problem in _help()). |         #       problem in _help()). | ||||||
|         valid_keys: List[str] = ['/start', '/stop', '/status', '/status table', |         valid_keys: List[str] = ['/start', '/stop', '/status', '/status table', | ||||||
|                                  '/trades', '/profit', '/performance', '/daily', |                                  '/trades', '/performance', '/daily', | ||||||
|  |                                  '/profit', '/profit day', '/profit week', | ||||||
|                                  '/stats', '/count', '/locks', '/balance', |                                  '/stats', '/count', '/locks', '/balance', | ||||||
|                                  '/stopbuy', '/reload_config', '/show_config', |                                  '/stopbuy', '/reload_config', '/show_config', | ||||||
|                                  '/logs', '/whitelist', '/blacklist', '/edge', |                                  '/logs', '/whitelist', '/blacklist', '/edge', | ||||||
| @@ -421,9 +422,17 @@ class Telegram(RPCHandler): | |||||||
|         stake_cur = self._config['stake_currency'] |         stake_cur = self._config['stake_currency'] | ||||||
|         fiat_disp_cur = self._config.get('fiat_display_currency', '') |         fiat_disp_cur = self._config.get('fiat_display_currency', '') | ||||||
|  |  | ||||||
|  |         start_date = datetime.fromtimestamp(0) | ||||||
|  |         if context.args: | ||||||
|  |             if 'day' in context.args: | ||||||
|  |                 start_date = datetime.utcnow().date() | ||||||
|  |             elif 'week' in context.args: | ||||||
|  |                 start_date = datetime.utcnow().date() - timedelta(days=7) | ||||||
|  |  | ||||||
|         stats = self._rpc._rpc_trade_statistics( |         stats = self._rpc._rpc_trade_statistics( | ||||||
|             stake_cur, |             stake_cur, | ||||||
|             fiat_disp_cur) |             fiat_disp_cur, | ||||||
|  |             start_date) | ||||||
|         profit_closed_coin = stats['profit_closed_coin'] |         profit_closed_coin = stats['profit_closed_coin'] | ||||||
|         profit_closed_percent_mean = stats['profit_closed_percent_mean'] |         profit_closed_percent_mean = stats['profit_closed_percent_mean'] | ||||||
|         profit_closed_percent_sum = stats['profit_closed_percent_sum'] |         profit_closed_percent_sum = stats['profit_closed_percent_sum'] | ||||||
| @@ -901,7 +910,7 @@ class Telegram(RPCHandler): | |||||||
|                    "                `pending buy orders are marked with an asterisk (*)`\n" |                    "                `pending buy orders are marked with an asterisk (*)`\n" | ||||||
|                    "                `pending sell orders are marked with a double asterisk (**)`\n" |                    "                `pending sell orders are marked with a double asterisk (**)`\n" | ||||||
|                    "*/trades [limit]:* `Lists last closed trades (limited to 10 by default)`\n" |                    "*/trades [limit]:* `Lists last closed trades (limited to 10 by default)`\n" | ||||||
|                    "*/profit:* `Lists cumulative profit from all finished trades`\n" |                    "*/profit [day]|[week]:* `Lists cumulative profit from all finished trades`\n" | ||||||
|                    "*/forcesell <trade_id>|all:* `Instantly sells the given trade or all trades, " |                    "*/forcesell <trade_id>|all:* `Instantly sells the given trade or all trades, " | ||||||
|                    "regardless of profit`\n" |                    "regardless of profit`\n" | ||||||
|                    f"{forcebuy_text if self._config.get('forcebuy_enable', False) else ''}" |                    f"{forcebuy_text if self._config.get('forcebuy_enable', False) else ''}" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user