Removes long format + pylint fixes
This commit is contained in:
parent
361bdd20d3
commit
60249af04c
@ -19,7 +19,7 @@ Persistence is achieved through sqlite.
|
|||||||
#### Telegram RPC commands:
|
#### Telegram RPC commands:
|
||||||
* /start: Starts the trader
|
* /start: Starts the trader
|
||||||
* /stop: Stops the trader
|
* /stop: Stops the trader
|
||||||
* /status [table [short]]: Lists all open trades
|
* /status [table]: Lists all open trades
|
||||||
* /count: Displays number of open trades
|
* /count: Displays number of open trades
|
||||||
* /profit: Lists cumulative profit from all finished trades
|
* /profit: Lists cumulative profit from all finished trades
|
||||||
* /forcesell <trade_id>: Instantly sells the given trade (Ignoring `minimum_roi`).
|
* /forcesell <trade_id>: Instantly sells the given trade (Ignoring `minimum_roi`).
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Callable, Any
|
from typing import Callable, Any
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
@ -164,11 +165,6 @@ def _status_table(bot: Bot, update: Update) -> None:
|
|||||||
:param update: message update
|
:param update: message update
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
short_version = False
|
|
||||||
params = update.message.text.replace('/status', '').split(' ')
|
|
||||||
if 'short' in params:
|
|
||||||
short_version = True
|
|
||||||
|
|
||||||
# Fetch open trade
|
# Fetch open trade
|
||||||
trades = Trade.query.filter(Trade.is_open.is_(True)).all()
|
trades = Trade.query.filter(Trade.is_open.is_(True)).all()
|
||||||
if get_state() != State.RUNNING:
|
if get_state() != State.RUNNING:
|
||||||
@ -180,46 +176,29 @@ def _status_table(bot: Bot, update: Update) -> None:
|
|||||||
for trade in trades:
|
for trade in trades:
|
||||||
# calculate profit and send message to user
|
# calculate profit and send message to user
|
||||||
current_rate = exchange.get_ticker(trade.pair)['bid']
|
current_rate = exchange.get_ticker(trade.pair)['bid']
|
||||||
current_profit = 100 * ((current_rate - trade.open_rate) / trade.open_rate)
|
current_profit = '{:.2f}'.format(100 * ((current_rate \
|
||||||
orders = exchange.get_open_orders(trade.pair)
|
- trade.open_rate) / trade.open_rate))
|
||||||
orders = [o for o in orders if o['id'] == trade.open_order_id]
|
|
||||||
order = orders[0] if orders else None
|
|
||||||
|
|
||||||
fmt_close_profit = '{:.2f}'.format(trade.close_profit) if trade.close_profit else 'No'
|
|
||||||
fmt_current_profit = '{:.2f}'.format(current_profit)
|
|
||||||
|
|
||||||
row = [
|
row = [
|
||||||
trade.id,
|
trade.id,
|
||||||
trade.pair,
|
trade.pair,
|
||||||
shorten_date(arrow.get(trade.open_date).humanize()),
|
shorten_date(arrow.get(trade.open_date).humanize(only_distance=True)),
|
||||||
round(trade.amount, 8),
|
current_profit
|
||||||
trade.open_rate,
|
|
||||||
trade.close_rate,
|
|
||||||
current_rate,
|
|
||||||
fmt_close_profit,
|
|
||||||
fmt_current_profit,
|
|
||||||
'{} ({})'.format(order['remaining'], order['type']) if order else 'No'
|
|
||||||
]
|
]
|
||||||
|
|
||||||
trades_list.append(row)
|
trades_list.append(row)
|
||||||
|
|
||||||
columns = ['ID', 'Pair', 'Since', 'Amount', 'Open Rate',
|
columns = ['ID', 'Pair', 'Since', 'Profit']
|
||||||
'Close Rate', 'Cur. Rate', 'Close Profit', 'Profit',
|
|
||||||
'Open Order']
|
|
||||||
|
|
||||||
df = DataFrame.from_records(trades_list, columns=columns)
|
df_statuses = DataFrame.from_records(trades_list, columns=columns)
|
||||||
df = df.set_index(columns[0])
|
df_statuses = df_statuses.set_index(columns[0])
|
||||||
|
|
||||||
columns_short = ['Pair', 'Since', 'Profit']
|
message = tabulate(df_statuses, headers='keys', tablefmt='simple')
|
||||||
|
|
||||||
if short_version == True:
|
|
||||||
df = df[columns_short]
|
|
||||||
|
|
||||||
message = tabulate(df, headers='keys', tablefmt='simple')
|
|
||||||
message = "<pre>{}</pre>".format(message)
|
message = "<pre>{}</pre>".format(message)
|
||||||
|
|
||||||
send_msg(message, parse_mode=ParseMode.HTML)
|
send_msg(message, parse_mode=ParseMode.HTML)
|
||||||
|
|
||||||
|
|
||||||
@authorized_only
|
@authorized_only
|
||||||
def _profit(bot: Bot, update: Update) -> None:
|
def _profit(bot: Bot, update: Update) -> None:
|
||||||
"""
|
"""
|
||||||
@ -387,7 +366,7 @@ def _performance(bot: Bot, update: Update) -> None:
|
|||||||
|
|
||||||
|
|
||||||
@authorized_only
|
@authorized_only
|
||||||
def _count(bot: Bot, update: Update) -> None:
|
def _count(bot: Bot) -> None:
|
||||||
"""
|
"""
|
||||||
Handler for /count.
|
Handler for /count.
|
||||||
Returns the number of trades running
|
Returns the number of trades running
|
||||||
@ -400,11 +379,8 @@ def _count(bot: Bot, update: Update) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
trades = Trade.query.filter(Trade.is_open.is_(True)).all()
|
trades = Trade.query.filter(Trade.is_open.is_(True)).all()
|
||||||
|
message = '<b>Count:</b>\ncurrent/max\n{}/{}\n'.format(len(trades), _CONF['max_open_trades'])
|
||||||
|
|
||||||
current_trades_count = len(trades)
|
|
||||||
max_trades_count = _CONF['max_open_trades']
|
|
||||||
|
|
||||||
message = '<b>Count:</b>\ncurrent/max\n{}/{}\n'.format(current_trades_count, max_trades_count)
|
|
||||||
logger.debug(message)
|
logger.debug(message)
|
||||||
send_msg(message, parse_mode=ParseMode.HTML)
|
send_msg(message, parse_mode=ParseMode.HTML)
|
||||||
|
|
||||||
@ -421,9 +397,8 @@ def _help(bot: Bot, update: Update) -> None:
|
|||||||
message = """
|
message = """
|
||||||
*/start:* `Starts the trader`
|
*/start:* `Starts the trader`
|
||||||
*/stop:* `Stops the trader`
|
*/stop:* `Stops the trader`
|
||||||
*/status [table [short]]:* `Lists all open trades`
|
*/status [table]:* `Lists all open trades`
|
||||||
*table :* `will display trades in a table`
|
*table :* `will display trades in a table`
|
||||||
*short :* `condensed output`
|
|
||||||
*/profit:* `Lists cumulative profit from all finished trades`
|
*/profit:* `Lists cumulative profit from all finished trades`
|
||||||
*/forcesell <trade_id>:* `Instantly sells the given trade, regardless of profit`
|
*/forcesell <trade_id>:* `Instantly sells the given trade, regardless of profit`
|
||||||
*/performance:* `Show performance of each finished trade grouped by pair`
|
*/performance:* `Show performance of each finished trade grouped by pair`
|
||||||
@ -434,17 +409,15 @@ def _help(bot: Bot, update: Update) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def shorten_date(date):
|
def shorten_date(date):
|
||||||
return date.replace('ago', '') \
|
"""
|
||||||
.replace('seconds', 's') \
|
Trim the date so it fits on small screens
|
||||||
.replace('minutes', 'm') \
|
"""
|
||||||
.replace('minute', 'm') \
|
new_date = re.sub('seconds?', 'sec', date)
|
||||||
.replace('hours', 'h') \
|
new_date = re.sub('minutes?', 'min', new_date)
|
||||||
.replace('hour', 'h') \
|
new_date = re.sub('hours?', 'h', new_date)
|
||||||
.replace('days', 'd') \
|
new_date = re.sub('days?', 'd', new_date)
|
||||||
.replace('day', 'd') \
|
new_date = re.sub('^an?', '1', new_date)
|
||||||
.replace('an', '1') \
|
return new_date
|
||||||
.replace('a', '1') \
|
|
||||||
.replace(' ', '')
|
|
||||||
|
|
||||||
|
|
||||||
def send_msg(msg: str, bot: Bot = None, parse_mode: ParseMode = ParseMode.MARKDOWN) -> None:
|
def send_msg(msg: str, bot: Bot = None, parse_mode: ParseMode = ParseMode.MARKDOWN) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user