Account for LBTC in lookup_rates
This commit is contained in:
parent
f39e6112e4
commit
72ce2704a6
|
@ -11,25 +11,25 @@ class Markets(util.Base):
|
|||
Markets handler for generic market functions.
|
||||
"""
|
||||
|
||||
def get_all_assets(self, platform):
|
||||
def get_settings(self, platform):
|
||||
if platform == "agora":
|
||||
assets = loads(settings.Agora.AssetList)
|
||||
return settings.Agora
|
||||
elif platform == "lbtc":
|
||||
assets = loads(settings.LocalBitcoins.AssetList)
|
||||
return settings.LocalBitcoins
|
||||
|
||||
def get_all_assets(self, platform):
|
||||
sets = self.get_settings(platform)
|
||||
assets = loads(sets.AssetList)
|
||||
return assets
|
||||
|
||||
def get_all_providers(self, platform):
|
||||
if platform == "agora":
|
||||
providers = loads(settings.Agora.ProviderList)
|
||||
elif platform == "lbtc":
|
||||
providers = loads(settings.LocalBitcoins.ProviderList)
|
||||
sets = self.get_settings(platform)
|
||||
providers = loads(sets.ProviderList)
|
||||
return providers
|
||||
|
||||
def get_all_currencies(self, platform):
|
||||
if platform == "agora":
|
||||
currencies = list(set([x[0] for x in loads(settings.Agora.DistList)]))
|
||||
elif platform == "lbtc":
|
||||
currencies = list(set([x[0] for x in loads(settings.Agora.DistList)]))
|
||||
sets = self.get_settings(platform)
|
||||
currencies = list(set([x[0] for x in loads(sets.DistList)]))
|
||||
return currencies
|
||||
|
||||
def get_new_ad_equations(self, platform, public_ads, assets=None):
|
||||
|
@ -40,14 +40,11 @@ class Markets(util.Base):
|
|||
:return: list of ads to modify
|
||||
:rtype: list
|
||||
"""
|
||||
if platform == "agora":
|
||||
username = settings.Agora.Username
|
||||
min_margin = settings.Agora.MinMargin
|
||||
max_margin = settings.Agora.MaxMargin
|
||||
elif platform == "lbtc":
|
||||
username = settings.LocalBitcoins.Username
|
||||
min_margin = settings.LocalBitcoins.MinMargin
|
||||
max_margin = settings.LocalBitcoins.MaxMargin
|
||||
sets = self.get_settings(platform)
|
||||
username = sets.Username
|
||||
min_margin = sets.MinMargin
|
||||
max_margin = sets.MaxMargin
|
||||
|
||||
to_update = []
|
||||
|
||||
# NOTES:
|
||||
|
@ -167,18 +164,20 @@ class Markets(util.Base):
|
|||
# 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):
|
||||
def create_distribution_list(self, platform, filter_asset=None):
|
||||
"""
|
||||
Create a list for distribution of ads.
|
||||
:return: generator of asset, countrycode, currency, provider
|
||||
:rtype: generator of tuples
|
||||
"""
|
||||
sets = self.get_settings(platform)
|
||||
|
||||
# Iterate providers like REVOLUT, NATIONAL_BANK
|
||||
for provider in loads(settings.Agora.ProviderList):
|
||||
for provider in loads(sets.ProviderList):
|
||||
# Iterate assets like XMR, BTC
|
||||
for asset in loads(settings.Agora.AssetList):
|
||||
for asset in loads(sets.AssetList):
|
||||
# Iterate pairs of currency and country like EUR, GB
|
||||
for currency, countrycode in loads(settings.Agora.DistList):
|
||||
for currency, countrycode in loads(sets.DistList):
|
||||
if filter_asset:
|
||||
if asset == filter_asset:
|
||||
yield (asset, countrycode, currency, provider)
|
||||
|
|
|
@ -22,14 +22,14 @@ class Money(util.Base):
|
|||
self.cr = CurrencyRates()
|
||||
self.cg = CoinGeckoAPI()
|
||||
|
||||
def lookup_rates(self, ads, rates=None):
|
||||
def lookup_rates(self, platform, ads, rates=None):
|
||||
"""
|
||||
Lookup the rates for a list of public ads.
|
||||
"""
|
||||
if not rates:
|
||||
rates = self.cg.get_price(
|
||||
ids=["monero", "bitcoin"],
|
||||
vs_currencies=self.markets.get_all_currencies("agora"),
|
||||
vs_currencies=self.markets.get_all_currencies(platform),
|
||||
)
|
||||
# Set the price based on the asset
|
||||
for ad in ads:
|
||||
|
|
|
@ -378,7 +378,7 @@ class Agora(util.Base):
|
|||
ads_list = self.enum_public_ads(asset, currency, providers)
|
||||
if not ads_list:
|
||||
continue
|
||||
ads = self.money.lookup_rates(ads_list, rates=rates)
|
||||
ads = self.money.lookup_rates("agora", ads_list, rates=rates)
|
||||
if not ads:
|
||||
continue
|
||||
self.write_to_es_ads("ads", ads)
|
||||
|
|
|
@ -206,7 +206,7 @@ class TestAgora(TestCase):
|
|||
ad.append(margin)
|
||||
expected_return.append(ad)
|
||||
|
||||
lookup_rates_return = self.agora.money.lookup_rates(enum_ads_return) # TODO: do this properly
|
||||
lookup_rates_return = self.agora.money.lookup_rates("agora", enum_ads_return) # TODO: do this properly
|
||||
self.assertCountEqual(lookup_rates_return, expected_return)
|
||||
|
||||
def test_lookup_rates_not_usd(self):
|
||||
|
@ -234,5 +234,5 @@ class TestAgora(TestCase):
|
|||
ad.append(margin)
|
||||
expected_return.append(ad)
|
||||
# Test specifying rates=
|
||||
lookup_rates_return = self.agora.money.lookup_rates(enum_ads_return, rates=cg_prices)
|
||||
lookup_rates_return = self.agora.money.lookup_rates("agora", enum_ads_return, rates=cg_prices)
|
||||
self.assertCountEqual(lookup_rates_return, expected_return)
|
||||
|
|
Loading…
Reference in New Issue