Filter the currencies in Agora

This commit is contained in:
Mark Veidemanis 2022-04-20 12:55:08 +01:00
parent 9360af7588
commit 165fe48234
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 21 additions and 3 deletions

View File

@ -259,7 +259,6 @@ class Agora(util.Base):
@util.handle_exceptions @util.handle_exceptions
def enum_public_ads(self, asset, currency, providers=None, page=0): def enum_public_ads(self, asset, currency, providers=None, page=0):
to_return = [] to_return = []
if asset == "XMR": if asset == "XMR":
coin = "monero" coin = "monero"
elif asset == "BTC": elif asset == "BTC":
@ -366,6 +365,9 @@ class Agora(util.Base):
currencies = self.markets.get_all_currencies(self.platform) currencies = self.markets.get_all_currencies(self.platform)
if not providers: if not providers:
providers = self.markets.get_all_providers(self.platform) providers = self.markets.get_all_providers(self.platform)
sinks_currencies = self.sinks.currencies
supported_currencies = [currency for currency in currencies if currency in sinks_currencies]
currencies = supported_currencies
# We want to get the ads for each of these currencies and return the result # 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) rates = self.money.cg.get_price(ids=["monero", "bitcoin"], vs_currencies=currencies)
for asset in assets: for asset in assets:

View File

@ -278,22 +278,30 @@ class LBTC(util.Base):
# with open("pub.json", "a") as f: # with open("pub.json", "a") as f:
# import json # import json
#
# f.write(json.dumps([page, currency, asset, ads]) + "\n") # f.write(json.dumps([page, currency, asset, ads]) + "\n")
# f.close() # f.close()
if ads is None: if ads is None:
print("ASDS IS NONE")
return False return False
if ads is False: if ads is False:
print("ADS IS FALSE")
return False return False
if ads["response"] is None: if ads["response"] is None:
print("NO RESPONSE")
return False return False
if "data" not in ads["response"]: if "data" not in ads["response"]:
print("NO DATAS")
return False return False
for ad in ads["response"]["data"]["ad_list"]: for ad in ads["response"]["data"]["ad_list"]:
if self.map_provider(ad["data"]["online_provider"]) not in providers: if self.map_provider(ad["data"]["online_provider"]) not in providers:
print(ad["data"]["online_provider"], "is not in", providers)
print(ad["data"]["online_provider"] in providers)
continue continue
date_last_seen = ad["data"]["profile"]["last_online"] date_last_seen = ad["data"]["profile"]["last_online"]
# Check if this person was seen recently # Check if this person was seen recently
if not util.last_online_recent(date_last_seen): if not util.last_online_recent(date_last_seen):
print("NOT SEEN RECENTLTY")
continue continue
ad_id = str(ad["data"]["ad_id"]) ad_id = str(ad["data"]["ad_id"])
username = ad["data"]["profile"]["username"] username = ad["data"]["profile"]["username"]
@ -340,13 +348,16 @@ class LBTC(util.Base):
@util.handle_exceptions @util.handle_exceptions
def update_prices(self, assets=None): def update_prices(self, assets=None):
print("UPDATE_PRICES", assets)
# Get all public ads for the given assets # Get all public ads for the given assets
public_ads = self.get_all_public_ads(assets) public_ads = self.get_all_public_ads(assets)
if not public_ads: if not public_ads:
print("NOT PUBLIC ADS")
return False return False
# Get the ads to update # Get the ads to update
to_update = self.markets.get_new_ad_equations(self.platform, public_ads, assets) to_update = self.markets.get_new_ad_equations(self.platform, public_ads, assets)
print("TO UPdATE", to_update)
self.slow_ad_update(to_update) self.slow_ad_update(to_update)
# TODO: make generic and move to markets # TODO: make generic and move to markets
@ -357,6 +368,7 @@ class LBTC(util.Base):
:return: dict of public ads keyed by currency :return: dict of public ads keyed by currency
:rtype: dict :rtype: dict
""" """
print("GET ALL PUBLIC ADS")
public_ads = {} public_ads = {}
crypto_map = { crypto_map = {
"BTC": "bitcoin", "BTC": "bitcoin",
@ -382,11 +394,14 @@ class LBTC(util.Base):
except KeyError: except KeyError:
# self.log.error("Error getting public ads for currency {currency}", currency=currency) # self.log.error("Error getting public ads for currency {currency}", currency=currency)
continue continue
print("ABOUT TO RUN ENUM PUBLIC ADS WITH ", asset, currency, providers)
ads_list = self.enum_public_ads(asset, currency, providers) ads_list = self.enum_public_ads(asset, currency, providers)
print("ADS LIST", ads_list)
if not ads_list: if not ads_list:
continue continue
ads = self.money.lookup_rates(self.platform, ads_list, rates=rates) ads = self.money.lookup_rates(self.platform, ads_list, rates=rates)
if not ads: if not ads:
print("NOT ADS CONTINUE")
continue continue
self.write_to_es_ads("ads", ads) self.write_to_es_ads("ads", ads)
if currency in public_ads: if currency in public_ads:
@ -395,6 +410,7 @@ class LBTC(util.Base):
public_ads[currency].append(ad) public_ads[currency].append(ad)
else: else:
public_ads[currency] = ads public_ads[currency] = ads
print("RETURNING PUBLIC ADS", public_ads)
return public_ads return public_ads
def write_to_es_ads(self, msgtype, ads): def write_to_es_ads(self, msgtype, ads):