Implement getting XMR/BTC rates and total balance
This commit is contained in:
parent
26bbe93dd2
commit
de232b1847
|
@ -167,8 +167,8 @@ class IRCCommands(object):
|
||||||
if accounts_posted == 0:
|
if accounts_posted == 0:
|
||||||
msg("No accounts with balances.")
|
msg("No accounts with balances.")
|
||||||
|
|
||||||
class total(object):
|
class balance(object):
|
||||||
name = "total"
|
name = "balance"
|
||||||
authed = True
|
authed = True
|
||||||
helptext = "Get total account balance from Revolut in USD."
|
helptext = "Get total account balance from Revolut in USD."
|
||||||
|
|
||||||
|
@ -179,6 +179,36 @@ class IRCCommands(object):
|
||||||
msg("Error getting total balance.")
|
msg("Error getting total balance.")
|
||||||
msg(f"Total: {round(total_usd, 2)}USD")
|
msg(f"Total: {round(total_usd, 2)}USD")
|
||||||
|
|
||||||
|
class total(object):
|
||||||
|
name = "total"
|
||||||
|
authed = True
|
||||||
|
helptext = "Get total account balance from Revolut and Agora."
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
total_usd_revolut = revolut.get_total_usd()
|
||||||
|
if total_usd_revolut is False:
|
||||||
|
msg("Error getting Revolut balance.")
|
||||||
|
return
|
||||||
|
agora_wallet = agora.agora.wallet_balance_xmr()
|
||||||
|
if not agora_wallet["success"]:
|
||||||
|
msg("Error getting Agora balance.")
|
||||||
|
return
|
||||||
|
total_xmr_agora = agora_wallet["response"]["data"]["total"]["balance"]
|
||||||
|
# Get the XMR -> USD exchange rate
|
||||||
|
xmr_usd = agora.cg.get_price(ids="monero", vs_currencies=["USD"])
|
||||||
|
|
||||||
|
# Convert the Agora XMR total to USD
|
||||||
|
total_usd_agora = float(total_xmr_agora) * xmr_usd["monero"]["usd"]
|
||||||
|
total_usd = total_usd_agora + total_usd_revolut
|
||||||
|
|
||||||
|
# Convert the total USD price to GBP and SEK
|
||||||
|
rates = agora.get_rates_all()
|
||||||
|
price_sek = rates["SEK"] * total_usd
|
||||||
|
price_usd = total_usd
|
||||||
|
price_gbp = rates["GBP"] * total_usd
|
||||||
|
msg(f"SEK: {price_sek} | USD: {price_usd} | GBP: {price_gbp}")
|
||||||
|
|
||||||
class ping(object):
|
class ping(object):
|
||||||
name = "ping"
|
name = "ping"
|
||||||
authed = False
|
authed = False
|
||||||
|
@ -314,7 +344,7 @@ class IRCCommands(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
rtrn = agora.update_prices()
|
rtrn = agora._update_prices()
|
||||||
msg(dumps(rtrn))
|
msg(dumps(rtrn))
|
||||||
|
|
||||||
class ads(object):
|
class ads(object):
|
||||||
|
@ -327,3 +357,29 @@ class IRCCommands(object):
|
||||||
ads = agora.enum_ads()
|
ads = agora.enum_ads()
|
||||||
for ad in ads:
|
for ad in ads:
|
||||||
msg(f"({ad[0]}) {ad[1]} {ad[2]}")
|
msg(f"({ad[0]}) {ad[1]} {ad[2]}")
|
||||||
|
|
||||||
|
class xmr(object):
|
||||||
|
name = "xmr"
|
||||||
|
authed = True
|
||||||
|
helptext = "Get current XMR price."
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
xmr_prices = agora.cg.get_price(ids="monero", vs_currencies=["sek", "usd", "gbp"])
|
||||||
|
price_sek = xmr_prices["monero"]["sek"]
|
||||||
|
price_usd = xmr_prices["monero"]["usd"]
|
||||||
|
price_gbp = xmr_prices["monero"]["gbp"]
|
||||||
|
msg(f"SEK: {price_sek} | USD: {price_usd} | GBP: {price_gbp}")
|
||||||
|
|
||||||
|
class btc(object):
|
||||||
|
name = "btc"
|
||||||
|
authed = True
|
||||||
|
helptext = "Get current BTC price."
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
xmr_prices = agora.cg.get_price(ids="bitcoin", vs_currencies=["sek", "usd", "gbp"])
|
||||||
|
price_sek = xmr_prices["bitcoin"]["sek"]
|
||||||
|
price_usd = xmr_prices["bitcoin"]["usd"]
|
||||||
|
price_gbp = xmr_prices["bitcoin"]["gbp"]
|
||||||
|
msg(f"SEK: {price_sek} | USD: {price_usd} | GBP: {price_gbp}")
|
||||||
|
|
Loading…
Reference in New Issue