diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-02-09 20:00:26 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-02-09 20:07:47 +0100 |
commit | c51687d2b0cbad5460d8424f550014502d84696e (patch) | |
tree | a4fce092bdc31c28b5c6ea0fc40768b65da6550c /portfolio.py | |
parent | 80cdd672da2f0a4997a792bd1a2de19d4f516e5b (diff) | |
download | Trader-c51687d2b0cbad5460d8424f550014502d84696e.tar.gz Trader-c51687d2b0cbad5460d8424f550014502d84696e.tar.zst Trader-c51687d2b0cbad5460d8424f550014502d84696e.zip |
Fix Amount.__sub__ not working with 0
Add more tests
Diffstat (limited to 'portfolio.py')
-rw-r--r-- | portfolio.py | 4 |
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"): |