diff --git a/handler/agora.py b/handler/agora.py index 7e7b5c7..c65275c 100644 --- a/handler/agora.py +++ b/handler/agora.py @@ -508,23 +508,6 @@ class Agora(object): ad = self.agora.ad_create(**form) return ad - # TODO: move to markets - def create_distribution_list(self, filter_asset=None): - """ - Create a list for distribution of ads. - :return: generator of asset, countrycode, currency, provider - :rtype: generator of tuples - """ - # Iterate providers like REVOLUT, NATIONAL_BANK - for provider in loads(settings.Agora.ProviderList): - # Iterate assets like XMR, BTC - for asset in loads(settings.Agora.AssetList): - # Iterate pairs of currency and country like EUR, GB - for currency, countrycode in loads(settings.Agora.DistList): - if filter_asset: - if asset == filter_asset: - yield (asset, countrycode, currency, provider) - def dist_countries(self, filter_asset=None): """ Distribute our advert into all countries and providers listed in the config. @@ -532,7 +515,7 @@ class Agora(object): :return: False or dict with response :rtype: bool or dict """ - dist_list = list(self.create_distribution_list(filter_asset)) + dist_list = list(self.markets.create_distribution_list(filter_asset)) our_ads = self.enum_ads() # Let's get rid of the ad IDs and make it a tuple like dist_list our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads] diff --git a/handler/markets.py b/handler/markets.py index 4559c75..c1ab740 100644 --- a/handler/markets.py +++ b/handler/markets.py @@ -154,3 +154,19 @@ class Markets(object): return float(settings.Agora.MaxMargin) # self.log.debug("Cheapest ad above our min that is not us: {x}", x=cheapest_ad) return cheapest_ad_margin + + def create_distribution_list(self, filter_asset=None): + """ + Create a list for distribution of ads. + :return: generator of asset, countrycode, currency, provider + :rtype: generator of tuples + """ + # Iterate providers like REVOLUT, NATIONAL_BANK + for provider in loads(settings.Agora.ProviderList): + # Iterate assets like XMR, BTC + for asset in loads(settings.Agora.AssetList): + # Iterate pairs of currency and country like EUR, GB + for currency, countrycode in loads(settings.Agora.DistList): + if filter_asset: + if asset == filter_asset: + yield (asset, countrycode, currency, provider) diff --git a/handler/money.py b/handler/money.py index 7a8af45..5727a66 100644 --- a/handler/money.py +++ b/handler/money.py @@ -3,7 +3,7 @@ from twisted.logger import Logger # Other library imports from pycoingecko import CoinGeckoAPI - +from forex_python.converter import CurrencyRates # Project imports from settings import settings @@ -21,6 +21,7 @@ class Money(object): Initialise the CoinGecko API. """ self.log = Logger("money") + self.cr = CurrencyRates() self.cg = CoinGeckoAPI() def lookup_rates(self, ads, rates=None):