Libraries refactor and add some sinks #4

Closed
m wants to merge 136 commits from library-refactor into master
2 changed files with 49 additions and 0 deletions
Showing only changes of commit 0675b015e5 - Show all commits

View File

@ -450,3 +450,13 @@ class IRCCommands(object):
currency = spl[1] currency = spl[1]
rtrn = revolut.shuffle(currency) rtrn = revolut.shuffle(currency)
msg(dumps(rtrn)) msg(dumps(rtrn))
class remaining(object):
name = "r"
authed = True
helptext = "Show how much is left before we are able to withdraw funds."
@staticmethod
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
remaining = tx.get_remaining()
msg(f"Remaining: {remaining}USD")

View File

@ -392,6 +392,35 @@ class Transactions(object):
return False return False
return ref_data["id"] return ref_data["id"]
def get_total_usd(self):
total_usd_revolut = self.revolut.get_total_usd()
if total_usd_revolut is False:
return False
agora_wallet_xmr = self.agora.agora.wallet_balance_xmr()
if not agora_wallet_xmr["success"]:
return False
agora_wallet_btc = self.agora.agora.wallet_balance()
if not agora_wallet_btc["success"]:
return False
total_xmr_agora = agora_wallet_xmr["response"]["data"]["total"]["balance"]
total_btc_agora = agora_wallet_btc["response"]["data"]["total"]["balance"]
# Get the XMR -> USD exchange rate
xmr_usd = self.agora.cg.get_price(ids="monero", vs_currencies=["USD"])
# Get the BTC -> USD exchange rate
btc_usd = self.agora.cg.get_price(ids="bitcoin", vs_currencies=["USD"])
# Convert the Agora XMR total to USD
total_usd_agora_xmr = float(total_xmr_agora) * xmr_usd["monero"]["usd"]
# Convert the Agora BTC total to USD
total_usd_agora_btc = float(total_btc_agora) * btc_usd["bitcoin"]["usd"]
# Add it all up
total_usd_agora = total_usd_agora_xmr + total_usd_agora_btc
total_usd = total_usd_agora + total_usd_revolut
return total_usd
def get_total(self): def get_total(self):
total_usd_revolut = self.revolut.get_total_usd() total_usd_revolut = self.revolut.get_total_usd()
if total_usd_revolut is False: if total_usd_revolut is False:
@ -431,3 +460,13 @@ class Transactions(object):
(total_usd_agora_xmr, total_usd_agora_btc), # Total USD balance in only Agora (total_usd_agora_xmr, total_usd_agora_btc), # Total USD balance in only Agora
(total_xmr_agora, total_btc_agora), (total_xmr_agora, total_btc_agora),
) # Total XMR and BTC balance in Agora ) # Total XMR and BTC balance in Agora
def get_remaining(self):
total_usd = self.get_total_usd()
if not total_usd:
return False
withdraw_threshold = float(settings.Money.BaseUSD) + float(settings.Money.WithdrawLimit)
remaining = withdraw_threshold - total_usd
return remaining