Add function to get acceptable margins

This commit is contained in:
Mark Veidemanis 2021-12-28 23:56:32 +00:00
parent cd6e19a38a
commit 70682d1a9c
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 20 additions and 0 deletions

View File

@ -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.