diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-03-25 23:57:57 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-03-25 23:57:57 +0200 |
commit | e967a372218df05424b1566a02cafe2432d57326 (patch) | |
tree | e69f8f99ad47cfc3270192428fc2abee87eea65b /portfolio.py | |
parent | d004a2a5e15a78991870dcb90cd6db63ab40a4e6 (diff) | |
parent | b47d7b54cca8ff142eaadf38c8bb425bf11af2cd (diff) | |
download | Trader-e967a372218df05424b1566a02cafe2432d57326.tar.gz Trader-e967a372218df05424b1566a02cafe2432d57326.tar.zst Trader-e967a372218df05424b1566a02cafe2432d57326.zip |
Merge branch 'invalid_nonce' into dev
Fixes https://git.immae.eu/mantisbt/view.php?id=59
Diffstat (limited to 'portfolio.py')
-rw-r--r-- | portfolio.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/portfolio.py b/portfolio.py index 9c58676..9dae23e 100644 --- a/portfolio.py +++ b/portfolio.py | |||
@@ -1,7 +1,7 @@ | |||
1 | from datetime import datetime | 1 | from datetime import datetime |
2 | from retry import retry | 2 | from retry import retry |
3 | from decimal import Decimal as D, ROUND_DOWN | 3 | from decimal import Decimal as D, ROUND_DOWN |
4 | from ccxt import ExchangeError, InsufficientFunds, ExchangeNotAvailable, InvalidOrder, OrderNotCached, OrderNotFound, RequestTimeout | 4 | from ccxt import ExchangeError, InsufficientFunds, ExchangeNotAvailable, InvalidOrder, OrderNotCached, OrderNotFound, RequestTimeout, InvalidNonce |
5 | 5 | ||
6 | class Computation: | 6 | class Computation: |
7 | computations = { | 7 | computations = { |
@@ -477,7 +477,7 @@ class Order: | |||
477 | def finished(self): | 477 | def finished(self): |
478 | return self.status.startswith("closed") or self.status == "canceled" or self.status == "error" | 478 | return self.status.startswith("closed") or self.status == "canceled" or self.status == "error" |
479 | 479 | ||
480 | @retry((InsufficientFunds, RetryException)) | 480 | @retry((InsufficientFunds, RetryException, InvalidNonce)) |
481 | def run(self): | 481 | def run(self): |
482 | self.tries += 1 | 482 | self.tries += 1 |
483 | symbol = "{}/{}".format(self.amount.currency, self.base_currency) | 483 | symbol = "{}/{}".format(self.amount.currency, self.base_currency) |
@@ -496,6 +496,14 @@ class Order: | |||
496 | self.status = "closed" | 496 | self.status = "closed" |
497 | self.mark_finished_order() | 497 | self.mark_finished_order() |
498 | return | 498 | return |
499 | except InvalidNonce as e: | ||
500 | if self.tries < 5: | ||
501 | self.market.report.log_error(action, message="Retrying after invalid nonce", exception=e) | ||
502 | raise e | ||
503 | else: | ||
504 | self.market.report.log_error(action, message="Giving up {} after invalid nonce".format(self), exception=e) | ||
505 | self.status = "error" | ||
506 | return | ||
499 | except RequestTimeout as e: | 507 | except RequestTimeout as e: |
500 | if not self.retrieve_order(): | 508 | if not self.retrieve_order(): |
501 | if self.tries < 5: | 509 | if self.tries < 5: |