Libraries refactor and add some sinks #4
|
@ -386,7 +386,8 @@ class Agora(object):
|
||||||
coin = "monero"
|
coin = "monero"
|
||||||
elif asset == "BTC":
|
elif asset == "BTC":
|
||||||
coin = "bitcoin"
|
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:
|
if ads is False:
|
||||||
return False
|
return False
|
||||||
# ads = list(ads_obj)
|
# ads = list(ads_obj)
|
||||||
|
@ -459,7 +460,7 @@ class Agora(object):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
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
|
||||||
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
|
# Get the ads for this country/currency pair
|
||||||
try:
|
try:
|
||||||
if asset == "XMR":
|
if asset == "XMR":
|
||||||
|
@ -567,7 +568,7 @@ class Agora(object):
|
||||||
self.log.debug("Autoprice starting for {x}", x=currency)
|
self.log.debug("Autoprice starting for {x}", x=currency)
|
||||||
# Find cheapest ad
|
# Find cheapest ad
|
||||||
# Filter by 3rd index on each ad list to find the cheapest
|
# 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)
|
self.log.debug("Minimum margin ad: {x}", x=min_margin_ad)
|
||||||
|
|
||||||
# Find second cheapest that is not us
|
# 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]
|
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)
|
self.log.debug("Ads without us: {x}", x=ads_without_us)
|
||||||
# Find ads above our min that are not 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)
|
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
|
# Check that this list without us is not empty
|
||||||
if ads_without_us:
|
if ads_without_us:
|
||||||
# Find the cheapest from these
|
# 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)
|
self.log.debug("Min margin ad not us: {x}", x=min_margin_ad_not_us)
|
||||||
# Lowball the lowest ad that is not ours
|
# 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)
|
self.log.debug("Lowball lowest not ours: {x}", x=lowball_lowest_not_ours)
|
||||||
|
|
||||||
# Check if the username field of the cheapest ad matches ours
|
# Check if the username field of the cheapest ad matches ours
|
||||||
|
@ -618,8 +619,8 @@ class Agora(object):
|
||||||
# Return the maximum margin?
|
# Return the maximum margin?
|
||||||
return float(settings.Agora.MaxMargin)
|
return float(settings.Agora.MaxMargin)
|
||||||
# Find cheapest ad above our min that is not us
|
# 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 = min(ads_above_our_min_not_us, key=lambda x: x[4])
|
||||||
cheapest_ad_margin = cheapest_ad[3] # - 0.005
|
cheapest_ad_margin = cheapest_ad[4] # - 0.005
|
||||||
if cheapest_ad_margin > float(settings.Agora.MaxMargin):
|
if cheapest_ad_margin > float(settings.Agora.MaxMargin):
|
||||||
self.log.debug("Cheapest ad not ours more than MaxMargin")
|
self.log.debug("Cheapest ad not ours more than MaxMargin")
|
||||||
return float(settings.Agora.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)
|
rtrn = self.agora._api_call(api_method=f"contact_release/{contact_id}", http_method="POST", query_values=payload)
|
||||||
|
|
||||||
# Check if we can withdraw funds
|
# Check if we can withdraw funds
|
||||||
# self.withdraw_funds()
|
self.withdraw_funds()
|
||||||
|
|
||||||
return rtrn
|
return rtrn
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue