Handle LBTC in autoprice
This commit is contained in:
parent
7cfeb95b10
commit
f39e6112e4
|
@ -42,8 +42,12 @@ class Markets(util.Base):
|
||||||
"""
|
"""
|
||||||
if platform == "agora":
|
if platform == "agora":
|
||||||
username = settings.Agora.Username
|
username = settings.Agora.Username
|
||||||
|
min_margin = settings.Agora.MinMargin
|
||||||
|
max_margin = settings.Agora.MaxMargin
|
||||||
elif platform == "lbtc":
|
elif platform == "lbtc":
|
||||||
username = settings.LocalBitcoins.Username
|
username = settings.LocalBitcoins.Username
|
||||||
|
min_margin = settings.LocalBitcoins.MinMargin
|
||||||
|
max_margin = settings.LocalBitcoins.MaxMargin
|
||||||
to_update = []
|
to_update = []
|
||||||
|
|
||||||
# NOTES:
|
# NOTES:
|
||||||
|
@ -78,7 +82,7 @@ class Markets(util.Base):
|
||||||
our_ads = [ad for ad in public_ads_filtered if ad[1] == username]
|
our_ads = [ad for ad in public_ads_filtered if ad[1] == username]
|
||||||
if not our_ads:
|
if not our_ads:
|
||||||
continue
|
continue
|
||||||
new_margin = self.autoprice(public_ads_filtered, currency)
|
new_margin = self.autoprice(username, min_margin, max_margin, public_ads_filtered, currency)
|
||||||
# self.log.info("New rate for {currency}: {rate}", currency=currency, rate=new_margin)
|
# self.log.info("New rate for {currency}: {rate}", currency=currency, rate=new_margin)
|
||||||
new_formula = f"coingecko{asset.lower()}usd*usd{currency.lower()}*{new_margin}"
|
new_formula = f"coingecko{asset.lower()}usd*usd{currency.lower()}*{new_margin}"
|
||||||
for ad in our_ads:
|
for ad in our_ads:
|
||||||
|
@ -90,7 +94,7 @@ class Markets(util.Base):
|
||||||
|
|
||||||
return to_update
|
return to_update
|
||||||
|
|
||||||
def autoprice(self, ads, currency):
|
def autoprice(self, username, min_margin, max_margin, ads, currency):
|
||||||
"""
|
"""
|
||||||
Helper function to automatically adjust the price up/down in certain markets
|
Helper function to automatically adjust the price up/down in certain markets
|
||||||
in order to gain the most profits and sales.
|
in order to gain the most profits and sales.
|
||||||
|
@ -109,10 +113,10 @@ class Markets(util.Base):
|
||||||
|
|
||||||
# Find second cheapest that is not us
|
# Find second cheapest that is not us
|
||||||
# Remove results from ads that are us
|
# Remove results from ads that are us
|
||||||
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] == 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[6] > float(settings.Agora.MinMargin)]
|
ads_above_our_min_not_us = [ad for ad in ads_without_us if ad[6] > float(min_margin)]
|
||||||
# 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:
|
||||||
|
@ -124,26 +128,26 @@ class Markets(util.Base):
|
||||||
# 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
|
||||||
if min_margin_ad[1] == settings.Agora.Username:
|
if min_margin_ad[1] == username:
|
||||||
# self.log.debug("We are the cheapest for: {x}", x=currency)
|
# self.log.debug("We are the cheapest for: {x}", x=currency)
|
||||||
# We are the cheapest!
|
# We are the cheapest!
|
||||||
# Are all of the ads ours?
|
# Are all of the ads ours?
|
||||||
all_ads_ours = all([ad[1] == settings.Agora.Username for ad in ads])
|
all_ads_ours = all([ad[1] == username for ad in ads])
|
||||||
if all_ads_ours:
|
if all_ads_ours:
|
||||||
# self.log.debug("All ads are ours for: {x}", x=currency)
|
# self.log.debug("All ads are ours for: {x}", x=currency)
|
||||||
# Now we know it's safe to return the maximum value
|
# Now we know it's safe to return the maximum value
|
||||||
return float(settings.Agora.MaxMargin)
|
return float(max_margin)
|
||||||
else:
|
else:
|
||||||
# self.log.debug("All ads are NOT ours for: {x}", x=currency)
|
# self.log.debug("All ads are NOT ours for: {x}", x=currency)
|
||||||
# All the ads are not ours, but we are first...
|
# All the ads are not ours, but we are first...
|
||||||
# Check if the lowballed, lowest (that is not ours) ad's margin
|
# Check if the lowballed, lowest (that is not ours) ad's margin
|
||||||
# is less than our minimum
|
# is less than our minimum
|
||||||
if lowball_lowest_not_ours < float(settings.Agora.MinMargin):
|
if lowball_lowest_not_ours < float(min_margin):
|
||||||
# self.log.debug("Lowball lowest not ours less than MinMargin")
|
# self.log.debug("Lowball lowest not ours less than MinMargin")
|
||||||
return float(settings.Agora.MinMargin)
|
return float(min_margin)
|
||||||
elif lowball_lowest_not_ours > float(settings.Agora.MaxMargin):
|
elif lowball_lowest_not_ours > float(max_margin):
|
||||||
# self.log.debug("Lowball lowest not ours more than MaxMargin")
|
# self.log.debug("Lowball lowest not ours more than MaxMargin")
|
||||||
return float(settings.Agora.MaxMargin)
|
return float(max_margin)
|
||||||
else:
|
else:
|
||||||
# self.log.debug("Returning lowballed figure: {x}", x=lowball_lowest_not_ours)
|
# self.log.debug("Returning lowballed figure: {x}", x=lowball_lowest_not_ours)
|
||||||
return lowball_lowest_not_ours
|
return lowball_lowest_not_ours
|
||||||
|
@ -153,13 +157,13 @@ class Markets(util.Base):
|
||||||
# Check if this list is empty
|
# Check if this list is empty
|
||||||
if not ads_above_our_min_not_us:
|
if not ads_above_our_min_not_us:
|
||||||
# Return the maximum margin?
|
# Return the maximum margin?
|
||||||
return float(settings.Agora.MaxMargin)
|
return float(max_margin)
|
||||||
# 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[4])
|
cheapest_ad = min(ads_above_our_min_not_us, key=lambda x: x[4])
|
||||||
cheapest_ad_margin = cheapest_ad[6] # - 0.005
|
cheapest_ad_margin = cheapest_ad[6] # - 0.005
|
||||||
if cheapest_ad_margin > float(settings.Agora.MaxMargin):
|
if cheapest_ad_margin > float(max_margin):
|
||||||
# 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(max_margin)
|
||||||
# self.log.debug("Cheapest ad above our min that is not us: {x}", x=cheapest_ad)
|
# self.log.debug("Cheapest ad above our min that is not us: {x}", x=cheapest_ad)
|
||||||
return cheapest_ad_margin
|
return cheapest_ad_margin
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ class TestMarkets(TestCase):
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
currency = "EUR"
|
currency = "EUR"
|
||||||
margin = self.markets.autoprice(ads, currency)
|
margin = self.markets.autoprice("topmonero", 1.1, 1.3, ads, currency)
|
||||||
expected_margin = 1.18
|
expected_margin = 1.18
|
||||||
self.assertEqual(margin, expected_margin)
|
self.assertEqual(margin, expected_margin)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue