From 70682d1a9c66569e26f19de7e67aa7f2fa966520 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 28 Dec 2021 23:56:32 +0000 Subject: [PATCH] Add function to get acceptable margins --- handler/agora.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/handler/agora.py b/handler/agora.py index 356144d..131776c 100644 --- a/handler/agora.py +++ b/handler/agora.py @@ -186,6 +186,26 @@ class Agora(object): rates = self.cr.get_rates("USD") return rates + def get_acceptable_margins(self, currency, amount): + """ + Get the minimum and maximum amounts we would accept a trade for. + :param currency: currency code + :param amount: amount + :return: (min, max) + :rtype: tuple + """ + rates = self.get_rates_all() + if currency == "USD": + min_amount = amount - float(settings.Agora.AcceptableUSDMargin) + max_amount = amount + float(settings.Agora.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_local = min_usd * rates[currency] + max_local = max_usd * rates[currency] + return (min_local, max_local) + def create_ad(self, countrycode, currency): """ Post an ad in a country with a given currency.