Libraries refactor and add some sinks #4
|
@ -423,6 +423,8 @@ class Agora(object):
|
|||
def update_prices(self, assets=None):
|
||||
# Get all public ads for the given assets
|
||||
public_ads = self.get_all_public_ads(assets)
|
||||
if not public_ads:
|
||||
return False
|
||||
|
||||
# Get the ads to update
|
||||
to_update = self.markets.get_new_ad_equations(public_ads, assets)
|
||||
|
@ -449,7 +451,6 @@ class Agora(object):
|
|||
if not providers:
|
||||
providers = self.markets.get_all_providers()
|
||||
# We want to get the ads for each of these currencies and return the result
|
||||
|
||||
rates = self.cg.get_price(ids=["monero", "bitcoin"], vs_currencies=currencies)
|
||||
for asset in assets:
|
||||
for currency in currencies:
|
||||
|
@ -460,6 +461,8 @@ class Agora(object):
|
|||
self.log.error("Error getting public ads for currency {currency}", currency=currency)
|
||||
continue
|
||||
ads_list = self.enum_public_ads(asset, currency, providers)
|
||||
if not ads_list:
|
||||
continue
|
||||
ads = self.lookup_rates(ads_list, rates=rates)
|
||||
if not ads:
|
||||
continue
|
||||
|
@ -469,6 +472,7 @@ class Agora(object):
|
|||
public_ads[currency].append(ad)
|
||||
else:
|
||||
public_ads[currency] = ads
|
||||
|
||||
return public_ads
|
||||
|
||||
def slow_ad_update(self, ads):
|
||||
|
@ -486,7 +490,6 @@ class Agora(object):
|
|||
ad_id, new_formula, asset, currency, actioned = ads[ad_index]
|
||||
assets.add(asset)
|
||||
currencies.add(currency)
|
||||
self.log.error("ASSET {a}", a=asset)
|
||||
if not actioned:
|
||||
rtrn = self.agora.ad_equation(ad_id, new_formula)
|
||||
if rtrn["success"]:
|
||||
|
@ -732,7 +735,7 @@ class Agora(object):
|
|||
@handle_exceptions
|
||||
def withdraw_funds(self):
|
||||
"""
|
||||
Withdraw excess funds to our XMR/BTC wallets.
|
||||
Withdraw excess funds to our XMR wallets.
|
||||
"""
|
||||
totals_all = self.tx.get_total()
|
||||
if totals_all is False:
|
||||
|
@ -742,9 +745,11 @@ class Agora(object):
|
|||
|
||||
# Get the wallet balances in USD
|
||||
total_usd = totals_all[0][1]
|
||||
|
||||
total_trades_usd = self.tx.get_open_trades_usd()
|
||||
if not total_usd:
|
||||
return False
|
||||
total_usd += total_trades_usd
|
||||
profit_usd = total_usd - float(settings.Money.BaseUSD)
|
||||
|
||||
# Get the XMR -> USD exchange rate
|
||||
xmr_usd = self.cg.get_price(ids="monero", vs_currencies=["USD"])
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class IRCCommands(object):
|
|||
class create(object):
|
||||
name = "create"
|
||||
authed = True
|
||||
helptext = "Create an ad. Usage: create <XMR/BTC> <country> <currency>"
|
||||
helptext = "Create an ad. Usage: create <XMR/BTC> <country> <currency> [<provider>]"
|
||||
|
||||
@staticmethod
|
||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
||||
|
@ -45,6 +45,18 @@ class IRCCommands(object):
|
|||
msg(f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}")
|
||||
else:
|
||||
msg(dumps(posted["response"]))
|
||||
elif length == 5:
|
||||
if spl[1] not in loads(settings.Agora.AssetList):
|
||||
msg(f"Not a valid asset: {spl[1]}")
|
||||
return
|
||||
if spl[4] not in loads(settings.Agora.ProviderList):
|
||||
msg(f"Not a valid provider: {spl[4]}")
|
||||
return
|
||||
posted = agora.create_ad(spl[1], spl[2], spl[3], spl[4])
|
||||
if posted["success"]:
|
||||
msg(f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}")
|
||||
else:
|
||||
msg(dumps(posted["response"]))
|
||||
|
||||
class messages(object):
|
||||
name = "messages"
|
||||
|
@ -331,7 +343,10 @@ class IRCCommands(object):
|
|||
msg(f"Not a valid asset: {spl[1]}")
|
||||
return
|
||||
currency = spl[2]
|
||||
rtrn = agora.get_all_public_ads([asset], [currency])
|
||||
rtrn = agora.get_all_public_ads(assets=[asset], currencies=[currency])
|
||||
if not rtrn:
|
||||
msg("No results.")
|
||||
return
|
||||
for ad in rtrn[currency]:
|
||||
msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]} {ad[4]} {ad[5]} {ad[6]}")
|
||||
elif length == 4:
|
||||
|
@ -341,7 +356,10 @@ class IRCCommands(object):
|
|||
return
|
||||
providers = spl[3].split(",")
|
||||
currency = spl[2]
|
||||
rtrn = agora.get_all_public_ads([asset], [currency], providers)
|
||||
rtrn = agora.get_all_public_ads(assets=[asset], currencies=[currency], providers=providers)
|
||||
if not rtrn:
|
||||
msg("No results.")
|
||||
return
|
||||
for ad in rtrn[currency]:
|
||||
msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]} {ad[4]} {ad[5]} {ad[6]}")
|
||||
|
||||
|
|
Loading…
Reference in New Issue