From e8a6f55ed15879738e8b0b893d8404573e860bd2 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 22 Feb 2022 20:15:42 +0000 Subject: [PATCH] Move create_distribution_list to Markets library --- handler/agora.py | 19 +------------------ handler/markets.py | 16 ++++++++++++++++ handler/money.py | 3 ++- 3 files changed, 19 insertions(+), 19 deletions(-) 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):