|
|
@ -454,36 +454,49 @@ class Agora(util.Base):
|
|
|
|
return_ids.append(rtrn["success"])
|
|
|
|
return_ids.append(rtrn["success"])
|
|
|
|
return all(return_ids)
|
|
|
|
return all(return_ids)
|
|
|
|
|
|
|
|
|
|
|
|
@util.handle_exceptions
|
|
|
|
def format_ad(self, asset, currency, payment_details_text):
|
|
|
|
def create_ad(self, asset, countrycode, currency, provider, edit=False, ad_id=None):
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Post an ad with the given asset in a country with a given currency.
|
|
|
|
Format the ad.
|
|
|
|
Convert the min and max amounts from settings to the given currency with CurrencyRates.
|
|
|
|
|
|
|
|
:param asset: the crypto asset to list (XMR or BTC)
|
|
|
|
|
|
|
|
:type asset: string
|
|
|
|
|
|
|
|
:param countrycode: country code
|
|
|
|
|
|
|
|
:param currency: currency code
|
|
|
|
|
|
|
|
:type countrycode: string
|
|
|
|
|
|
|
|
:type currency: string
|
|
|
|
|
|
|
|
:return: data about created object or error
|
|
|
|
|
|
|
|
:rtype: dict
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
ad = settings.Agora.Ad
|
|
|
|
ad = settings.Agora.Ad
|
|
|
|
paymentdetails = settings.Agora.PaymentDetails
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Substitute the currency
|
|
|
|
# Substitute the currency
|
|
|
|
ad = ad.replace("$CURRENCY$", currency)
|
|
|
|
ad = ad.replace("$CURRENCY$", currency)
|
|
|
|
if currency == "GBP":
|
|
|
|
|
|
|
|
ad = ad.replace("$PAYMENT$", settings.Agora.GBPDetailsAd)
|
|
|
|
|
|
|
|
paymentdetailstext = paymentdetails.replace("$PAYMENT$", settings.Agora.GBPDetailsPayment)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
ad = ad.replace("$PAYMENT$", settings.Agora.DefaultDetailsAd)
|
|
|
|
|
|
|
|
paymentdetailstext = paymentdetails.replace("$PAYMENT$", settings.Agora.DefaultDetailsPayment)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Substitute the asset
|
|
|
|
# Substitute the asset
|
|
|
|
ad = ad.replace("$ASSET$", 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.Agora.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()
|
|
|
|
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":
|
|
|
|
if asset == "XMR":
|
|
|
|
min_usd = float(settings.Agora.MinUSDXMR)
|
|
|
|
min_usd = float(settings.Agora.MinUSDXMR)
|
|
|
|
max_usd = float(settings.Agora.MaxUSDXMR)
|
|
|
|
max_usd = float(settings.Agora.MaxUSDXMR)
|
|
|
@ -496,9 +509,33 @@ class Agora(util.Base):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
min_amount = rates[currency] * min_usd
|
|
|
|
min_amount = rates[currency] * min_usd
|
|
|
|
max_amount = rates[currency] * max_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=True, edit=False, ad_id=None):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Post an ad with the given asset in a country with a given currency.
|
|
|
|
|
|
|
|
Convert the min and max amounts from settings to the given currency with CurrencyRates.
|
|
|
|
|
|
|
|
:param asset: the crypto asset to list (XMR or BTC)
|
|
|
|
|
|
|
|
:type asset: string
|
|
|
|
|
|
|
|
:param countrycode: country code
|
|
|
|
|
|
|
|
:param currency: currency code
|
|
|
|
|
|
|
|
:param payment_details: the payment details
|
|
|
|
|
|
|
|
:type countrycode: string
|
|
|
|
|
|
|
|
:type currency: string
|
|
|
|
|
|
|
|
:type payment_details: dict
|
|
|
|
|
|
|
|
:return: data about created object or error
|
|
|
|
|
|
|
|
:rtype: dict
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
price_formula = f"coingecko{asset.lower()}usd*usd{currency.lower()}*{settings.Agora.Margin}"
|
|
|
|
price_formula = f"coingecko{asset.lower()}usd*usd{currency.lower()}*{settings.Agora.Margin}"
|
|
|
|
# Remove extra tabs
|
|
|
|
|
|
|
|
ad = ad.replace("\\t", "\t")
|
|
|
|
|
|
|
|
form = {
|
|
|
|
form = {
|
|
|
|
"country_code": countrycode,
|
|
|
|
"country_code": countrycode,
|
|
|
|
"currency": currency,
|
|
|
|
"currency": currency,
|
|
|
@ -508,12 +545,15 @@ class Agora(util.Base):
|
|
|
|
"track_max_amount": False,
|
|
|
|
"track_max_amount": False,
|
|
|
|
"require_trusted_by_advertiser": False,
|
|
|
|
"require_trusted_by_advertiser": False,
|
|
|
|
"online_provider": provider,
|
|
|
|
"online_provider": provider,
|
|
|
|
"msg": ad,
|
|
|
|
|
|
|
|
"min_amount": min_amount,
|
|
|
|
|
|
|
|
"max_amount": max_amount,
|
|
|
|
|
|
|
|
"payment_method_details": settings.Agora.PaymentMethodDetails,
|
|
|
|
"payment_method_details": settings.Agora.PaymentMethodDetails,
|
|
|
|
"account_info": paymentdetailstext,
|
|
|
|
"visible": visible,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if payment_details:
|
|
|
|
|
|
|
|
form["account_info"] = payment_details_text
|
|
|
|
|
|
|
|
form["msg"] = ad_text
|
|
|
|
|
|
|
|
form["min_amount"] = min_amount
|
|
|
|
|
|
|
|
form["max_amount"] = max_amount
|
|
|
|
|
|
|
|
|
|
|
|
if edit:
|
|
|
|
if edit:
|
|
|
|
ad = self.agora.ad(ad_id=ad_id, **form)
|
|
|
|
ad = self.agora.ad(ad_id=ad_id, **form)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|