Add commands to check only profit

This commit is contained in:
Mark Veidemanis 2022-02-15 23:20:42 +00:00
parent 17ec43eba0
commit 6eff2b76e7
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 37 additions and 0 deletions

View File

@ -465,3 +465,23 @@ class IRCCommands(object):
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
total = tx.get_total_with_trades()
msg(f"${total}")
class profit(object):
name = "profit"
authed = True
helptext = "Get total profit."
@staticmethod
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
total = tx.get_profit()
msg(f"Profit: {total}USD")
class tprofit(object):
name = "tprofit"
authed = True
helptext = "Get total profit with open trades."
@staticmethod
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
total = tx.get_profit(True)
msg(f"Profit: {total}USD")

View File

@ -485,6 +485,23 @@ class Transactions(object):
return remaining
# TODO: move to money
def get_profit(self, trades=False):
"""
Check how much total profit we have made.
:return: profit in USD
:rtype: float
"""
total_usd = self.get_total_usd()
if not total_usd:
return False
if trades:
trades_usd = self.get_open_trades_usd()
total_usd += trades_usd
profit = total_usd - float(settings.Money.BaseUSD)
return profit
def get_open_trades_usd(self):
"""
Get total value of open trades in USD.