]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/blobdiff - portfolio.py
Fix Amount.__sub__ not working with 0
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git] / portfolio.py
index b3065b88542dabad925633a51cf4e0e2ab627cbc..45fbef98e72fefac5104223955a1b1897f632131 100644 (file)
@@ -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"):