aboutsummaryrefslogtreecommitdiff
path: root/portfolio.py
diff options
context:
space:
mode:
Diffstat (limited to 'portfolio.py')
-rw-r--r--portfolio.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/portfolio.py b/portfolio.py
index b3065b8..45fbef9 100644
--- a/portfolio.py
+++ b/portfolio.py
@@ -116,6 +116,8 @@ class Amount:
116 return self.__add__(other) 116 return self.__add__(other)
117 117
118 def __sub__(self, other): 118 def __sub__(self, other):
119 if other == 0:
120 return self
119 if other.currency != self.currency and other.value * self.value != 0: 121 if other.currency != self.currency and other.value * self.value != 0:
120 raise Exception("Summing amounts must be done with same currencies") 122 raise Exception("Summing amounts must be done with same currencies")
121 return Amount(self.currency, self.value - other.value) 123 return Amount(self.currency, self.value - other.value)
@@ -197,7 +199,7 @@ class Balance:
197 "margin_lending_fees", 199 "margin_lending_fees",
198 "margin_borrowed_base_price" 200 "margin_borrowed_base_price"
199 ]: 201 ]:
200 setattr(self, key, Amount(base_currency, hash_[key])) 202 setattr(self, key, Amount(base_currency, hash_.get(key, 0)))
201 203
202 @classmethod 204 @classmethod
203 def in_currency(cls, other_currency, market, compute_value="average", type="total"): 205 def in_currency(cls, other_currency, market, compute_value="average", type="total"):