Implement accounting for open trade value as part of total remaining

This commit is contained in:
Mark Veidemanis 2022-02-09 18:45:43 +00:00
parent 3417e6166a
commit fdc3f419cc
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 44 additions and 0 deletions

View File

@ -441,3 +441,13 @@ class IRCCommands(object):
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
remaining = tx.get_remaining()
msg(f"Remaining: {remaining}USD")
class total_remaining(object):
name = "tr"
authed = True
helptext = "Show how much is left before we are able to withdraw funds (including open trades)."
@staticmethod
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
remaining = tx.get_total_remaining()
msg(f"Total remaining: {remaining}USD")

View File

@ -458,3 +458,37 @@ class Transactions(object):
remaining = withdraw_threshold - total_usd
return remaining
def get_open_trades_usd(self):
dash = self.agora.wrap_dashboard()
if dash is False:
return False
rates = self.agora.get_rates_all()
cumul_usd = 0
for contact_id, contact in dash.items():
amount = contact["data"]["amount"]
currency = contact["data"]["currency"]
if not contact["data"]["is_selling"]:
continue
if currency == "USD":
cumul_usd += amount
else:
rate = rates[currency]
amount_usd = float(amount) / rate
print("AMOUTN USD", amount_usd)
cumul_usd += amount_usd
return cumul_usd
def get_total_remaining(self):
total_usd = self.get_total_usd()
total_trades_usd = self.get_open_trades_usd()
if not total_usd:
return False
total_usd += total_trades_usd
withdraw_threshold = float(settings.Money.BaseUSD) + float(settings.Money.WithdrawLimit)
remaining = withdraw_threshold - total_usd
return remaining