Fix public ad related LBTC calls and tests

This commit is contained in:
2022-04-23 15:02:29 +01:00
parent ad21f6fb67
commit 69e44b9fdb
4 changed files with 49 additions and 29 deletions

View File

@@ -250,12 +250,18 @@ class LBTC(util.Base):
ads_total.append([ad[0], ad[1], ad[2], ad[3], ad[4]])
return ads_total
def map_provider(self, provider):
def map_provider(self, provider, reverse=False):
provider_map = {"NATIONAL_BANK": "national-bank-transfer"}
try:
return provider_map[provider]
except KeyError:
return False
if reverse:
try:
return next(key for key, value in provider_map.items() if value == provider)
except StopIteration:
return False
else:
try:
return provider_map[provider]
except KeyError:
return False
@util.handle_exceptions
def enum_public_ads(self, asset, currency, providers=None, page=1):
@@ -282,26 +288,19 @@ class LBTC(util.Base):
# f.write(json.dumps([page, currency, asset, ads]) + "\n")
# f.close()
if ads is None:
print("ASDS IS NONE")
return False
if ads is False:
print("ADS IS FALSE")
return False
if ads["response"] is None:
print("NO RESPONSE")
return False
if "data" not in ads["response"]:
print("NO DATAS")
return False
for ad in ads["response"]["data"]["ad_list"]:
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
date_last_seen = ad["data"]["profile"]["last_online"]
# Check if this person was seen recently
if not util.last_online_recent(date_last_seen):
print("NOT SEEN RECENTLTY")
continue
ad_id = str(ad["data"]["ad_id"])
username = ad["data"]["profile"]["username"]
@@ -348,16 +347,13 @@ class LBTC(util.Base):
@util.handle_exceptions
def update_prices(self, assets=None):
print("UPDATE_PRICES", assets)
# Get all public ads for the given assets
public_ads = self.get_all_public_ads(assets)
if not public_ads:
print("NOT PUBLIC ADS")
return False
# Get the ads to update
to_update = self.markets.get_new_ad_equations(self.platform, public_ads, assets)
print("TO UPdATE", to_update)
self.slow_ad_update(to_update)
# TODO: make generic and move to markets
@@ -368,7 +364,6 @@ class LBTC(util.Base):
:return: dict of public ads keyed by currency
:rtype: dict
"""
print("GET ALL PUBLIC ADS")
public_ads = {}
crypto_map = {
"BTC": "bitcoin",
@@ -394,14 +389,11 @@ class LBTC(util.Base):
except KeyError:
# self.log.error("Error getting public ads for currency {currency}", currency=currency)
continue
print("ABOUT TO RUN ENUM PUBLIC ADS WITH ", asset, currency, providers)
ads_list = self.enum_public_ads(asset, currency, providers)
print("ADS LIST", ads_list)
if not ads_list:
continue
ads = self.money.lookup_rates(self.platform, ads_list, rates=rates)
if not ads:
print("NOT ADS CONTINUE")
continue
self.write_to_es_ads("ads", ads)
if currency in public_ads:
@@ -410,7 +402,6 @@ class LBTC(util.Base):
public_ads[currency].append(ad)
else:
public_ads[currency] = ads
print("RETURNING PUBLIC ADS", public_ads)
return public_ads
def write_to_es_ads(self, msgtype, ads):