Account trades for withdrawal calculation and fix cheat for multiple providers

This commit is contained in:
Mark Veidemanis 2022-02-13 09:56:22 +00:00
parent 1f17183b1f
commit 42dbccf043
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 31 additions and 8 deletions

View File

@ -423,6 +423,8 @@ class Agora(object):
def update_prices(self, assets=None): def update_prices(self, assets=None):
# Get all public ads for the given assets # Get all public ads for the given assets
public_ads = self.get_all_public_ads(assets) public_ads = self.get_all_public_ads(assets)
if not public_ads:
return False
# Get the ads to update # Get the ads to update
to_update = self.markets.get_new_ad_equations(public_ads, assets) to_update = self.markets.get_new_ad_equations(public_ads, assets)
@ -449,7 +451,6 @@ class Agora(object):
if not providers: if not providers:
providers = self.markets.get_all_providers() providers = self.markets.get_all_providers()
# We want to get the ads for each of these currencies and return the result # 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) rates = self.cg.get_price(ids=["monero", "bitcoin"], vs_currencies=currencies)
for asset in assets: for asset in assets:
for currency in currencies: for currency in currencies:
@ -460,6 +461,8 @@ class Agora(object):
self.log.error("Error getting public ads for currency {currency}", currency=currency) self.log.error("Error getting public ads for currency {currency}", currency=currency)
continue continue
ads_list = self.enum_public_ads(asset, currency, providers) ads_list = self.enum_public_ads(asset, currency, providers)
if not ads_list:
continue
ads = self.lookup_rates(ads_list, rates=rates) ads = self.lookup_rates(ads_list, rates=rates)
if not ads: if not ads:
continue continue
@ -469,6 +472,7 @@ class Agora(object):
public_ads[currency].append(ad) public_ads[currency].append(ad)
else: else:
public_ads[currency] = ads public_ads[currency] = ads
return public_ads return public_ads
def slow_ad_update(self, ads): def slow_ad_update(self, ads):
@ -486,7 +490,6 @@ class Agora(object):
ad_id, new_formula, asset, currency, actioned = ads[ad_index] ad_id, new_formula, asset, currency, actioned = ads[ad_index]
assets.add(asset) assets.add(asset)
currencies.add(currency) currencies.add(currency)
self.log.error("ASSET {a}", a=asset)
if not actioned: if not actioned:
rtrn = self.agora.ad_equation(ad_id, new_formula) rtrn = self.agora.ad_equation(ad_id, new_formula)
if rtrn["success"]: if rtrn["success"]:
@ -732,7 +735,7 @@ class Agora(object):
@handle_exceptions @handle_exceptions
def withdraw_funds(self): 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() totals_all = self.tx.get_total()
if totals_all is False: if totals_all is False:
@ -742,9 +745,11 @@ class Agora(object):
# Get the wallet balances in USD # Get the wallet balances in USD
total_usd = totals_all[0][1] 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) profit_usd = total_usd - float(settings.Money.BaseUSD)
# Get the XMR -> USD exchange rate # Get the XMR -> USD exchange rate
xmr_usd = self.cg.get_price(ids="monero", vs_currencies=["USD"]) xmr_usd = self.cg.get_price(ids="monero", vs_currencies=["USD"])

View File

@ -29,7 +29,7 @@ class IRCCommands(object):
class create(object): class create(object):
name = "create" name = "create"
authed = True authed = True
helptext = "Create an ad. Usage: create <XMR/BTC> <country> <currency>" helptext = "Create an ad. Usage: create <XMR/BTC> <country> <currency> [<provider>]"
@staticmethod @staticmethod
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify): 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']}") msg(f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}")
else: else:
msg(dumps(posted["response"])) 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): class messages(object):
name = "messages" name = "messages"
@ -331,7 +343,10 @@ class IRCCommands(object):
msg(f"Not a valid asset: {spl[1]}") msg(f"Not a valid asset: {spl[1]}")
return return
currency = spl[2] 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]: for ad in rtrn[currency]:
msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]} {ad[4]} {ad[5]} {ad[6]}") msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]} {ad[4]} {ad[5]} {ad[6]}")
elif length == 4: elif length == 4:
@ -341,7 +356,10 @@ class IRCCommands(object):
return return
providers = spl[3].split(",") providers = spl[3].split(",")
currency = spl[2] 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]: for ad in rtrn[currency]:
msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]} {ad[4]} {ad[5]} {ad[6]}") msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]} {ad[4]} {ad[5]} {ad[6]}")