/daily: fix identation and simplify loops
This commit is contained in:
parent
e00f02b603
commit
c1c9dd03ce
@ -208,6 +208,7 @@ def _status_table(bot: Bot, update: Update) -> None:
|
|||||||
|
|
||||||
send_msg(message, parse_mode=ParseMode.HTML)
|
send_msg(message, parse_mode=ParseMode.HTML)
|
||||||
|
|
||||||
|
|
||||||
@authorized_only
|
@authorized_only
|
||||||
def _daily(bot: Bot, update: Update) -> None:
|
def _daily(bot: Bot, update: Update) -> None:
|
||||||
"""
|
"""
|
||||||
@ -217,37 +218,33 @@ def _daily(bot: Bot, update: Update) -> None:
|
|||||||
:param update: message update
|
:param update: message update
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
trades = Trade.query.order_by(Trade.close_date).all()
|
|
||||||
today = date.today().toordinal()
|
today = date.today().toordinal()
|
||||||
profit_days = {}
|
profit_days = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
timescale = int(update.message.text.replace('/daily', '').strip())
|
timescale = int(update.message.text.replace('/daily', '').strip())
|
||||||
except:
|
except (TypeError, ValueError):
|
||||||
timescale = 5
|
timescale = 5
|
||||||
|
|
||||||
if not (isinstance(timescale, int) and timescale > 0):
|
if not (isinstance(timescale, int) and timescale > 0):
|
||||||
send_msg('*Daily [n]:* `must be an integer greater than 0`', bot=bot)
|
send_msg('*Daily [n]:* `must be an integer greater than 0`', bot=bot)
|
||||||
return
|
return
|
||||||
|
|
||||||
for day in range(0, timescale):
|
for day in range(0, timescale):
|
||||||
#need to query between day+1 and day-1
|
# need to query between day+1 and day-1
|
||||||
nextdate = date.fromordinal(today-day+1)
|
nextdate = date.fromordinal(today-day+1)
|
||||||
prevdate = date.fromordinal(today-day-1)
|
prevdate = date.fromordinal(today-day-1)
|
||||||
trades = Trade.query.filter(between(Trade.close_date, prevdate, nextdate)).all()
|
trades = Trade.query.filter(between(Trade.close_date, prevdate, nextdate)).all()
|
||||||
curdayprofit = 0
|
curdayprofit = sum(trade.close_profit * trade.stake_amount for trade in trades)
|
||||||
for trade in trades:
|
profit_days[date.fromordinal(today-day)] = format(curdayprofit, '.8f')
|
||||||
curdayprofit += trade.close_profit * trade.stake_amount
|
|
||||||
profit_days[date.fromordinal(today-day)] = format(curdayprofit, '.8f')
|
|
||||||
|
|
||||||
stats = []
|
stats = [[key, str(value) + ' BTC'] for key, value in profit_days.items()]
|
||||||
for key, value in profit_days.items():
|
|
||||||
stats.append([key, str(value) + ' BTC'])
|
|
||||||
stats = tabulate(stats, headers=['Day', 'Profit'], tablefmt='simple')
|
stats = tabulate(stats, headers=['Day', 'Profit'], tablefmt='simple')
|
||||||
|
|
||||||
message = '<b>Daily Profit over the last {} days</b>:\n<pre>{}</pre>'.format(timescale, stats)
|
message = '<b>Daily Profit over the last {} days</b>:\n<pre>{}</pre>'.format(timescale, stats)
|
||||||
send_msg(message, bot=bot, parse_mode=ParseMode.HTML)
|
send_msg(message, bot=bot, parse_mode=ParseMode.HTML)
|
||||||
|
|
||||||
|
|
||||||
@authorized_only
|
@authorized_only
|
||||||
def _profit(bot: Bot, update: Update) -> None:
|
def _profit(bot: Bot, update: Update) -> None:
|
||||||
"""
|
"""
|
||||||
@ -504,11 +501,11 @@ def _version(bot: Bot, update: Update) -> None:
|
|||||||
send_msg('*Version:* `{}`'.format(__version__), bot=bot)
|
send_msg('*Version:* `{}`'.format(__version__), bot=bot)
|
||||||
|
|
||||||
|
|
||||||
def shorten_date(date):
|
def shorten_date(_date):
|
||||||
"""
|
"""
|
||||||
Trim the date so it fits on small screens
|
Trim the date so it fits on small screens
|
||||||
"""
|
"""
|
||||||
new_date = re.sub('seconds?', 'sec', date)
|
new_date = re.sub('seconds?', 'sec', _date)
|
||||||
new_date = re.sub('minutes?', 'min', new_date)
|
new_date = re.sub('minutes?', 'min', new_date)
|
||||||
new_date = re.sub('hours?', 'h', new_date)
|
new_date = re.sub('hours?', 'h', new_date)
|
||||||
new_date = re.sub('days?', 'd', new_date)
|
new_date = re.sub('days?', 'd', new_date)
|
||||||
|
Loading…
Reference in New Issue
Block a user