Don't make unnecessary calls to update ad equations
This commit is contained in:
parent
b60ae03699
commit
965bba8d15
|
@ -355,10 +355,27 @@ class Agora(object):
|
||||||
if asset == "BTC":
|
if asset == "BTC":
|
||||||
new_margin = self.autoprice(public_ads, currency)
|
new_margin = self.autoprice(public_ads, currency)
|
||||||
new_formula = f"coingeckobtcusd*usd{currency.lower()}*{new_margin}"
|
new_formula = f"coingeckobtcusd*usd{currency.lower()}*{new_margin}"
|
||||||
rtrn = self.agora.ad_equation(ad_id, new_formula)
|
# Get all of our ads
|
||||||
if not rtrn["success"]:
|
our_ads_list = [ad for ad in public_ads if ad[1] == settings.Agora.Username]
|
||||||
self.log.error("Error updating ad {ad_id}: {response}", ad_id=ad_id, response=rtrn["response"])
|
if not len(our_ads_list) == 1:
|
||||||
self.log.info("Rate for {currency}: {margin}", currency=currency, margin=new_margin)
|
self.log.error("More ads than expected: {ads}", ads=our_ads_list)
|
||||||
|
# Get one from the list, they're probably the same, if not we will deal with the other
|
||||||
|
# ones in a later pass
|
||||||
|
|
||||||
|
# Get one
|
||||||
|
our_ad = our_ads_list.pop()
|
||||||
|
|
||||||
|
# Take the 4th argument, the margin
|
||||||
|
our_margin = our_ad[3]
|
||||||
|
|
||||||
|
# Don't waste API rate limits on setting the same margin as before
|
||||||
|
if new_margin != our_margin:
|
||||||
|
rtrn = self.agora.ad_equation(ad_id, new_formula)
|
||||||
|
if not rtrn["success"]:
|
||||||
|
self.log.error("Error updating ad {ad_id}: {response}", ad_id=ad_id, response=rtrn["response"])
|
||||||
|
self.log.info("Rate for {currency}: {margin}", currency=currency, margin=new_margin)
|
||||||
|
else:
|
||||||
|
self.log.info("Not changed rate for {currency}, keeping old margin of {margin}", currency=currency, margin=our_margin)
|
||||||
|
|
||||||
def autoprice(self, ads, currency):
|
def autoprice(self, ads, currency):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue