Provide the provider to market and money functions
This commit is contained in:
parent
c173e9d232
commit
7cfeb95b10
|
@ -11,19 +11,28 @@ class Markets(util.Base):
|
|||
Markets handler for generic market functions.
|
||||
"""
|
||||
|
||||
def get_all_assets(self):
|
||||
def get_all_assets(self, platform):
|
||||
if platform == "agora":
|
||||
assets = loads(settings.Agora.AssetList)
|
||||
elif platform == "lbtc":
|
||||
assets = loads(settings.LocalBitcoins.AssetList)
|
||||
return assets
|
||||
|
||||
def get_all_providers(self):
|
||||
def get_all_providers(self, platform):
|
||||
if platform == "agora":
|
||||
providers = loads(settings.Agora.ProviderList)
|
||||
elif platform == "lbtc":
|
||||
providers = loads(settings.LocalBitcoins.ProviderList)
|
||||
return providers
|
||||
|
||||
def get_all_currencies(self):
|
||||
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)]))
|
||||
return currencies
|
||||
|
||||
def get_new_ad_equations(self, public_ads, assets=None):
|
||||
def get_new_ad_equations(self, platform, public_ads, assets=None):
|
||||
"""
|
||||
Update all our prices.
|
||||
:param public_ads: dictionary of public ads keyed by currency
|
||||
|
@ -31,6 +40,10 @@ class Markets(util.Base):
|
|||
:return: list of ads to modify
|
||||
:rtype: list
|
||||
"""
|
||||
if platform == "agora":
|
||||
username = settings.Agora.Username
|
||||
elif platform == "lbtc":
|
||||
username = settings.LocalBitcoins.Username
|
||||
to_update = []
|
||||
|
||||
# NOTES:
|
||||
|
@ -40,9 +53,9 @@ class Markets(util.Base):
|
|||
|
||||
# (asset, currency, provider)
|
||||
if not assets:
|
||||
assets = self.get_all_assets()
|
||||
currencies = self.get_all_currencies()
|
||||
providers = self.get_all_providers()
|
||||
assets = self.get_all_assets(platform)
|
||||
currencies = self.get_all_currencies(platform)
|
||||
providers = self.get_all_providers(platform)
|
||||
|
||||
brute = [(asset, currency, provider) for asset in assets for currency in currencies for provider in providers]
|
||||
for asset, currency, provider in brute:
|
||||
|
@ -62,7 +75,7 @@ class Markets(util.Base):
|
|||
# Filter provider
|
||||
public_ads_filtered = [ad for ad in public_ads_filtered if ad[3] == provider]
|
||||
|
||||
our_ads = [ad for ad in public_ads_filtered if ad[1] == settings.Agora.Username]
|
||||
our_ads = [ad for ad in public_ads_filtered if ad[1] == username]
|
||||
if not our_ads:
|
||||
continue
|
||||
new_margin = self.autoprice(public_ads_filtered, currency)
|
||||
|
|
|
@ -29,7 +29,7 @@ class Money(util.Base):
|
|||
if not rates:
|
||||
rates = self.cg.get_price(
|
||||
ids=["monero", "bitcoin"],
|
||||
vs_currencies=self.markets.get_all_currencies(),
|
||||
vs_currencies=self.markets.get_all_currencies("agora"),
|
||||
)
|
||||
# Set the price based on the asset
|
||||
for ad in ads:
|
||||
|
|
|
@ -341,7 +341,7 @@ class Agora(util.Base):
|
|||
return False
|
||||
|
||||
# Get the ads to update
|
||||
to_update = self.markets.get_new_ad_equations(public_ads, assets)
|
||||
to_update = self.markets.get_new_ad_equations("agora", public_ads, assets)
|
||||
self.slow_ad_update(to_update)
|
||||
|
||||
# TODO: make generic and move to markets
|
||||
|
@ -359,12 +359,12 @@ class Agora(util.Base):
|
|||
}
|
||||
|
||||
if not assets:
|
||||
assets = self.markets.get_all_assets()
|
||||
assets = self.markets.get_all_assets("agora")
|
||||
# Get all currencies we have ads for, deduplicated
|
||||
if not currencies:
|
||||
currencies = self.markets.get_all_currencies()
|
||||
currencies = self.markets.get_all_currencies("agora")
|
||||
if not providers:
|
||||
providers = self.markets.get_all_providers()
|
||||
providers = self.markets.get_all_providers("agora")
|
||||
# We want to get the ads for each of these currencies and return the result
|
||||
rates = self.money.cg.get_price(ids=["monero", "bitcoin"], vs_currencies=currencies)
|
||||
for asset in assets:
|
||||
|
|
|
@ -64,18 +64,18 @@ class TestMarkets(TestCase):
|
|||
self.assertEqual(margin, expected_margin)
|
||||
|
||||
def test_get_new_ad_equation(self):
|
||||
to_update = self.markets.get_new_ad_equations(fake_public_ads)
|
||||
to_update = self.markets.get_new_ad_equations("agora", fake_public_ads)
|
||||
self.assertCountEqual(to_update, expected_to_update)
|
||||
|
||||
res_xmr = self.markets.get_new_ad_equations(fake_public_ads, ["XMR"])
|
||||
res_xmr = self.markets.get_new_ad_equations("agora", fake_public_ads, ["XMR"])
|
||||
expected_xmr_to_update = [x for x in expected_to_update if x[2] == "XMR"]
|
||||
self.assertCountEqual(res_xmr, expected_xmr_to_update)
|
||||
|
||||
res_btc = self.markets.get_new_ad_equations(fake_public_ads, ["BTC"])
|
||||
res_btc = self.markets.get_new_ad_equations("agora", fake_public_ads, ["BTC"])
|
||||
expected_btc_to_update = [x for x in expected_to_update if x[2] == "BTC"]
|
||||
self.assertCountEqual(res_btc, expected_btc_to_update)
|
||||
|
||||
res_both = self.markets.get_new_ad_equations(fake_public_ads, ["XMR", "BTC"])
|
||||
res_both = self.markets.get_new_ad_equations("agora", fake_public_ads, ["XMR", "BTC"])
|
||||
self.assertCountEqual(res_both, expected_to_update)
|
||||
|
||||
def test_format_ad(self):
|
||||
|
|
Loading…
Reference in New Issue