]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/commitdiff
Return correct values and fix isinstance use
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Thu, 25 Jan 2018 22:59:39 +0000 (23:59 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Thu, 25 Jan 2018 22:59:39 +0000 (23:59 +0100)
portfolio.py

index 9f82d881fcfac30e440b06d3e3c423167c994ce2..1fe56b5992222f8eafddae8479ae0fdbb9f1b987 100644 (file)
@@ -26,7 +26,7 @@ class Portfolio:
         try:
             r = http.request("GET", cls.URL)
         except Exception:
-            return
+            return None
         try:
             cls.data = json.loads(r.data,
                     parse_int=D,
@@ -48,7 +48,7 @@ class Portfolio:
 
         def clean_weights(i):
             def clean_weights_(h):
-                if type(h[1][i]) == str:
+                if isinstance(h[1][i], str):
                     return [h[0], h[1][i]]
                 else:
                     return [h[0], int(h[1][i] * 10000)]
@@ -125,7 +125,7 @@ class Amount:
         return Amount(self.currency, self.value - other.value)
 
     def __mul__(self, value):
-        if type(value) != int and type(value) != float and type(value) != D:
+        if not isinstance(value, (int, float, D)):
             raise TypeError("Amount may only be multiplied by numbers")
         return Amount(self.currency, self.value * value)
 
@@ -133,7 +133,7 @@ class Amount:
         return self.__mul__(value)
 
     def __floordiv__(self, value):
-        if type(value) != int and type(value) != float and type(value) != D:
+        if not isinstance(value, (int, float, D)):
             raise TypeError("Amount may only be multiplied by integers")
         return Amount(self.currency, self.value / value)
 
@@ -411,7 +411,7 @@ class Trade:
 
     @classmethod
     def compute_value(cls, ticker, action, compute_value="default"):
-        if type(compute_value) == str:
+        if isinstance(compute_value, str):
             compute_value = Computation.computations[compute_value]
         return compute_value(ticker, action)