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