Fix autoprice bugs and re-enable withdrawing on release

This commit is contained in:
Mark Veidemanis 2022-01-31 13:45:02 +00:00
parent cdc80b6896
commit c3ff7d6e76
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 10 additions and 9 deletions

View File

@ -386,7 +386,8 @@ class Agora(object):
coin = "monero"
elif asset == "BTC":
coin = "bitcoin"
ads = self.enum_public_ads(coin, currency.upper(), providers)
ads_obj = self.enum_public_ads(coin, currency.upper(), providers)
ads = list(ads_obj)
if ads is False:
return False
# ads = list(ads_obj)
@ -459,7 +460,7 @@ class Agora(object):
except KeyError:
self.log.error("Error getting public ads for currency {currency}", currency=currency)
continue
for asset, ad_id, country, currency in our_ads:
for asset, ad_id, country, currency, provider in our_ads:
# Get the ads for this country/currency pair
try:
if asset == "XMR":
@ -567,7 +568,7 @@ class Agora(object):
self.log.debug("Autoprice starting for {x}", x=currency)
# Find cheapest ad
# Filter by 3rd index on each ad list to find the cheapest
min_margin_ad = min(ads, key=lambda x: x[3])
min_margin_ad = min(ads, key=lambda x: x[4])
self.log.debug("Minimum margin ad: {x}", x=min_margin_ad)
# Find second cheapest that is not us
@ -575,15 +576,15 @@ class Agora(object):
ads_without_us = [ad for ad in ads if not ad[1] == settings.Agora.Username]
self.log.debug("Ads without us: {x}", x=ads_without_us)
# Find ads above our min that are not us
ads_above_our_min_not_us = [ad for ad in ads_without_us if ad[3] > float(settings.Agora.MinMargin)]
ads_above_our_min_not_us = [ad for ad in ads_without_us if ad[4] > float(settings.Agora.MinMargin)]
self.log.debug("Ads above our min not us: {x}", x=ads_above_our_min_not_us)
# Check that this list without us is not empty
if ads_without_us:
# Find the cheapest from these
min_margin_ad_not_us = min(ads_without_us, key=lambda x: x[3])
min_margin_ad_not_us = min(ads_without_us, key=lambda x: x[4])
self.log.debug("Min margin ad not us: {x}", x=min_margin_ad_not_us)
# Lowball the lowest ad that is not ours
lowball_lowest_not_ours = min_margin_ad_not_us[3] # - 0.005
lowball_lowest_not_ours = min_margin_ad_not_us[4] # - 0.005
self.log.debug("Lowball lowest not ours: {x}", x=lowball_lowest_not_ours)
# Check if the username field of the cheapest ad matches ours
@ -618,8 +619,8 @@ class Agora(object):
# Return the maximum margin?
return float(settings.Agora.MaxMargin)
# Find cheapest ad above our min that is not us
cheapest_ad = min(ads_above_our_min_not_us, key=lambda x: x[3])
cheapest_ad_margin = cheapest_ad[3] # - 0.005
cheapest_ad = min(ads_above_our_min_not_us, key=lambda x: x[4])
cheapest_ad_margin = cheapest_ad[4] # - 0.005
if cheapest_ad_margin > float(settings.Agora.MaxMargin):
self.log.debug("Cheapest ad not ours more than MaxMargin")
return float(settings.Agora.MaxMargin)
@ -790,7 +791,7 @@ class Agora(object):
rtrn = self.agora._api_call(api_method=f"contact_release/{contact_id}", http_method="POST", query_values=payload)
# Check if we can withdraw funds
# self.withdraw_funds()
self.withdraw_funds()
return rtrn