]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/commitdiff
Handle error when placing orders
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 22 Jan 2018 00:07:21 +0000 (01:07 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 22 Jan 2018 00:07:21 +0000 (01:07 +0100)
portfolio.py

index 60b57cad1aaac93fcf46f76a78612509ac97a3a1..fc468c28d5bfed892c9e48290d5fd4ec4ef64edb 100644 (file)
@@ -463,7 +463,7 @@ class Order:
 
     @property
     def finished(self):
-        return self.status == "closed" or self.status == "canceled"
+        return self.status == "closed" or self.status == "canceled" or self.status == "error"
 
     def run(self, debug=False):
         symbol = "{}/{}".format(self.amount.currency, self.base_currency)
@@ -476,8 +476,12 @@ class Order:
             try:
                 self.result = self.market.create_order(symbol, 'limit', self.action, amount, price=self.rate)
                 self.status = "open"
-            except Exception:
-                pass
+            except Exception as e:
+                self.status = "error"
+                print("error when running market.create_order('{}', 'limit', '{}', {}, price={})".format(
+                    symbol, self.action, amount, self.rate))
+                self.error_message = str("{}: {}".format(e.__class__.__name__, e))
+                print(self.error_message)
 
     def get_status(self):
         # other states are "closed" and "canceled"