aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-01-22 01:07:21 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-01-22 01:07:21 +0100
commitfd8afa518c0e22387d27e5a6008f6b4816cb7dbe (patch)
tree47341cd74ea9b959cc9dee9bd80a6c49c64535c8
parentf2097d713e2e9419850ca5b758c76b79485d7502 (diff)
downloadTrader-fd8afa518c0e22387d27e5a6008f6b4816cb7dbe.tar.gz
Trader-fd8afa518c0e22387d27e5a6008f6b4816cb7dbe.tar.zst
Trader-fd8afa518c0e22387d27e5a6008f6b4816cb7dbe.zip
Handle error when placing orders
-rw-r--r--portfolio.py10
1 files 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:
463 463
464 @property 464 @property
465 def finished(self): 465 def finished(self):
466 return self.status == "closed" or self.status == "canceled" 466 return self.status == "closed" or self.status == "canceled" or self.status == "error"
467 467
468 def run(self, debug=False): 468 def run(self, debug=False):
469 symbol = "{}/{}".format(self.amount.currency, self.base_currency) 469 symbol = "{}/{}".format(self.amount.currency, self.base_currency)
@@ -476,8 +476,12 @@ class Order:
476 try: 476 try:
477 self.result = self.market.create_order(symbol, 'limit', self.action, amount, price=self.rate) 477 self.result = self.market.create_order(symbol, 'limit', self.action, amount, price=self.rate)
478 self.status = "open" 478 self.status = "open"
479 except Exception: 479 except Exception as e:
480 pass 480 self.status = "error"
481 print("error when running market.create_order('{}', 'limit', '{}', {}, price={})".format(
482 symbol, self.action, amount, self.rate))
483 self.error_message = str("{}: {}".format(e.__class__.__name__, e))
484 print(self.error_message)
481 485
482 def get_status(self): 486 def get_status(self):
483 # other states are "closed" and "canceled" 487 # other states are "closed" and "canceled"