Add function to make unsupported ads invisible
This commit is contained in:
parent
ba0f6cbf33
commit
dce33ca11c
|
@ -69,19 +69,6 @@ class LocalPlatformClient(ABC):
|
||||||
else:
|
else:
|
||||||
raise Exception(f"Method {method} not found in {self.name} API.")
|
raise Exception(f"Method {method} not found in {self.name} API.")
|
||||||
|
|
||||||
# TODO: do in schedules
|
|
||||||
# def setup_loop(self):
|
|
||||||
# """
|
|
||||||
# Set up the LoopingCall to get all active trades and messages.
|
|
||||||
# """
|
|
||||||
# log.debug("Setting up loops.")
|
|
||||||
# self.lc_dash = LoopingCall(self.loop_check)
|
|
||||||
# self.lc_dash.start(int(self.sets.RefreshSec))
|
|
||||||
# if settings.Agora.Cheat == "1":
|
|
||||||
# self.lc_cheat = LoopingCall(self.run_cheat_in_thread)
|
|
||||||
# self.lc_cheat.start(int(self.sets.CheatSec))
|
|
||||||
# log.debug("Finished setting up loops.")
|
|
||||||
|
|
||||||
def map_provider(self, provider, reverse=False):
|
def map_provider(self, provider, reverse=False):
|
||||||
provider_map = {"NATIONAL_BANK": "national-bank-transfer"}
|
provider_map = {"NATIONAL_BANK": "national-bank-transfer"}
|
||||||
if reverse:
|
if reverse:
|
||||||
|
@ -101,13 +88,10 @@ class LocalPlatformClient(ABC):
|
||||||
dash_tmp = await self.wrap_dashboard(dash)
|
dash_tmp = await self.wrap_dashboard(dash)
|
||||||
await self.dashboard_hook(dash_tmp)
|
await self.dashboard_hook(dash_tmp)
|
||||||
|
|
||||||
async def wrap_dashboard(self, dash=None): # backwards compatibility with TX
|
async def wrap_dashboard(self, dash=None):
|
||||||
if not dash:
|
if not dash:
|
||||||
# dash = await self.api.dashboard()
|
|
||||||
dash = await self.call("dashboard")
|
dash = await self.call("dashboard")
|
||||||
|
|
||||||
# if dash["response"] is None:
|
|
||||||
# return False
|
|
||||||
dash_tmp = {}
|
dash_tmp = {}
|
||||||
if not dash:
|
if not dash:
|
||||||
return False
|
return False
|
||||||
|
@ -131,38 +115,6 @@ class LocalPlatformClient(ABC):
|
||||||
messages = await self.api.recent_messages()
|
messages = await self.api.recent_messages()
|
||||||
await self.got_recent_messages(messages)
|
await self.got_recent_messages(messages)
|
||||||
|
|
||||||
# async def get_dashboard_irc(self):
|
|
||||||
# """
|
|
||||||
# Get dashboard helper for IRC only.
|
|
||||||
# """
|
|
||||||
# dash = await self.wrap_dashboard()
|
|
||||||
# rtrn = []
|
|
||||||
# if dash is False:
|
|
||||||
# return False
|
|
||||||
# for contact_id, contact in dash.items():
|
|
||||||
# reference = db.tx_to_ref(contact_id)
|
|
||||||
# buyer = contact["data"]["buyer"]["username"]
|
|
||||||
# amount = contact["data"]["amount"]
|
|
||||||
# if self.name == "agora":
|
|
||||||
# asset = contact["data"]["advertisement"]["asset"]
|
|
||||||
# elif self.name == "lbtc":
|
|
||||||
# asset = "BTC"
|
|
||||||
# if asset == "XMR":
|
|
||||||
# amount_crypto = contact["data"]["amount_xmr"]
|
|
||||||
# elif asset == "BTC":
|
|
||||||
# amount_crypto = contact["data"]["amount_btc"]
|
|
||||||
# currency = contact["data"]["currency"]
|
|
||||||
# provider = contact["data"]["advertisement"]["payment_method"]
|
|
||||||
# if not contact["data"]["is_selling"]:
|
|
||||||
# continue
|
|
||||||
# rtrn.append(
|
|
||||||
# (
|
|
||||||
# f"[#] [{reference}] ({self.name}) <{buyer}>"
|
|
||||||
# f" {amount}{currency} {provider} {amount_crypto}{asset}"
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
# return rtrn
|
|
||||||
|
|
||||||
async def dashboard_hook(self, dash):
|
async def dashboard_hook(self, dash):
|
||||||
"""
|
"""
|
||||||
Get information about our open trades.
|
Get information about our open trades.
|
||||||
|
@ -285,7 +237,6 @@ class LocalPlatformClient(ABC):
|
||||||
if self.name == "lbtc" and page == 0:
|
if self.name == "lbtc" and page == 0:
|
||||||
page = 1
|
page = 1
|
||||||
ads = await self.call("ads", page=page)
|
ads = await self.call("ads", page=page)
|
||||||
# ads = await self.api._api_call(api_method="ads", query_values={"page": page})
|
|
||||||
ads_total = []
|
ads_total = []
|
||||||
if not ads["success"]:
|
if not ads["success"]:
|
||||||
return False
|
return False
|
||||||
|
@ -309,7 +260,6 @@ class LocalPlatformClient(ABC):
|
||||||
query_values = {"page": page}
|
query_values = {"page": page}
|
||||||
if requested_asset:
|
if requested_asset:
|
||||||
query_values["asset"] = requested_asset
|
query_values["asset"] = requested_asset
|
||||||
# ads = await self.api._api_call(api_method="ads", query_values=query_values)
|
|
||||||
ads = await self.call("ads", page=page)
|
ads = await self.call("ads", page=page)
|
||||||
ads_total = []
|
ads_total = []
|
||||||
if not ads["success"]:
|
if not ads["success"]:
|
||||||
|
@ -362,12 +312,6 @@ class LocalPlatformClient(ABC):
|
||||||
async def enum_public_ads(self, asset, currency, provider, page=0):
|
async def enum_public_ads(self, asset, currency, provider, page=0):
|
||||||
log.debug(f"Enumerating public ads: {asset}/{currency}/{provider} ({page})")
|
log.debug(f"Enumerating public ads: {asset}/{currency}/{provider} ({page})")
|
||||||
to_return = []
|
to_return = []
|
||||||
# buy-monero-online, buy-bitcoin-online
|
|
||||||
# Work around Agora weirdness calling it bitcoins
|
|
||||||
# ads = await self.api._api_call(
|
|
||||||
# api_method=f"buy-{coin}-online/{currency}",
|
|
||||||
# query_values={"page": page},
|
|
||||||
# )
|
|
||||||
if asset == "XMR":
|
if asset == "XMR":
|
||||||
ads = await self.call(
|
ads = await self.call(
|
||||||
"buy_monero_online",
|
"buy_monero_online",
|
||||||
|
@ -409,7 +353,6 @@ class LocalPlatformClient(ABC):
|
||||||
to_append = [ad_id, username, temp_price, provider_ad, asset, currency]
|
to_append = [ad_id, username, temp_price, provider_ad, asset, currency]
|
||||||
if to_append not in to_return:
|
if to_append not in to_return:
|
||||||
to_return.append(to_append)
|
to_return.append(to_append)
|
||||||
# await [ad_id, username, temp_price, provider, asset, currency]
|
|
||||||
|
|
||||||
if found_us:
|
if found_us:
|
||||||
log.debug("Aborting fetch after finding our username")
|
log.debug("Aborting fetch after finding our username")
|
||||||
|
@ -552,7 +495,6 @@ class LocalPlatformClient(ABC):
|
||||||
f"sleeping for {sleep_time} seconds"
|
f"sleeping for {sleep_time} seconds"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# We're running in a thread, so this is fine
|
|
||||||
await asyncio.sleep(sleep_time)
|
await asyncio.sleep(sleep_time)
|
||||||
log.error(f"Error updating ad {ad_id}: {rtrn['response']}")
|
log.error(f"Error updating ad {ad_id}: {rtrn['response']}")
|
||||||
continue
|
continue
|
||||||
|
@ -614,17 +556,11 @@ class LocalPlatformClient(ABC):
|
||||||
asset,
|
asset,
|
||||||
currency,
|
currency,
|
||||||
)
|
)
|
||||||
if self.name == "lbtc":
|
|
||||||
bank_name = payment_details["bank"]
|
|
||||||
|
|
||||||
# if self.name == "agora":
|
|
||||||
price_formula = (
|
price_formula = (
|
||||||
f"coingecko{asset.lower()}usd*"
|
f"coingecko{asset.lower()}usd*"
|
||||||
f"usd{currency.lower()}*{self.instance.margin}"
|
f"usd{currency.lower()}*{self.instance.margin}"
|
||||||
)
|
)
|
||||||
# elif self.name == "lbtc":
|
|
||||||
# price_formula = f"btc_in_usd*{self.instance.margin}*USD_in_{currency}"
|
|
||||||
|
|
||||||
form = {
|
form = {
|
||||||
"country_code": countrycode,
|
"country_code": countrycode,
|
||||||
"currency": currency,
|
"currency": currency,
|
||||||
|
@ -636,12 +572,10 @@ class LocalPlatformClient(ABC):
|
||||||
"online_provider": provider,
|
"online_provider": provider,
|
||||||
"require_feedback_score": 0,
|
"require_feedback_score": 0,
|
||||||
}
|
}
|
||||||
if self.name == "agora":
|
form["asset"] = asset
|
||||||
form["asset"] = asset
|
form["payment_method_details"] = ad.payment_method_details
|
||||||
form["payment_method_details"] = ad.payment_method_details
|
form["online_provider"] = provider
|
||||||
form["online_provider"] = provider
|
|
||||||
elif self.name == "lbtc":
|
|
||||||
form["online_provider"] = self.map_provider(provider, reverse=True)
|
|
||||||
if visible is False:
|
if visible is False:
|
||||||
form["visible"] = False
|
form["visible"] = False
|
||||||
elif visible is True:
|
elif visible is True:
|
||||||
|
@ -651,8 +585,6 @@ class LocalPlatformClient(ABC):
|
||||||
form["msg"] = ad_text
|
form["msg"] = ad_text
|
||||||
form["min_amount"] = round(min_amount, 2)
|
form["min_amount"] = round(min_amount, 2)
|
||||||
form["max_amount"] = round(max_amount, 2)
|
form["max_amount"] = round(max_amount, 2)
|
||||||
if self.name == "lbtc":
|
|
||||||
form["bank_name"] = bank_name
|
|
||||||
|
|
||||||
if edit:
|
if edit:
|
||||||
ad_response = await self.api.ad(ad_id=ad_id, **form)
|
ad_response = await self.api.ad(ad_id=ad_id, **form)
|
||||||
|
@ -777,7 +709,6 @@ class LocalPlatformClient(ABC):
|
||||||
return all(actioned)
|
return all(actioned)
|
||||||
|
|
||||||
async def release_trade_escrow(self, trade_id, reference):
|
async def release_trade_escrow(self, trade_id, reference):
|
||||||
# stored_trade = await db.get_ref(reference)
|
|
||||||
logmessage = f"All checks passed, releasing funds for {trade_id} {reference}"
|
logmessage = f"All checks passed, releasing funds for {trade_id} {reference}"
|
||||||
log.info(logmessage)
|
log.info(logmessage)
|
||||||
title = "Releasing escrow"
|
title = "Releasing escrow"
|
||||||
|
@ -860,17 +791,6 @@ class LocalPlatformClient(ABC):
|
||||||
reference = f"AGR-{reference}"
|
reference = f"AGR-{reference}"
|
||||||
existing_ref = self.instance.contact_id_to_reference(trade_id)
|
existing_ref = self.instance.contact_id_to_reference(trade_id)
|
||||||
if not existing_ref:
|
if not existing_ref:
|
||||||
# to_store = {
|
|
||||||
# "id": trade_id,
|
|
||||||
# "tx": "",
|
|
||||||
# "asset": asset,
|
|
||||||
# "buyer": buyer,
|
|
||||||
# "currency": currency,
|
|
||||||
# "amount": amount,
|
|
||||||
# "amount_crypto": amount_crypto,
|
|
||||||
# "reference": reference,
|
|
||||||
# "provider": provider,
|
|
||||||
# }
|
|
||||||
trade_cast = {
|
trade_cast = {
|
||||||
"contact_id": trade_id,
|
"contact_id": trade_id,
|
||||||
"reference": reference,
|
"reference": reference,
|
||||||
|
@ -884,8 +804,6 @@ class LocalPlatformClient(ABC):
|
||||||
}
|
}
|
||||||
log.info(f"Storing trade information: {str(trade_cast)}")
|
log.info(f"Storing trade information: {str(trade_cast)}")
|
||||||
self.instance.new_trade(trade_cast)
|
self.instance.new_trade(trade_cast)
|
||||||
# await db.r.hmset(f"trade.{reference}", to_store)
|
|
||||||
# await db.r.set(f"trade.{trade_id}.reference", reference)
|
|
||||||
message = f"Generated reference for {trade_id}: {reference}"
|
message = f"Generated reference for {trade_id}: {reference}"
|
||||||
title = "Generated reference"
|
title = "Generated reference"
|
||||||
await notify.sendmsg(self.instance.user, message, title=title)
|
await notify.sendmsg(self.instance.user, message, title=title)
|
||||||
|
@ -1007,10 +925,6 @@ class LocalPlatformClient(ABC):
|
||||||
assets = self.instance.ads_assets
|
assets = self.instance.ads_assets
|
||||||
currencies = self.instance.currencies
|
currencies = self.instance.currencies
|
||||||
providers = self.instance.ads_providers
|
providers = self.instance.ads_providers
|
||||||
# if platform == "lbtc":
|
|
||||||
# providers = [
|
|
||||||
# self.sources.lbtc.map_provider(x, reverse=True) for x in providers
|
|
||||||
# ]
|
|
||||||
|
|
||||||
brute = [
|
brute = [
|
||||||
(asset, currency, provider)
|
(asset, currency, provider)
|
||||||
|
@ -1165,22 +1079,25 @@ class LocalPlatformClient(ABC):
|
||||||
else:
|
else:
|
||||||
yield (asset, countrycode, currency, provider)
|
yield (asset, countrycode, currency, provider)
|
||||||
|
|
||||||
def get_valid_account_details(self, ad):
|
def get_valid_account_details(self, ad=None):
|
||||||
currencies = self.instance.currencies
|
currencies = self.instance.currencies
|
||||||
account_info = self.instance.account_info
|
account_info = self.instance.account_info
|
||||||
account_whitelist = ad.account_whitelist
|
if ad is not None:
|
||||||
if account_whitelist:
|
account_whitelist = ad.account_whitelist
|
||||||
whitelist = account_whitelist.splitlines()
|
if account_whitelist:
|
||||||
else:
|
whitelist = account_whitelist.splitlines()
|
||||||
whitelist = None
|
else:
|
||||||
|
whitelist = None
|
||||||
currency_account_info_map = {}
|
currency_account_info_map = {}
|
||||||
|
# Nothing to see here...
|
||||||
for currency in currencies:
|
for currency in currencies:
|
||||||
for bank, accounts in account_info.items():
|
for bank, accounts in account_info.items():
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
if account["currency"] == currency:
|
if account["currency"] == currency:
|
||||||
if whitelist:
|
if ad is not None:
|
||||||
if account["account_id"] not in whitelist:
|
if whitelist:
|
||||||
continue
|
if account["account_id"] not in whitelist:
|
||||||
|
continue
|
||||||
currency_account_info_map[currency] = account["account_number"]
|
currency_account_info_map[currency] = account["account_number"]
|
||||||
currency_account_info_map[currency]["bank"] = bank.split("_")[0]
|
currency_account_info_map[currency]["bank"] = bank.split("_")[0]
|
||||||
currency_account_info_map[currency]["recipient"] = account[
|
currency_account_info_map[currency]["recipient"] = account[
|
||||||
|
@ -1197,77 +1114,64 @@ class LocalPlatformClient(ABC):
|
||||||
return False
|
return False
|
||||||
return currency_account_info_map[currency]
|
return currency_account_info_map[currency]
|
||||||
|
|
||||||
# def _distribute_account_details(self, platform, currencies=
|
async def sync_ad_visibility(self, currencies=None, account_info=None):
|
||||||
# None, account_info=None):
|
"""
|
||||||
# """
|
We will disable ads we can't support.
|
||||||
# Distribute account details for ads.
|
"""
|
||||||
# We will disable ads we can't support.
|
|
||||||
# """
|
|
||||||
|
|
||||||
# if not currencies:
|
if not currencies:
|
||||||
# currencies = self.instance.currencies
|
currencies = self.instance.currencies
|
||||||
# if not account_info:
|
if not account_info:
|
||||||
# account_info = self.instance.account_info
|
account_info = self.instance.account_info
|
||||||
# (
|
# (
|
||||||
# supported_currencies,
|
# supported_currencies,
|
||||||
# currency_account_info_map,
|
# currency_account_info_map,
|
||||||
# ) = self.get_valid_account_details(platform)
|
# ) = self.get_valid_account_details(self.platform)
|
||||||
|
|
||||||
# # not_supported = [currency for currency in all_currencies if
|
# not_supported = [currency for currency in all_currencies if
|
||||||
# # currency not in supported_currencies]
|
# currency not in supported_currencies]
|
||||||
|
|
||||||
# our_ads = self.enum_ads()
|
our_ads = await self.enum_ads()
|
||||||
|
|
||||||
# supported_ads = [ad for ad in our_ads if ad[3] in supported_curr
|
# supported_ads = [ad for ad in our_ads if ad[3] in currencies]
|
||||||
# encies]
|
|
||||||
|
|
||||||
# not_supported_ads = [ad for ad in our_ads if ad[3] not in supporte
|
not_supported_ads = [ad for ad in our_ads if ad[3] not in currencies]
|
||||||
# d_currencies]
|
|
||||||
|
|
||||||
# for ad in supported_ads:
|
# for ad in supported_ads:
|
||||||
# asset = ad[0]
|
# asset = ad[0]
|
||||||
# countrycode = ad[2]
|
# countrycode = ad[2]
|
||||||
# currency = ad[3]
|
# currency = ad[3]
|
||||||
# provider = ad[4]
|
# provider = ad[4]
|
||||||
# payment_details = currency_account_info_map[currency]
|
# # payment_details = currency_account_info_map[currency]
|
||||||
# ad_id = ad[1]
|
# ad_id = ad[1]
|
||||||
# self.create_ad(
|
# self.create_ad(
|
||||||
# asset,
|
# asset,
|
||||||
# countrycode,
|
# countrycode,
|
||||||
# currency,
|
# currency,
|
||||||
# provider,
|
# provider,
|
||||||
# payment_details,
|
# payment_details,
|
||||||
# visible=True,
|
# visible=True,
|
||||||
# edit=True,
|
# edit=True,
|
||||||
# ad_id=ad_id,
|
# ad_id=ad_id,
|
||||||
# )
|
# )
|
||||||
|
|
||||||
# for ad in not_supported_ads:
|
for ad in not_supported_ads:
|
||||||
# asset = ad[0]
|
asset = ad[0]
|
||||||
# countrycode = ad[2]
|
countrycode = ad[2]
|
||||||
# currency = ad[3]
|
currency = ad[3]
|
||||||
# provider = ad[4]
|
provider = ad[4]
|
||||||
# ad_id = ad[1]
|
ad_id = ad[1]
|
||||||
# self.create_ad(
|
await self.create_ad(
|
||||||
# asset,
|
asset,
|
||||||
# countrycode,
|
countrycode,
|
||||||
# currency,
|
currency,
|
||||||
# provider,
|
provider,
|
||||||
# payment_details=False,
|
payment_details=False,
|
||||||
# visible=False,
|
ad=None,
|
||||||
# edit=True,
|
visible=False,
|
||||||
# ad_id=ad_id,
|
edit=True,
|
||||||
# )
|
ad_id=ad_id,
|
||||||
|
)
|
||||||
# def distribute_account_details(self, currencies=None, account_info=None):
|
|
||||||
# """
|
|
||||||
# Helper to distribute the account details for all platforms.
|
|
||||||
# """
|
|
||||||
# platforms = "agora"
|
|
||||||
# for platform in platforms:
|
|
||||||
# self._distribute_account_details(
|
|
||||||
# platform, currencies=currencies, account_info=account_info
|
|
||||||
# )
|
|
||||||
|
|
||||||
def format_ad(self, asset, currency, payment_details_text, ad):
|
def format_ad(self, asset, currency, payment_details_text, ad):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue