|
|
@ -175,42 +175,6 @@ class Agora(object):
|
|
|
|
current_trades.append(reference)
|
|
|
|
current_trades.append(reference)
|
|
|
|
self.tx.cleanup(current_trades)
|
|
|
|
self.tx.cleanup(current_trades)
|
|
|
|
|
|
|
|
|
|
|
|
@handle_exceptions
|
|
|
|
|
|
|
|
def dashboard_release_urls(self):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Get information about our open trades.
|
|
|
|
|
|
|
|
Post new trades to IRC and cache trades for the future.
|
|
|
|
|
|
|
|
:return: human readable list of strings about our trades or False
|
|
|
|
|
|
|
|
:rtype: list or bool
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
dash = self.agora.dashboard_seller()
|
|
|
|
|
|
|
|
if dash is False:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
dash_tmp = []
|
|
|
|
|
|
|
|
if "data" not in dash["response"]:
|
|
|
|
|
|
|
|
self.log.error("Data not in dashboard response: {content}", content=dash)
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
if dash["response"]["data"]["contact_count"] > 0:
|
|
|
|
|
|
|
|
for contact in dash["response"]["data"]["contact_list"]:
|
|
|
|
|
|
|
|
contact_id = contact["data"]["contact_id"]
|
|
|
|
|
|
|
|
buyer = contact["data"]["buyer"]["username"]
|
|
|
|
|
|
|
|
amount = contact["data"]["amount"]
|
|
|
|
|
|
|
|
asset = contact["data"]["advertisement"]["asset"]
|
|
|
|
|
|
|
|
if asset == "XMR":
|
|
|
|
|
|
|
|
amount_crypto = contact["data"]["amount_xmr"]
|
|
|
|
|
|
|
|
elif asset == "BTC":
|
|
|
|
|
|
|
|
amount_crypto = contact["data"]["amount_btc"]
|
|
|
|
|
|
|
|
currency = contact["data"]["currency"]
|
|
|
|
|
|
|
|
release_url = contact["actions"]["release_url"]
|
|
|
|
|
|
|
|
if not contact["data"]["is_selling"]:
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
reference = self.tx.tx_to_ref(contact_id)
|
|
|
|
|
|
|
|
if not reference:
|
|
|
|
|
|
|
|
reference = "not_set"
|
|
|
|
|
|
|
|
dash_tmp.append(f"{reference}: {buyer} {amount}{currency} {amount_crypto}{asset} {release_url}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return dash_tmp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_exceptions
|
|
|
|
@handle_exceptions
|
|
|
|
def get_recent_messages(self, send_irc=True):
|
|
|
|
def get_recent_messages(self, send_irc=True):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -310,6 +274,7 @@ class Agora(object):
|
|
|
|
ads_total.append([ad[0], ad[1], ad[2], ad[3], ad[4]])
|
|
|
|
ads_total.append([ad[0], ad[1], ad[2], ad[3], ad[4]])
|
|
|
|
return ads_total
|
|
|
|
return ads_total
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: move to utils library
|
|
|
|
def last_online_recent(self, date):
|
|
|
|
def last_online_recent(self, date):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Check if the last online date was recent.
|
|
|
|
Check if the last online date was recent.
|
|
|
@ -381,6 +346,7 @@ class Agora(object):
|
|
|
|
to_return.append(to_append)
|
|
|
|
to_return.append(to_append)
|
|
|
|
return to_return
|
|
|
|
return to_return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: move to money library
|
|
|
|
def lookup_rates(self, ads, rates=None):
|
|
|
|
def lookup_rates(self, ads, rates=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Lookup the rates for a list of public ads.
|
|
|
|
Lookup the rates for a list of public ads.
|
|
|
@ -430,6 +396,7 @@ class Agora(object):
|
|
|
|
to_update = self.markets.get_new_ad_equations(public_ads, assets)
|
|
|
|
to_update = self.markets.get_new_ad_equations(public_ads, assets)
|
|
|
|
self.slow_ad_update(to_update)
|
|
|
|
self.slow_ad_update(to_update)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: make generic and move to markets
|
|
|
|
@handle_exceptions
|
|
|
|
@handle_exceptions
|
|
|
|
def get_all_public_ads(self, assets=None, currencies=None, providers=None):
|
|
|
|
def get_all_public_ads(self, assets=None, currencies=None, providers=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -480,7 +447,6 @@ class Agora(object):
|
|
|
|
Slow ad equation update utilising exponential backoff in order to guarantee all ads are updated.
|
|
|
|
Slow ad equation update utilising exponential backoff in order to guarantee all ads are updated.
|
|
|
|
:param ads: our list of ads
|
|
|
|
:param ads: our list of ads
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
# self.log.info("Beginning slow ad update for {num} ads", num=len(ads))
|
|
|
|
|
|
|
|
iterations = 0
|
|
|
|
iterations = 0
|
|
|
|
throttled = 0
|
|
|
|
throttled = 0
|
|
|
|
assets = set()
|
|
|
|
assets = set()
|
|
|
@ -495,7 +461,6 @@ class Agora(object):
|
|
|
|
if rtrn["success"]:
|
|
|
|
if rtrn["success"]:
|
|
|
|
ads[ad_index][4] = True
|
|
|
|
ads[ad_index][4] = True
|
|
|
|
throttled = 0
|
|
|
|
throttled = 0
|
|
|
|
# self.log.info("Successfully updated ad: {id}", id=ad_id)
|
|
|
|
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if "error_code" not in rtrn["response"]["error"]:
|
|
|
|
if "error_code" not in rtrn["response"]["error"]:
|
|
|
@ -515,17 +480,6 @@ class Agora(object):
|
|
|
|
self.log.error("Error updating ad {ad_id}: {response}", ad_id=ad_id, response=rtrn["response"])
|
|
|
|
self.log.error("Error updating ad {ad_id}: {response}", ad_id=ad_id, response=rtrn["response"])
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
iterations += 1
|
|
|
|
iterations += 1
|
|
|
|
# if iterations == 0:
|
|
|
|
|
|
|
|
# self.log.info("Slow ad update finished, no ads to update")
|
|
|
|
|
|
|
|
# self.irc.sendmsg("Slow ad update finished, no ads to update")
|
|
|
|
|
|
|
|
# else:
|
|
|
|
|
|
|
|
# self.log.info(
|
|
|
|
|
|
|
|
# "Slow ad update completed with {iterations} iterations: [{assets}] | [{currencies}]",
|
|
|
|
|
|
|
|
# iterations=iterations,
|
|
|
|
|
|
|
|
# assets=", ".join(assets),
|
|
|
|
|
|
|
|
# currencies=", ".join(currencies),
|
|
|
|
|
|
|
|
# )
|
|
|
|
|
|
|
|
# self.irc.sendmsg(f"Slow ad update completed with {iterations} iterations: [{', '.join(assets)}] | [{', '.join(currencies)}]")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_exceptions
|
|
|
|
@handle_exceptions
|
|
|
|
def nuke_ads(self):
|
|
|
|
def nuke_ads(self):
|
|
|
@ -543,6 +497,7 @@ class Agora(object):
|
|
|
|
return_ids.append(rtrn["success"])
|
|
|
|
return_ids.append(rtrn["success"])
|
|
|
|
return all(return_ids)
|
|
|
|
return all(return_ids)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: move to money
|
|
|
|
def get_rates_all(self):
|
|
|
|
def get_rates_all(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Get all rates that pair with USD.
|
|
|
|
Get all rates that pair with USD.
|
|
|
@ -552,6 +507,7 @@ class Agora(object):
|
|
|
|
rates = self.cr.get_rates("USD")
|
|
|
|
rates = self.cr.get_rates("USD")
|
|
|
|
return rates
|
|
|
|
return rates
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: move to money
|
|
|
|
def get_acceptable_margins(self, currency, amount):
|
|
|
|
def get_acceptable_margins(self, currency, amount):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Get the minimum and maximum amounts we would accept a trade for.
|
|
|
|
Get the minimum and maximum amounts we would accept a trade for.
|
|
|
@ -615,11 +571,8 @@ class Agora(object):
|
|
|
|
min_amount = rates[currency] * min_usd
|
|
|
|
min_amount = rates[currency] * min_usd
|
|
|
|
max_amount = rates[currency] * max_usd
|
|
|
|
max_amount = rates[currency] * max_usd
|
|
|
|
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}"
|
|
|
|
# price_formula = f"coingeckoxmrusd*{settings.Agora.Margin}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Remove extra tabs
|
|
|
|
# Remove extra tabs
|
|
|
|
ad = ad.replace("\\t", "\t")
|
|
|
|
ad = ad.replace("\\t", "\t")
|
|
|
|
|
|
|
|
|
|
|
|
form = {
|
|
|
|
form = {
|
|
|
|
"country_code": countrycode,
|
|
|
|
"country_code": countrycode,
|
|
|
|
"currency": currency,
|
|
|
|
"currency": currency,
|
|
|
@ -635,10 +588,6 @@ class Agora(object):
|
|
|
|
"payment_method_details": settings.Agora.PaymentMethodDetails,
|
|
|
|
"payment_method_details": settings.Agora.PaymentMethodDetails,
|
|
|
|
"account_info": paymentdetailstext,
|
|
|
|
"account_info": paymentdetailstext,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Dirty hack to test
|
|
|
|
|
|
|
|
# if asset == "BTC":
|
|
|
|
|
|
|
|
# del form["min_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:
|
|
|
@ -817,6 +766,7 @@ class Agora(object):
|
|
|
|
self.irc.sendmsg(f"Withdrawal: {rtrn1['success']} | {rtrn2['success']}")
|
|
|
|
self.irc.sendmsg(f"Withdrawal: {rtrn1['success']} | {rtrn2['success']}")
|
|
|
|
self.notify.notify_withdrawal(half_rounded)
|
|
|
|
self.notify.notify_withdrawal(half_rounded)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: move to money
|
|
|
|
def to_usd(self, amount, currency):
|
|
|
|
def to_usd(self, amount, currency):
|
|
|
|
if currency == "USD":
|
|
|
|
if currency == "USD":
|
|
|
|
return float(amount)
|
|
|
|
return float(amount)
|
|
|
|