Move some Agora functions to money/markets
This commit is contained in:
@@ -450,64 +450,6 @@ class Agora(util.Base):
|
||||
return_ids.append(rtrn["success"])
|
||||
return all(return_ids)
|
||||
|
||||
def format_ad(self, asset, currency, payment_details_text):
|
||||
"""
|
||||
Format the ad.
|
||||
"""
|
||||
ad = settings.Platform.Ad
|
||||
|
||||
# Substitute the currency
|
||||
ad = ad.replace("$CURRENCY$", currency)
|
||||
|
||||
# Substitute the asset
|
||||
ad = ad.replace("$ASSET$", asset)
|
||||
|
||||
# Substitute the payment details
|
||||
ad = ad.replace("$PAYMENT$", payment_details_text)
|
||||
|
||||
# Strip extra tabs
|
||||
ad = ad.replace("\\t", "\t")
|
||||
return ad
|
||||
|
||||
def format_payment_details(self, currency, payment_details):
|
||||
"""
|
||||
Format the payment details.
|
||||
"""
|
||||
payment = settings.Platform.PaymentDetails
|
||||
|
||||
payment_text = ""
|
||||
for field, value in payment_details.items():
|
||||
formatted_name = field.replace("_", " ")
|
||||
formatted_name = formatted_name.capitalize()
|
||||
payment_text += f"* {formatted_name}: **{value}**"
|
||||
if field != list(payment_details.keys())[-1]: # No trailing newline
|
||||
payment_text += "\n"
|
||||
|
||||
payment = payment.replace("$PAYMENT$", payment_text)
|
||||
payment = payment.replace("$CURRENCY$", currency)
|
||||
|
||||
return payment
|
||||
|
||||
def get_minmax(self, asset, currency):
|
||||
rates = self.money.get_rates_all()
|
||||
if currency not in rates and not currency == "USD":
|
||||
self.log.error(f"Can't create ad without rates: {currency}")
|
||||
return
|
||||
if asset == "XMR":
|
||||
min_usd = float(settings.Agora.MinUSDXMR)
|
||||
max_usd = float(settings.Agora.MaxUSDXMR)
|
||||
elif asset == "BTC":
|
||||
min_usd = float(settings.Agora.MinUSDBTC)
|
||||
max_usd = float(settings.Agora.MaxUSDBTC)
|
||||
if currency == "USD":
|
||||
min_amount = min_usd
|
||||
max_amount = max_usd
|
||||
else:
|
||||
min_amount = rates[currency] * min_usd
|
||||
max_amount = rates[currency] * max_usd
|
||||
|
||||
return (min_amount, max_amount)
|
||||
|
||||
@util.handle_exceptions
|
||||
def create_ad(self, asset, countrycode, currency, provider, payment_details, visible=None, edit=False, ad_id=None):
|
||||
"""
|
||||
@@ -526,9 +468,9 @@ class Agora(util.Base):
|
||||
"""
|
||||
|
||||
if payment_details:
|
||||
payment_details_text = self.format_payment_details(currency, payment_details)
|
||||
ad_text = self.format_ad(asset, currency, payment_details_text)
|
||||
min_amount, max_amount = self.get_minmax(asset, currency)
|
||||
payment_details_text = self.markets.format_payment_details(currency, payment_details)
|
||||
ad_text = self.markets.format_ad(asset, currency, payment_details_text)
|
||||
min_amount, max_amount = self.money.get_minmax(asset, currency)
|
||||
|
||||
price_formula = f"coingecko{asset.lower()}usd*usd{currency.lower()}*{settings.Agora.Margin}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user