diff --git a/core/clients/platform.py b/core/clients/platform.py index 0fc8ec5..ef2da13 100644 --- a/core/clients/platform.py +++ b/core/clients/platform.py @@ -69,19 +69,6 @@ class LocalPlatformClient(ABC): else: 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): provider_map = {"NATIONAL_BANK": "national-bank-transfer"} if reverse: @@ -101,13 +88,10 @@ class LocalPlatformClient(ABC): dash_tmp = await self.wrap_dashboard(dash) 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: - # dash = await self.api.dashboard() dash = await self.call("dashboard") - # if dash["response"] is None: - # return False dash_tmp = {} if not dash: return False @@ -131,38 +115,6 @@ class LocalPlatformClient(ABC): messages = await self.api.recent_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): """ Get information about our open trades. @@ -285,7 +237,6 @@ class LocalPlatformClient(ABC): if self.name == "lbtc" and page == 0: page = 1 ads = await self.call("ads", page=page) - # ads = await self.api._api_call(api_method="ads", query_values={"page": page}) ads_total = [] if not ads["success"]: return False @@ -309,7 +260,6 @@ class LocalPlatformClient(ABC): query_values = {"page": page} if 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_total = [] if not ads["success"]: @@ -362,12 +312,6 @@ class LocalPlatformClient(ABC): async def enum_public_ads(self, asset, currency, provider, page=0): log.debug(f"Enumerating public ads: {asset}/{currency}/{provider} ({page})") 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": ads = await self.call( "buy_monero_online", @@ -409,7 +353,6 @@ class LocalPlatformClient(ABC): to_append = [ad_id, username, temp_price, provider_ad, asset, currency] if to_append not in to_return: to_return.append(to_append) - # await [ad_id, username, temp_price, provider, asset, currency] if found_us: log.debug("Aborting fetch after finding our username") @@ -552,7 +495,6 @@ class LocalPlatformClient(ABC): f"sleeping for {sleep_time} seconds" ) ) - # We're running in a thread, so this is fine await asyncio.sleep(sleep_time) log.error(f"Error updating ad {ad_id}: {rtrn['response']}") continue @@ -614,17 +556,11 @@ class LocalPlatformClient(ABC): asset, currency, ) - if self.name == "lbtc": - bank_name = payment_details["bank"] - # if self.name == "agora": price_formula = ( f"coingecko{asset.lower()}usd*" f"usd{currency.lower()}*{self.instance.margin}" ) - # elif self.name == "lbtc": - # price_formula = f"btc_in_usd*{self.instance.margin}*USD_in_{currency}" - form = { "country_code": countrycode, "currency": currency, @@ -636,12 +572,10 @@ class LocalPlatformClient(ABC): "online_provider": provider, "require_feedback_score": 0, } - if self.name == "agora": - form["asset"] = asset - form["payment_method_details"] = ad.payment_method_details - form["online_provider"] = provider - elif self.name == "lbtc": - form["online_provider"] = self.map_provider(provider, reverse=True) + form["asset"] = asset + form["payment_method_details"] = ad.payment_method_details + form["online_provider"] = provider + if visible is False: form["visible"] = False elif visible is True: @@ -651,8 +585,6 @@ class LocalPlatformClient(ABC): form["msg"] = ad_text form["min_amount"] = round(min_amount, 2) form["max_amount"] = round(max_amount, 2) - if self.name == "lbtc": - form["bank_name"] = bank_name if edit: ad_response = await self.api.ad(ad_id=ad_id, **form) @@ -777,7 +709,6 @@ class LocalPlatformClient(ABC): return all(actioned) 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}" log.info(logmessage) title = "Releasing escrow" @@ -860,17 +791,6 @@ class LocalPlatformClient(ABC): reference = f"AGR-{reference}" existing_ref = self.instance.contact_id_to_reference(trade_id) 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 = { "contact_id": trade_id, "reference": reference, @@ -884,8 +804,6 @@ class LocalPlatformClient(ABC): } log.info(f"Storing trade information: {str(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}" title = "Generated reference" await notify.sendmsg(self.instance.user, message, title=title) @@ -1007,10 +925,6 @@ class LocalPlatformClient(ABC): assets = self.instance.ads_assets currencies = self.instance.currencies providers = self.instance.ads_providers - # if platform == "lbtc": - # providers = [ - # self.sources.lbtc.map_provider(x, reverse=True) for x in providers - # ] brute = [ (asset, currency, provider) @@ -1165,22 +1079,25 @@ class LocalPlatformClient(ABC): else: yield (asset, countrycode, currency, provider) - def get_valid_account_details(self, ad): + def get_valid_account_details(self, ad=None): currencies = self.instance.currencies account_info = self.instance.account_info - account_whitelist = ad.account_whitelist - if account_whitelist: - whitelist = account_whitelist.splitlines() - else: - whitelist = None + if ad is not None: + account_whitelist = ad.account_whitelist + if account_whitelist: + whitelist = account_whitelist.splitlines() + else: + whitelist = None currency_account_info_map = {} + # Nothing to see here... for currency in currencies: for bank, accounts in account_info.items(): for account in accounts: if account["currency"] == currency: - if whitelist: - if account["account_id"] not in whitelist: - continue + if ad is not None: + if whitelist: + if account["account_id"] not in whitelist: + continue currency_account_info_map[currency] = account["account_number"] currency_account_info_map[currency]["bank"] = bank.split("_")[0] currency_account_info_map[currency]["recipient"] = account[ @@ -1197,77 +1114,64 @@ class LocalPlatformClient(ABC): return False return currency_account_info_map[currency] - # def _distribute_account_details(self, platform, currencies= - # None, account_info=None): - # """ - # Distribute account details for ads. - # We will disable ads we can't support. - # """ + async def sync_ad_visibility(self, currencies=None, account_info=None): + """ + We will disable ads we can't support. + """ - # if not currencies: - # currencies = self.instance.currencies - # if not account_info: - # account_info = self.instance.account_info - # ( - # supported_currencies, - # currency_account_info_map, - # ) = self.get_valid_account_details(platform) + if not currencies: + currencies = self.instance.currencies + if not account_info: + account_info = self.instance.account_info + # ( + # supported_currencies, + # currency_account_info_map, + # ) = self.get_valid_account_details(self.platform) - # # not_supported = [currency for currency in all_currencies if - # # currency not in supported_currencies] + # not_supported = [currency for currency in all_currencies if + # 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 - # encies] + # supported_ads = [ad for ad in our_ads if ad[3] in currencies] - # not_supported_ads = [ad for ad in our_ads if ad[3] not in supporte - # d_currencies] + not_supported_ads = [ad for ad in our_ads if ad[3] not in currencies] - # for ad in supported_ads: - # asset = ad[0] - # countrycode = ad[2] - # currency = ad[3] - # provider = ad[4] - # payment_details = currency_account_info_map[currency] - # ad_id = ad[1] - # self.create_ad( - # asset, - # countrycode, - # currency, - # provider, - # payment_details, - # visible=True, - # edit=True, - # ad_id=ad_id, - # ) + # for ad in supported_ads: + # asset = ad[0] + # countrycode = ad[2] + # currency = ad[3] + # provider = ad[4] + # # payment_details = currency_account_info_map[currency] + # ad_id = ad[1] + # self.create_ad( + # asset, + # countrycode, + # currency, + # provider, + # payment_details, + # visible=True, + # edit=True, + # ad_id=ad_id, + # ) - # for ad in not_supported_ads: - # asset = ad[0] - # countrycode = ad[2] - # currency = ad[3] - # provider = ad[4] - # ad_id = ad[1] - # self.create_ad( - # asset, - # countrycode, - # currency, - # provider, - # payment_details=False, - # visible=False, - # 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 - # ) + for ad in not_supported_ads: + asset = ad[0] + countrycode = ad[2] + currency = ad[3] + provider = ad[4] + ad_id = ad[1] + await self.create_ad( + asset, + countrycode, + currency, + provider, + payment_details=False, + ad=None, + visible=False, + edit=True, + ad_id=ad_id, + ) def format_ad(self, asset, currency, payment_details_text, ad): """