Libraries refactor and add some sinks #4

Closed
m wants to merge 136 commits from library-refactor into master
1 changed files with 21 additions and 4 deletions
Showing only changes of commit f871e8b93a - Show all commits

View File

@ -355,10 +355,27 @@ class Agora(object):
if asset == "BTC":
new_margin = self.autoprice(public_ads, currency)
new_formula = f"coingeckobtcusd*usd{currency.lower()}*{new_margin}"
# Get all of our ads
our_ads_list = [ad for ad in public_ads if ad[1] == settings.Agora.Username]
if not len(our_ads_list) == 1:
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):
"""