From 7dca3c6d03e83fe512d85280ceab0a5c41673d80 Mon Sep 17 00:00:00 2001 From: Samuel Husso Date: Thu, 14 Jun 2018 08:52:13 +0300 Subject: [PATCH] freqtradebot,main,hyperopt: fstrings in use --- freqtrade/freqtradebot.py | 8 ++------ freqtrade/main.py | 5 +---- freqtrade/optimize/hyperopt.py | 30 +++++++++++++++--------------- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 64ff170fd..9def7078c 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -626,12 +626,8 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \ # Because telegram._forcesell does not have the configuration # Ignore the FIAT value and does not show the stake_currency as well else: - message += '` ({gain}: {profit_percent:.2f}%, {profit_coin:.8f})`'.format( - gain="profit" if fmt_exp_profit > 0 else "loss", - profit_percent=fmt_exp_profit, - profit_coin=profit_trade - ) - + gain = "profit" if fmt_exp_profit > 0 else "loss" + message += f'` ({gain}: {fmt_exp_profit:.2f}%, {profit_trade:.8f})`' # Send the message self.rpc.send_msg(message) Trade.session.flush() diff --git a/freqtrade/main.py b/freqtrade/main.py index 9d17a403a..79080ce37 100755 --- a/freqtrade/main.py +++ b/freqtrade/main.py @@ -74,10 +74,7 @@ def reconfigure(freqtrade: FreqtradeBot, args: Namespace) -> FreqtradeBot: # Create new instance freqtrade = FreqtradeBot(Configuration(args).get_config()) freqtrade.rpc.send_msg( - '*Status:* `Config reloaded ...`'.format( - freqtrade.state.name.lower() - ) - ) + '*Status:* `Config reloaded {freqtrade.state.name.lower()}...`') return freqtrade diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 7138e2601..72bf34eb3 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -128,13 +128,12 @@ class Hyperopt(Backtesting): Log results if it is better than any previous evaluation """ if results['loss'] < self.current_best_loss: + current = results['current_tries'] + total = results['total_tries'] + res = results['result'] + loss = results['loss'] self.current_best_loss = results['loss'] - log_msg = '\n{:5d}/{}: {}. Loss {:.5f}'.format( - results['current_tries'], - results['total_tries'], - results['result'], - results['loss'] - ) + log_msg = f'\n{current:5d}/{total}: {res}. Loss {loss:.5f}' print(log_msg) else: print('.', end='') @@ -309,15 +308,16 @@ class Hyperopt(Backtesting): """ Return the format result in a string """ - return ('{:6d} trades. Avg profit {: 5.2f}%. ' - 'Total profit {: 11.8f} {} ({:.4f}Σ%). Avg duration {:5.1f} mins.').format( - len(results.index), - results.profit_percent.mean() * 100.0, - results.profit_abs.sum(), - self.config['stake_currency'], - results.profit_percent.sum(), - results.trade_duration.mean(), - ) + trades = len(results.index) + avg_profit = results.profit_percent.mean() * 100.0 + total_profit = results.profit_abs.sum() + stake_cur = self.config['stake_currency'] + profit = results.profit_percent.sum() + duration = results.trade_duration.mean() + + return (f'{trades:6d} trades. Avg profit {avg_profit: 5.2f}%. ' + f'Total profit {total_profit: 11.8f} {stake_cur} ' + f'({profit:.4f}Σ%). Avg duration {duration:5.1f} mins.') def get_optimizer(self, cpu_count) -> Optimizer: return Optimizer(