Move create_distribution_list to Markets library

This commit is contained in:
Mark Veidemanis 2022-02-22 20:15:42 +00:00
parent d535852ce6
commit d8c3d32bf7
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
3 changed files with 19 additions and 19 deletions

View File

@ -508,23 +508,6 @@ class Agora(object):
ad = self.agora.ad_create(**form) ad = self.agora.ad_create(**form)
return ad 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): def dist_countries(self, filter_asset=None):
""" """
Distribute our advert into all countries and providers listed in the config. 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 :return: False or dict with response
:rtype: bool or dict :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() our_ads = self.enum_ads()
# Let's get rid of the ad IDs and make it a tuple like dist_list # 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] our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads]

View File

@ -154,3 +154,19 @@ class Markets(object):
return float(settings.Agora.MaxMargin) return float(settings.Agora.MaxMargin)
# self.log.debug("Cheapest ad above our min that is not us: {x}", x=cheapest_ad) # self.log.debug("Cheapest ad above our min that is not us: {x}", x=cheapest_ad)
return cheapest_ad_margin 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)

View File

@ -3,7 +3,7 @@ from twisted.logger import Logger
# Other library imports # Other library imports
from pycoingecko import CoinGeckoAPI from pycoingecko import CoinGeckoAPI
from forex_python.converter import CurrencyRates
# Project imports # Project imports
from settings import settings from settings import settings
@ -21,6 +21,7 @@ class Money(object):
Initialise the CoinGecko API. Initialise the CoinGecko API.
""" """
self.log = Logger("money") self.log = Logger("money")
self.cr = CurrencyRates()
self.cg = CoinGeckoAPI() self.cg = CoinGeckoAPI()
def lookup_rates(self, ads, rates=None): def lookup_rates(self, ads, rates=None):