Add function to get acceptable margins
This commit is contained in:
parent
cd6e19a38a
commit
70682d1a9c
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue