Libraries refactor and add some sinks #4

Closed
m wants to merge 136 commits from library-refactor into master
2 changed files with 32 additions and 3 deletions
Showing only changes of commit 2740c1d9f9 - Show all commits

View File

@ -386,8 +386,6 @@ class Agora(object):
if not rates:
rates = self.cg.get_price(ids=["monero", "bitcoin"], vs_currencies=self.markets.get_all_currencies())
# Set the price based on the asset
else:
base_currency_price = rates
for ad in ads:
if ad[4] == "XMR":
coin = "monero"
@ -396,7 +394,7 @@ class Agora(object):
currency = ad[5]
base_currency_price = rates[coin][currency.lower()]
price = float(ad[2])
rate = round(price / base_currency_price, 4)
rate = round(price / base_currency_price, 2)
ad.append(rate)
return sorted(ads, key=lambda x: x[2])
@ -498,6 +496,9 @@ class Agora(object):
# self.log.info("Successfully updated ad: {id}", id=ad_id)
continue
else:
if "error_code" not in rtrn["response"]["error"]:
self.log.error("Error code not in return for ad {ad_id}: {response}", ad_id=ad_id, response=rtrn["response"])
return
if rtrn["response"]["error"]["error_code"] == 429:
throttled += 1
sleep_time = pow(throttled, float(settings.Agora.SleepExponent))

View File

@ -193,3 +193,31 @@ class TestAgora(TestCase):
lookup_rates_return = self.agora.lookup_rates(enum_ads_return)
self.assertCountEqual(lookup_rates_return, expected_return)
def test_lookup_rates_not_usd(self):
"""
Above test only tests USD which does not take into account Forex.
Let's test both, and additionaly specify our own rates.
"""
# Override enum_public_ads
self.agora.agora._api_call = self.mock_enum_public_ads_api_call
self.agora.last_online_recent = MagicMock()
self.agora.last_online_recent.return_value = True
# Override get_price
self.agora.cg.get_price = MagicMock()
self.agora.cg.get_price.return_value = cg_prices
enum_ads_return = self.agora.enum_public_ads("XMR", "EUR", self.all_providers)
expected_return = []
# Let's manually calculate what it's supposed to look like
price_xmr = cg_prices["monero"]["eur"]
for ad in deepcopy(enum_ads_return):
price = float(ad[2])
margin = round(price / price_xmr, 2)
ad.append(margin)
expected_return.append(ad)
# Test specifying rates=
lookup_rates_return = self.agora.lookup_rates(enum_ads_return, rates=cg_prices)
self.assertCountEqual(lookup_rates_return, expected_return)