Daily profit command - better message formatting and minor fixes
This commit is contained in:
parent
ccb8c3c352
commit
0b18c93d19
@ -25,7 +25,7 @@ Persistence is achieved through sqlite.
|
|||||||
* /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
|
||||||
* /daily [n]: Shows profit or loss per day, over the last n (default 7) days
|
* /daily <n>: Shows profit or loss per day, over the last n days
|
||||||
* /help: Show help message
|
* /help: Show help message
|
||||||
* /version: Show version
|
* /version: Show version
|
||||||
|
|
||||||
|
@ -212,7 +212,6 @@ def _daily(bot: Bot, update: Update) -> None:
|
|||||||
"""
|
"""
|
||||||
Handler for /daily <n>
|
Handler for /daily <n>
|
||||||
Returns a daily profit (in BTC) over the last n days.
|
Returns a daily profit (in BTC) over the last n days.
|
||||||
Default is 7 days
|
|
||||||
:param bot: telegram bot
|
:param bot: telegram bot
|
||||||
:param update: message update
|
:param update: message update
|
||||||
:return: None
|
:return: None
|
||||||
@ -222,9 +221,14 @@ def _daily(bot: Bot, update: Update) -> None:
|
|||||||
profit_days = {}
|
profit_days = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
timescale = update.message.text.replace('/daily', '').strip()
|
timescale = int(update.message.text.replace('/daily', '').strip())
|
||||||
except:
|
except:
|
||||||
timescale = 7
|
send_msg('*Daily <n>:* `must be an integer greater than 0`', bot=bot)
|
||||||
|
return
|
||||||
|
|
||||||
|
if not (isinstance(timescale, int) and timescale > 0):
|
||||||
|
send_msg('*Daily <n>:* `must be an integer greater than 0`', bot=bot)
|
||||||
|
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
|
||||||
@ -236,14 +240,13 @@ def _daily(bot: Bot, update: Update) -> None:
|
|||||||
curdayprofit += trade.close_profit * trade.stake_amount
|
curdayprofit += trade.close_profit * trade.stake_amount
|
||||||
profit_days[date.fromordinal(today-day)] = curdayprofit
|
profit_days[date.fromordinal(today-day)] = curdayprofit
|
||||||
|
|
||||||
|
stats = []
|
||||||
|
for key, value in profit_days.items():
|
||||||
|
stats.append([key, str(value) + ' BTC'])
|
||||||
|
stats = tabulate(stats, headers=['Day', 'Profit'], tablefmt='simple')
|
||||||
|
|
||||||
stats = '\n'.join('{index}\t{profit} BTC'.format(
|
message = '<b>Daily Profit over the last {} days</b>:\n<pre>{}</pre>'.format(timescale, stats)
|
||||||
index=key,
|
send_msg(message, bot=bot, parse_mode=ParseMode.HTML)
|
||||||
profit=value,
|
|
||||||
) for key, value in profit_days.items())
|
|
||||||
|
|
||||||
message = '<b>Daily Profit:</b>\n{}'.format(stats)
|
|
||||||
send_msg(message, bot=bot)
|
|
||||||
|
|
||||||
@authorized_only
|
@authorized_only
|
||||||
def _profit(bot: Bot, update: Update) -> None:
|
def _profit(bot: Bot, update: Update) -> None:
|
||||||
@ -469,6 +472,7 @@ def _help(bot: Bot, update: Update) -> None:
|
|||||||
*/profit:* `Lists cumulative profit from all finished trades`
|
*/profit:* `Lists cumulative profit from all finished trades`
|
||||||
*/forcesell <trade_id>|all:* `Instantly sells the given trade or all trades, regardless of profit`
|
*/forcesell <trade_id>|all:* `Instantly sells the given trade or all trades, regardless of profit`
|
||||||
*/performance:* `Show performance of each finished trade grouped by pair`
|
*/performance:* `Show performance of each finished trade grouped by pair`
|
||||||
|
*/daily <n>:* `Shows profit or loss per day, over the last n days`
|
||||||
*/count:* `Show number of trades running compared to allowed number of trades`
|
*/count:* `Show number of trades running compared to allowed number of trades`
|
||||||
*/balance:* `Show account balance per currency`
|
*/balance:* `Show account balance per currency`
|
||||||
*/help:* `This help message`
|
*/help:* `This help message`
|
||||||
@ -514,7 +518,7 @@ def send_msg(msg: str, bot: Bot = None, parse_mode: ParseMode = ParseMode.MARKDO
|
|||||||
|
|
||||||
bot = bot or _UPDATER.bot
|
bot = bot or _UPDATER.bot
|
||||||
|
|
||||||
keyboard = [['/status table', '/profit', '/performance', ],
|
keyboard = [['/daily', '/status table', '/profit', '/performance', ],
|
||||||
['/balance', '/status', '/count'],
|
['/balance', '/status', '/count'],
|
||||||
['/start', '/stop', '/help']]
|
['/start', '/stop', '/help']]
|
||||||
|
|
||||||
|
@ -345,10 +345,21 @@ def test_daily_handle(
|
|||||||
trade.close_date = datetime.utcnow()
|
trade.close_date = datetime.utcnow()
|
||||||
trade.is_open = False
|
trade.is_open = False
|
||||||
|
|
||||||
|
#try valid data
|
||||||
|
update.message.text = '/daily 7'
|
||||||
_daily(bot=MagicMock(), update=update)
|
_daily(bot=MagicMock(), update=update)
|
||||||
assert msg_mock.call_count == 1
|
assert msg_mock.call_count == 1
|
||||||
assert 'Daily' in msg_mock.call_args_list[0][0][0]
|
assert 'Daily' in msg_mock.call_args_list[0][0][0]
|
||||||
assert str(date.today()) + '\t1.50701325 BTC' in msg_mock.call_args_list[0][0][0]
|
assert str(date.today()) + ' 1.50701325 BTC' in msg_mock.call_args_list[0][0][0]
|
||||||
|
|
||||||
|
#try invalid data
|
||||||
|
msg_mock.reset_mock()
|
||||||
|
update_state(State.RUNNING)
|
||||||
|
update.message.text = '/daily'
|
||||||
|
_daily(bot=MagicMock(), update=update)
|
||||||
|
assert msg_mock.call_count == 1
|
||||||
|
assert 'must be an integer greater than 0' in msg_mock.call_args_list[0][0][0]
|
||||||
|
|
||||||
|
|
||||||
def test_count_handle(default_conf, update, ticker, mocker):
|
def test_count_handle(default_conf, update, ticker, mocker):
|
||||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||||
|
Loading…
Reference in New Issue
Block a user