Fixed flake 8, changed sell_tag to exit_tag and fixed telegram functions
This commit is contained in:
@@ -105,7 +105,7 @@ class RPC:
|
||||
val = {
|
||||
'dry_run': config['dry_run'],
|
||||
'stake_currency': config['stake_currency'],
|
||||
'stake_currency_decimals': decimals_per_coin(config['stake_currency']),
|
||||
'stake_currency_decimals': decimals_per_coin(config['stake_currency']),
|
||||
'stake_amount': config['stake_amount'],
|
||||
'available_capital': config.get('available_capital'),
|
||||
'max_open_trades': (config['max_open_trades']
|
||||
@@ -696,16 +696,15 @@ class RPC:
|
||||
[x.update({'profit': round(x['profit'] * 100, 2)}) for x in buy_tags]
|
||||
return buy_tags
|
||||
|
||||
|
||||
def _rpc_sell_tag_performance(self, pair: str) -> List[Dict[str, Any]]:
|
||||
def _rpc_exit_tag_performance(self, pair: str) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Handler for sell tag performance.
|
||||
Shows a performance statistic from finished trades
|
||||
"""
|
||||
sell_tags = Trade.get_sell_tag_performance(pair)
|
||||
exit_tags = Trade.get_exit_tag_performance(pair)
|
||||
# Round and convert to %
|
||||
[x.update({'profit': round(x['profit'] * 100, 2)}) for x in sell_tags]
|
||||
return sell_tags
|
||||
[x.update({'profit': round(x['profit'] * 100, 2)}) for x in exit_tags]
|
||||
return exit_tags
|
||||
|
||||
def _rpc_mix_tag_performance(self, pair: str) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
|
||||
@@ -108,7 +108,7 @@ class Telegram(RPCHandler):
|
||||
r'/trades$', r'/performance$', r'/daily$', r'/daily \d+$',
|
||||
r'/profit$', r'/profit \d+',
|
||||
r'/stats$', r'/count$', r'/locks$', r'/balance$',
|
||||
r'/buys',r'/sells',r'/mix_tags',
|
||||
r'/buys', r'/sells', r'/mix_tags',
|
||||
r'/stopbuy$', r'/reload_config$', r'/show_config$',
|
||||
r'/logs$', r'/whitelist$', r'/blacklist$', r'/edge$',
|
||||
r'/forcebuy$', r'/help$', r'/version$']
|
||||
@@ -154,7 +154,7 @@ class Telegram(RPCHandler):
|
||||
CommandHandler('delete', self._delete_trade),
|
||||
CommandHandler('performance', self._performance),
|
||||
CommandHandler('buys', self._buy_tag_performance),
|
||||
CommandHandler('sells', self._sell_tag_performance),
|
||||
CommandHandler('sells', self._exit_tag_performance),
|
||||
CommandHandler('mix_tags', self._mix_tag_performance),
|
||||
CommandHandler('stats', self._stats),
|
||||
CommandHandler('daily', self._daily),
|
||||
@@ -178,7 +178,7 @@ class Telegram(RPCHandler):
|
||||
CallbackQueryHandler(self._balance, pattern='update_balance'),
|
||||
CallbackQueryHandler(self._performance, pattern='update_performance'),
|
||||
CallbackQueryHandler(self._performance, pattern='update_buy_tag_performance'),
|
||||
CallbackQueryHandler(self._performance, pattern='update_sell_tag_performance'),
|
||||
CallbackQueryHandler(self._performance, pattern='update_exit_tag_performance'),
|
||||
CallbackQueryHandler(self._performance, pattern='update_mix_tag_performance'),
|
||||
CallbackQueryHandler(self._count, pattern='update_count'),
|
||||
CallbackQueryHandler(self._forcebuy_inline),
|
||||
@@ -242,6 +242,7 @@ class Telegram(RPCHandler):
|
||||
msg['duration'] = msg['close_date'].replace(
|
||||
microsecond=0) - msg['open_date'].replace(microsecond=0)
|
||||
msg['duration_min'] = msg['duration'].total_seconds() / 60
|
||||
msg['tags'] = self._get_tags_string(msg)
|
||||
|
||||
msg['emoji'] = self._get_sell_emoji(msg)
|
||||
|
||||
@@ -258,6 +259,7 @@ class Telegram(RPCHandler):
|
||||
|
||||
message = ("{emoji} *{exchange}:* Selling {pair} (#{trade_id})\n"
|
||||
"*Profit:* `{profit_percent:.2f}%{profit_extra}`\n"
|
||||
"{tags}"
|
||||
"*Sell Reason:* `{sell_reason}`\n"
|
||||
"*Duration:* `{duration} ({duration_min:.1f} min)`\n"
|
||||
"*Amount:* `{amount:.8f}`\n"
|
||||
@@ -265,46 +267,6 @@ class Telegram(RPCHandler):
|
||||
"*Current Rate:* `{current_rate:.8f}`\n"
|
||||
"*Close Rate:* `{limit:.8f}`").format(**msg)
|
||||
|
||||
sell_tag =None
|
||||
if("sell_tag" in msg.keys()):
|
||||
sell_tag = msg['sell_tag']
|
||||
buy_tag =None
|
||||
if("buy_tag" in msg.keys()):
|
||||
buy_tag = msg['buy_tag']
|
||||
|
||||
if sell_tag is not None and buy_tag is not None:
|
||||
message = ("{emoji} *{exchange}:* Selling {pair} (#{trade_id})\n"
|
||||
"*Profit:* `{profit_percent:.2f}%{profit_extra}`\n"
|
||||
"*Buy Tag:* `{buy_tag}`\n"
|
||||
"*Sell Tag:* `{sell_tag}`\n"
|
||||
"*Sell Reason:* `{sell_reason}`\n"
|
||||
"*Duration:* `{duration} ({duration_min:.1f} min)`\n"
|
||||
"*Amount:* `{amount:.8f}`\n"
|
||||
"*Open Rate:* `{open_rate:.8f}`\n"
|
||||
"*Current Rate:* `{current_rate:.8f}`\n"
|
||||
"*Close Rate:* `{limit:.8f}`").format(**msg)
|
||||
elif sell_tag is None and buy_tag is not None:
|
||||
message = ("{emoji} *{exchange}:* Selling {pair} (#{trade_id})\n"
|
||||
"*Profit:* `{profit_percent:.2f}%{profit_extra}`\n"
|
||||
"*Buy Tag:* `{buy_tag}`\n"
|
||||
"*Sell Reason:* `{sell_reason}`\n"
|
||||
"*Duration:* `{duration} ({duration_min:.1f} min)`\n"
|
||||
"*Amount:* `{amount:.8f}`\n"
|
||||
"*Open Rate:* `{open_rate:.8f}`\n"
|
||||
"*Current Rate:* `{current_rate:.8f}`\n"
|
||||
"*Close Rate:* `{limit:.8f}`").format(**msg)
|
||||
elif sell_tag is not None and buy_tag is None:
|
||||
message = ("{emoji} *{exchange}:* Selling {pair} (#{trade_id})\n"
|
||||
"*Profit:* `{profit_percent:.2f}%{profit_extra}`\n"
|
||||
"*Sell Tag:* `{sell_tag}`\n"
|
||||
"*Sell Reason:* `{sell_reason}`\n"
|
||||
"*Duration:* `{duration} ({duration_min:.1f} min)`\n"
|
||||
"*Amount:* `{amount:.8f}`\n"
|
||||
"*Open Rate:* `{open_rate:.8f}`\n"
|
||||
"*Current Rate:* `{current_rate:.8f}`\n"
|
||||
"*Close Rate:* `{limit:.8f}`").format(**msg)
|
||||
|
||||
|
||||
return message
|
||||
|
||||
def compose_message(self, msg: Dict[str, Any], msg_type: RPCMessageType) -> str:
|
||||
@@ -393,6 +355,18 @@ class Telegram(RPCHandler):
|
||||
else:
|
||||
return "\N{CROSS MARK}"
|
||||
|
||||
def _get_tags_string(self, msg):
|
||||
"""
|
||||
Get string lines for buy/sell tags to display when a sell is made
|
||||
"""
|
||||
tag_lines = ""
|
||||
|
||||
if ("buy_tag" in msg.keys() and msg['buy_tag'] is not None):
|
||||
tag_lines += ("*Buy Tag:* `{buy_tag}`\n").format(msg['buy_tag'])
|
||||
if ("exit_tag" in msg.keys() and msg['exit_tag'] is not None):
|
||||
tag_lines += ("*Sell Tag:* `{exit_tag}`\n").format(msg['exit_tag'])
|
||||
return tag_lines
|
||||
|
||||
@authorized_only
|
||||
def _status(self, update: Update, context: CallbackContext) -> None:
|
||||
"""
|
||||
@@ -425,7 +399,7 @@ class Telegram(RPCHandler):
|
||||
"*Current Pair:* {pair}",
|
||||
"*Amount:* `{amount} ({stake_amount} {base_currency})`",
|
||||
"*Buy Tag:* `{buy_tag}`" if r['buy_tag'] else "",
|
||||
"*Sell Tag:* `{sell_tag}`" if r['sell_tag'] else "",
|
||||
"*Sell Tag:* `{exit_tag}`" if r['exit_tag'] else "",
|
||||
"*Open Rate:* `{open_rate:.8f}`",
|
||||
"*Close Rate:* `{close_rate}`" if r['close_rate'] else "",
|
||||
"*Current Rate:* `{current_rate:.8f}`",
|
||||
@@ -923,12 +897,12 @@ class Telegram(RPCHandler):
|
||||
:return: None
|
||||
"""
|
||||
try:
|
||||
pair=None
|
||||
pair = None
|
||||
if context.args:
|
||||
pair = context.args[0]
|
||||
|
||||
trades = self._rpc._rpc_buy_tag_performance(pair)
|
||||
output = "<b>Performance:</b>\n"
|
||||
output = "<b>Buy Tag Performance:</b>\n"
|
||||
for i, trade in enumerate(trades):
|
||||
stat_line = (
|
||||
f"{i+1}.\t <code>{trade['buy_tag']}\t"
|
||||
@@ -949,7 +923,7 @@ class Telegram(RPCHandler):
|
||||
self._send_msg(str(e))
|
||||
|
||||
@authorized_only
|
||||
def _sell_tag_performance(self, update: Update, context: CallbackContext) -> None:
|
||||
def _exit_tag_performance(self, update: Update, context: CallbackContext) -> None:
|
||||
"""
|
||||
Handler for /sells.
|
||||
Shows a performance statistic from finished trades
|
||||
@@ -958,15 +932,15 @@ class Telegram(RPCHandler):
|
||||
:return: None
|
||||
"""
|
||||
try:
|
||||
pair=None
|
||||
pair = None
|
||||
if context.args:
|
||||
pair = context.args[0]
|
||||
|
||||
trades = self._rpc._rpc_sell_tag_performance(pair)
|
||||
output = "<b>Performance:</b>\n"
|
||||
trades = self._rpc._rpc_exit_tag_performance(pair)
|
||||
output = "<b>Sell Tag Performance:</b>\n"
|
||||
for i, trade in enumerate(trades):
|
||||
stat_line = (
|
||||
f"{i+1}.\t <code>{trade['sell_tag']}\t"
|
||||
f"{i+1}.\t <code>{trade['exit_tag']}\t"
|
||||
f"{round_coin_value(trade['profit_abs'], self._config['stake_currency'])} "
|
||||
f"({trade['profit']:.2f}%) "
|
||||
f"({trade['count']})</code>\n")
|
||||
@@ -978,7 +952,7 @@ class Telegram(RPCHandler):
|
||||
output += stat_line
|
||||
|
||||
self._send_msg(output, parse_mode=ParseMode.HTML,
|
||||
reload_able=True, callback_path="update_sell_tag_performance",
|
||||
reload_able=True, callback_path="update_exit_tag_performance",
|
||||
query=update.callback_query)
|
||||
except RPCException as e:
|
||||
self._send_msg(str(e))
|
||||
@@ -993,13 +967,14 @@ class Telegram(RPCHandler):
|
||||
:return: None
|
||||
"""
|
||||
try:
|
||||
pair=None
|
||||
pair = None
|
||||
if context.args:
|
||||
pair = context.args[0]
|
||||
|
||||
trades = self._rpc._rpc_mix_tag_performance(pair)
|
||||
output = "<b>Performance:</b>\n"
|
||||
output = "<b>Mix Tag Performance:</b>\n"
|
||||
for i, trade in enumerate(trades):
|
||||
print(str(trade))
|
||||
stat_line = (
|
||||
f"{i+1}.\t <code>{trade['mix_tag']}\t"
|
||||
f"{round_coin_value(trade['profit_abs'], self._config['stake_currency'])} "
|
||||
|
||||
Reference in New Issue
Block a user