aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-01-25 23:59:39 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-01-25 23:59:39 +0100
commit77f8a3789e293ece45946abd7ea3acffdf6add82 (patch)
tree8afaee3dc0e74f0a72effe1ca450d9ab0e4e3817
parente0b14bcc15b5ce397733c2a965917ce17dd935b3 (diff)
downloadTrader-77f8a3789e293ece45946abd7ea3acffdf6add82.tar.gz
Trader-77f8a3789e293ece45946abd7ea3acffdf6add82.tar.zst
Trader-77f8a3789e293ece45946abd7ea3acffdf6add82.zip
Return correct values and fix isinstance use
-rw-r--r--portfolio.py10
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