diff --git a/handler/markets.py b/handler/markets.py index 4b903e1..ae0be1f 100644 --- a/handler/markets.py +++ b/handler/markets.py @@ -11,24 +11,18 @@ class Markets(util.Base): Markets handler for generic market functions. """ - def get_settings(self, platform): - if platform == "agora": - return settings.Agora - elif platform == "lbtc": - return settings.LocalBitcoins - def get_all_assets(self, platform): - sets = self.get_settings(platform) + sets = util.get_settings(platform) assets = loads(sets.AssetList) return assets def get_all_providers(self, platform): - sets = self.get_settings(platform) + sets = util.get_settings(platform) providers = loads(sets.ProviderList) return providers def get_all_currencies(self, platform): - sets = self.get_settings(platform) + sets = util.get_settings(platform) currencies = list(set([x[0] for x in loads(sets.DistList)])) return currencies @@ -40,7 +34,7 @@ class Markets(util.Base): :return: list of ads to modify :rtype: list """ - sets = self.get_settings(platform) + sets = util.get_settings(platform) username = sets.Username min_margin = sets.MinMargin max_margin = sets.MaxMargin @@ -170,7 +164,7 @@ class Markets(util.Base): :return: generator of asset, countrycode, currency, provider :rtype: generator of tuples """ - sets = self.get_settings(platform) + sets = util.get_settings(platform) # Iterate providers like REVOLUT, NATIONAL_BANK for provider in loads(sets.ProviderList): diff --git a/handler/money.py b/handler/money.py index 8ba1c0b..38af7fd 100644 --- a/handler/money.py +++ b/handler/money.py @@ -54,7 +54,7 @@ class Money(util.Base): rates = self.cr.get_rates("USD") return rates - def get_acceptable_margins(self, currency, amount): + def get_acceptable_margins(self, platform, currency, amount): """ Get the minimum and maximum amounts we would accept a trade for. :param currency: currency code @@ -62,29 +62,31 @@ class Money(util.Base): :return: (min, max) :rtype: tuple """ + sets = util.get_settings(platform) rates = self.get_rates_all() if currency == "USD": - min_amount = amount - float(settings.Agora.AcceptableUSDMargin) - max_amount = amount + float(settings.Agora.AcceptableUSDMargin) + min_amount = amount - float(sets.AcceptableUSDMargin) + max_amount = amount + float(sets.AcceptableUSDMargin) return (min_amount, max_amount) amount_usd = amount / rates[currency] - min_usd = amount_usd - float(settings.Agora.AcceptableUSDMargin) - max_usd = amount_usd + float(settings.Agora.AcceptableUSDMargin) + min_usd = amount_usd - float(sets.AcceptableUSDMargin) + max_usd = amount_usd + float(sets.AcceptableUSDMargin) min_local = min_usd * rates[currency] max_local = max_usd * rates[currency] return (min_local, max_local) - def get_minmax(self, asset, currency): + def get_minmax(self, platform, asset, currency): + sets = util.get_settings(platform) rates = self.get_rates_all() if currency not in rates and not currency == "USD": self.log.error(f"Can't create ad without rates: {currency}") return if asset == "XMR": - min_usd = float(settings.Agora.MinUSDXMR) - max_usd = float(settings.Agora.MaxUSDXMR) + min_usd = float(sets.MinUSDXMR) + max_usd = float(sets.MaxUSDXMR) elif asset == "BTC": - min_usd = float(settings.Agora.MinUSDBTC) - max_usd = float(settings.Agora.MaxUSDBTC) + min_usd = float(sets.MinUSDBTC) + max_usd = float(sets.MaxUSDBTC) if currency == "USD": min_amount = min_usd max_amount = max_usd diff --git a/handler/transactions.py b/handler/transactions.py index 8f34b7f..0fceebf 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -196,9 +196,9 @@ class Transactions(util.Base): return False return True - def alt_amount_check(self, amount, currency, reference, stored_trade): + def alt_amount_check(self, platform, amount, currency, reference, stored_trade): # If the amount does not match exactly, get the min and max values for our given acceptable margins for trades - min_amount, max_amount = self.money.get_acceptable_margins(currency, stored_trade["amount"]) + min_amount, max_amount = self.money.get_acceptable_margins(platform, currency, stored_trade["amount"]) self.log.info(f"Amount does not match exactly, trying with margins: min: {min_amount} / max: {max_amount}") self.irc.sendmsg(f"Amount does not match exactly, trying with margins: min: {min_amount} / max: {max_amount}") if not min_amount < amount < max_amount: @@ -372,7 +372,8 @@ class Transactions(util.Base): if not stored_trade["amount"] == amount: if looked_up_without_reference: return - if not self.alt_amount_check(amount, currency, reference, stored_trade): + platform = stored_trade["subclass"] + if not self.alt_amount_check(platform, amount, currency, reference, stored_trade): return platform = stored_trade["subclass"] platform_buyer = stored_trade["buyer"] diff --git a/handler/util.py b/handler/util.py index 0160cb6..3e143e0 100644 --- a/handler/util.py +++ b/handler/util.py @@ -3,6 +3,9 @@ from httpx import ReadTimeout, ReadError, RemoteProtocolError from datetime import datetime import logging +# Project imports +from settings import settings + log = logging.getLogger("util") @@ -151,3 +154,10 @@ def handle_exceptions(func): return rtrn return inner_function + + +def get_settings(platform): + if platform == "agora": + return settings.Agora + elif platform == "lbtc": + return settings.LocalBitcoins