diff options
Diffstat (limited to 'portfolio.py')
-rw-r--r-- | portfolio.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/portfolio.py b/portfolio.py index 9f82d88..1fe56b5 100644 --- a/portfolio.py +++ b/portfolio.py | |||
@@ -26,7 +26,7 @@ class Portfolio: | |||
26 | try: | 26 | try: |
27 | r = http.request("GET", cls.URL) | 27 | r = http.request("GET", cls.URL) |
28 | except Exception: | 28 | except Exception: |
29 | return | 29 | return None |
30 | try: | 30 | try: |
31 | cls.data = json.loads(r.data, | 31 | cls.data = json.loads(r.data, |
32 | parse_int=D, | 32 | parse_int=D, |
@@ -48,7 +48,7 @@ class Portfolio: | |||
48 | 48 | ||
49 | def clean_weights(i): | 49 | def clean_weights(i): |
50 | def clean_weights_(h): | 50 | def clean_weights_(h): |
51 | if type(h[1][i]) == str: | 51 | if isinstance(h[1][i], str): |
52 | return [h[0], h[1][i]] | 52 | return [h[0], h[1][i]] |
53 | else: | 53 | else: |
54 | return [h[0], int(h[1][i] * 10000)] | 54 | return [h[0], int(h[1][i] * 10000)] |
@@ -125,7 +125,7 @@ class Amount: | |||
125 | return Amount(self.currency, self.value - other.value) | 125 | return Amount(self.currency, self.value - other.value) |
126 | 126 | ||
127 | def __mul__(self, value): | 127 | def __mul__(self, value): |
128 | if type(value) != int and type(value) != float and type(value) != D: | 128 | if not isinstance(value, (int, float, D)): |
129 | raise TypeError("Amount may only be multiplied by numbers") | 129 | raise TypeError("Amount may only be multiplied by numbers") |
130 | return Amount(self.currency, self.value * value) | 130 | return Amount(self.currency, self.value * value) |
131 | 131 | ||
@@ -133,7 +133,7 @@ class Amount: | |||
133 | return self.__mul__(value) | 133 | return self.__mul__(value) |
134 | 134 | ||
135 | def __floordiv__(self, value): | 135 | def __floordiv__(self, value): |
136 | if type(value) != int and type(value) != float and type(value) != D: | 136 | if not isinstance(value, (int, float, D)): |
137 | raise TypeError("Amount may only be multiplied by integers") | 137 | raise TypeError("Amount may only be multiplied by integers") |
138 | return Amount(self.currency, self.value / value) | 138 | return Amount(self.currency, self.value / value) |
139 | 139 | ||
@@ -411,7 +411,7 @@ class Trade: | |||
411 | 411 | ||
412 | @classmethod | 412 | @classmethod |
413 | def compute_value(cls, ticker, action, compute_value="default"): | 413 | def compute_value(cls, ticker, action, compute_value="default"): |
414 | if type(compute_value) == str: | 414 | if isinstance(compute_value, str): |
415 | compute_value = Computation.computations[compute_value] | 415 | compute_value = Computation.computations[compute_value] |
416 | return compute_value(ticker, action) | 416 | return compute_value(ticker, action) |
417 | 417 | ||