From c51687d2b0cbad5460d8424f550014502d84696e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Fri, 9 Feb 2018 20:00:26 +0100 Subject: Fix Amount.__sub__ not working with 0 Add more tests --- portfolio.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'portfolio.py') diff --git a/portfolio.py b/portfolio.py index b3065b8..45fbef9 100644 --- a/portfolio.py +++ b/portfolio.py @@ -116,6 +116,8 @@ class Amount: return self.__add__(other) def __sub__(self, other): + if other == 0: + return self if other.currency != self.currency and other.value * self.value != 0: raise Exception("Summing amounts must be done with same currencies") return Amount(self.currency, self.value - other.value) @@ -197,7 +199,7 @@ class Balance: "margin_lending_fees", "margin_borrowed_base_price" ]: - setattr(self, key, Amount(base_currency, hash_[key])) + setattr(self, key, Amount(base_currency, hash_.get(key, 0))) @classmethod def in_currency(cls, other_currency, market, compute_value="average", type="total"): -- cgit v1.2.3