From fd8afa518c0e22387d27e5a6008f6b4816cb7dbe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 22 Jan 2018 01:07:21 +0100 Subject: [PATCH] Handle error when placing orders --- portfolio.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/portfolio.py b/portfolio.py index 60b57ca..fc468c2 100644 --- a/portfolio.py +++ b/portfolio.py @@ -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" -- 2.41.0