444 lines
16 KiB
Python
444 lines
16 KiB
Python
# Other library imports
|
|
from json import dumps, loads
|
|
|
|
# Project imports
|
|
from settings import settings
|
|
|
|
|
|
class IRCCommands(object):
|
|
class trades(object):
|
|
name = "trades"
|
|
authed = True
|
|
helptext = "Get all open trades."
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
"""
|
|
Get details of open trades and post on IRC.
|
|
"""
|
|
# Send IRC - we don't want to automatically send messages on IRC, even though
|
|
# this variable seems counter-intuitive here, we are doing something with the result
|
|
# then calling msg() ourselves, and we don't want extra spam in the channel.
|
|
trades = agora.get_dashboard()
|
|
if not trades:
|
|
msg("No open trades.")
|
|
return
|
|
for trade_id in trades:
|
|
msg(trade_id)
|
|
|
|
class create(object):
|
|
name = "create"
|
|
authed = True
|
|
helptext = "Create an ad. Usage: create <XMR/BTC> <country> <currency>"
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
"""
|
|
Post an ad on AgoraDesk with the given country and currency code.
|
|
"""
|
|
if length == 4:
|
|
if spl[1] not in loads(settings.Agora.AssetList):
|
|
msg(f"Not a valid asset: {spl[1]}")
|
|
return
|
|
posted = agora.create_ad(spl[1], spl[2], spl[3], "REVOLUT")
|
|
if posted["success"]:
|
|
msg(f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}")
|
|
else:
|
|
msg(dumps(posted["response"]))
|
|
|
|
class messages(object):
|
|
name = "messages"
|
|
authed = True
|
|
helptext = "Get messages. Usage: messages [<reference>]"
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
"""
|
|
Get all messages for all open trades or a given trade.
|
|
"""
|
|
if length == 1:
|
|
messages = agora.get_recent_messages()
|
|
if messages is False:
|
|
msg("Error getting messages.")
|
|
return
|
|
if not messages:
|
|
msg("No messages.")
|
|
return
|
|
for reference in messages:
|
|
for message in messages[reference]:
|
|
msg(f"{reference}: {message[0]} {message[1]}")
|
|
msg("---")
|
|
|
|
elif length == 2:
|
|
tx = tx.ref_to_tx(spl[1])
|
|
if not tx:
|
|
msg(f"No such reference: {spl[1]}")
|
|
return
|
|
messages = agora.get_messages(spl[1], send_irc=False)
|
|
if not messages:
|
|
msg("No messages.")
|
|
for message in messages:
|
|
msg(f"{spl[1]}: {message}")
|
|
|
|
class dist(object):
|
|
name = "dist"
|
|
authed = True
|
|
helptext = "Distribute all our chosen currency and country ad pairs."
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
# Distribute out our ad to all countries in the config
|
|
for x in agora.dist_countries():
|
|
if x["success"]:
|
|
msg(f"{x['response']['data']['message']}: {x['response']['data']['ad_id']}")
|
|
else:
|
|
msg(dumps(x["response"]))
|
|
|
|
class redist(object):
|
|
name = "redist"
|
|
authed = True
|
|
helptext = "Update all ads with details."
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
for x in agora.redist_countries():
|
|
if x[0]["success"]:
|
|
msg(f"{x[0]['response']['data']['message']}: {x[1]}")
|
|
else:
|
|
msg(dumps(x[0]["response"]))
|
|
|
|
class stripdupes(object):
|
|
name = "stripdupes"
|
|
authed = True
|
|
helptext = "Remove all duplicate adverts."
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
rtrn = agora.strip_duplicate_ads()
|
|
msg(dumps(rtrn))
|
|
|
|
class find(object):
|
|
name = "find"
|
|
authed = True
|
|
helptext = "Find a transaction. Usage: find <currency> <amount>"
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
"""
|
|
Find a transaction received by Revolut with the given reference and amount.
|
|
"""
|
|
try:
|
|
int(spl[2])
|
|
except ValueError:
|
|
msg("Amount is not an integer.")
|
|
rtrn = tx.find_tx(spl[1], spl[2])
|
|
if rtrn == "AMOUNT_INVALID":
|
|
msg("Reference found but amount invalid.")
|
|
elif not rtrn:
|
|
msg("Reference not found.")
|
|
else:
|
|
return dumps(rtrn)
|
|
|
|
class accounts(object):
|
|
name = "accounts"
|
|
authed = True
|
|
helptext = "Get all account information from Revolut."
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
accounts = revolut.accounts()
|
|
accounts_posted = 0
|
|
if accounts is None:
|
|
msg("Error getting accounts.")
|
|
for account in accounts:
|
|
if account["balance"] > 0:
|
|
if "name" in account:
|
|
name = account["name"]
|
|
else:
|
|
name = "not_set"
|
|
msg(f"{name} {account['currency']}: {account['balance']}")
|
|
accounts_posted += 1
|
|
if accounts_posted == 0:
|
|
msg("No accounts with balances.")
|
|
|
|
class balance(object):
|
|
name = "balance"
|
|
authed = True
|
|
helptext = "Get total account balance from Revolut in USD."
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
total_usd = revolut.get_total_usd()
|
|
if total_usd is False:
|
|
msg("Error getting total balance.")
|
|
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, notify):
|
|
totals_all = tx.get_total()
|
|
totals = totals_all[0]
|
|
wallets = totals_all[1]
|
|
msg(f"Totals: SEK: {totals[0]} | USD: {totals[1]} | GBP: {totals[2]}")
|
|
msg(f"Wallets: XMR USD: {wallets[0]} | BTC USD: {wallets[1]}")
|
|
|
|
class ping(object):
|
|
name = "ping"
|
|
authed = False
|
|
helptext = "Pong!"
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg):
|
|
msg("Pong!")
|
|
|
|
class summon(object):
|
|
name = "summon"
|
|
authed = True
|
|
helptext = "Summon all operators."
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
notify.sendmsg("You have been summoned!")
|
|
|
|
class release_url(object):
|
|
name = "release_url"
|
|
authed = True
|
|
helptext = "Get release URL for all open trades."
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
trades = agora.dashboard_release_urls()
|
|
if not trades:
|
|
msg("No trades.")
|
|
for trade in trades:
|
|
msg(trade)
|
|
|
|
class message(object):
|
|
name = "msg"
|
|
authed = True
|
|
helptext = "Send a message on a trade. Usage: msg <reference> <message...>"
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
if length > 2:
|
|
full_msg = " ".join(spl[2:])
|
|
reference = tx.ref_to_tx(spl[1])
|
|
if not reference:
|
|
msg(f"No such reference: {spl[1]}")
|
|
return
|
|
rtrn = agora.agora.contact_message_post(reference, full_msg)
|
|
msg(f"Sent {full_msg} to {reference}: {rtrn}")
|
|
|
|
class refs(object):
|
|
name = "refs"
|
|
authed = True
|
|
helptext = "List all references"
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
msg(f"References: {', '.join(tx.get_refs())}")
|
|
|
|
class ref(object):
|
|
name = "ref"
|
|
authed = True
|
|
helptext = "Get more information about a reference. Usage: ref <reference>"
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
if length == 2:
|
|
ref_data = tx.get_ref(spl[1])
|
|
if not ref_data:
|
|
msg(f"No such reference: {spl[1]}")
|
|
return
|
|
msg(f"{spl[1]}: {dumps(ref_data)}")
|
|
|
|
class delete(object):
|
|
name = "del"
|
|
authed = True
|
|
helptext = "Delete a reference. Usage: del <reference>"
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
if length == 2:
|
|
ref_data = tx.get_ref(spl[1])
|
|
if not ref_data:
|
|
msg(f"No such reference: {spl[1]}")
|
|
return
|
|
tx.del_ref(spl[1])
|
|
msg(f"Deleted reference: {spl[1]}")
|
|
|
|
class release(object):
|
|
name = "release"
|
|
authed = True
|
|
helptext = "Release funds for a trade. Usage: release <reference>"
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
if length == 2:
|
|
tx = tx.ref_to_tx(spl[1])
|
|
if not tx:
|
|
msg(f"No such reference: {spl[1]}")
|
|
return
|
|
rtrn = agora.release_funds(tx)
|
|
message = rtrn["message"]
|
|
message_long = rtrn["response"]["data"]["message"]
|
|
msg(f"{message} - {message_long}")
|
|
|
|
class nuke(object):
|
|
name = "nuke"
|
|
authed = True
|
|
helptext = "Delete all our adverts."
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
rtrn = agora.nuke_ads()
|
|
msg(dumps(rtrn))
|
|
|
|
class wallet(object):
|
|
name = "wallet"
|
|
authed = True
|
|
helptext = "Get Agora wallet balances."
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
rtrn_xmr = agora.agora.wallet_balance_xmr()
|
|
if not rtrn_xmr["success"]:
|
|
msg("Error getting XMR wallet details.")
|
|
return
|
|
rtrn_btc = agora.agora.wallet_balance()
|
|
if not rtrn_btc["success"]:
|
|
msg("Error getting BTC wallet details.")
|
|
return
|
|
balance_xmr = rtrn_xmr["response"]["data"]["total"]["balance"]
|
|
balance_btc = rtrn_btc["response"]["data"]["total"]["balance"]
|
|
msg(f"XMR wallet balance: {balance_xmr}")
|
|
msg(f"BTC wallet balance: {balance_btc}")
|
|
|
|
class pubads(object):
|
|
name = "pubads"
|
|
authed = True
|
|
helptext = "View public adverts. Usage: pubads <XMR/BTC> <currency>"
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
if length == 3:
|
|
asset = spl[1]
|
|
if asset not in loads(settings.Agora.AssetList):
|
|
msg(f"Not a valid asset: {spl[1]}")
|
|
return
|
|
currency = spl[2]
|
|
rtrn = agora.wrap_public_ads(asset, currency)
|
|
for ad in rtrn:
|
|
msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[4]}")
|
|
elif length == 4:
|
|
asset = spl[1]
|
|
if asset not in loads(settings.Agora.AssetList):
|
|
msg(f"Not a valid asset: {spl[1]}")
|
|
return
|
|
providers = spl[3].split(",")
|
|
currency = spl[2]
|
|
rtrn = agora.wrap_public_ads(asset, currency, providers)
|
|
for ad in rtrn:
|
|
msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]} {ad[4]}")
|
|
|
|
class cheat(object):
|
|
name = "cheat"
|
|
authed = True
|
|
helptext = "Cheat the markets by manipulating our prices to exploit people. Usage: cheat [<XMR/BTC>]"
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
if length == 1:
|
|
agora.run_cheat_in_thread()
|
|
msg("Running cheat in thread.")
|
|
elif length == 2:
|
|
asset = spl[1]
|
|
if asset not in loads(settings.Agora.AssetList):
|
|
msg(f"Not a valid asset: {spl[1]}")
|
|
return
|
|
agora.run_cheat_in_thread([asset])
|
|
msg(f"Running cheat in thread for {asset}.")
|
|
|
|
class cheatnext(object):
|
|
name = "cheatnext"
|
|
authed = True
|
|
helptext = "Run the next currency for cheat."
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
if length == 1:
|
|
asset = agora._update_prices(None, None)
|
|
msg(f"Running next asset for cheat in thread: {asset}")
|
|
|
|
class ads(object):
|
|
name = "ads"
|
|
authed = True
|
|
helptext = "Get all our ad regions"
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
ads = agora.enum_ads()
|
|
for ad in ads:
|
|
msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]} {ad[4]}")
|
|
|
|
class xmr(object):
|
|
name = "xmr"
|
|
authed = True
|
|
helptext = "Get current XMR price."
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
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, notify):
|
|
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}")
|
|
|
|
class withdraw(object):
|
|
name = "withdraw"
|
|
authed = True
|
|
helptext = "Take profit."
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
agora.withdraw_funds()
|
|
|
|
class shuffle(object):
|
|
name = "shuffle"
|
|
authed = True
|
|
helptext = "Convert all currencies in Revolut to supplied one. Usage: shuffle <currency>"
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
|
if length == 2:
|
|
currency = spl[1]
|
|
rtrn = revolut.shuffle(currency)
|
|
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")
|