X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git;a=blobdiff_plain;f=portfolio.py;h=45fbef98e72fefac5104223955a1b1897f632131;hp=b3065b88542dabad925633a51cf4e0e2ab627cbc;hb=c51687d2b0cbad5460d8424f550014502d84696e;hpb=80cdd672da2f0a4997a792bd1a2de19d4f516e5b 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"):