aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-05-08 21:00:27 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-05-08 21:00:27 +0200
commit5321200c05b3b693581ec4238c74eb02e0b715d7 (patch)
tree893f0bd619deba53cd92895c97bd13e0a600feb9
parent3a15ffc79ea84e5ec6200545bcbf11fc6c1c6564 (diff)
downloadTrader-5321200c05b3b693581ec4238c74eb02e0b715d7.tar.gz
Trader-5321200c05b3b693581ec4238c74eb02e0b715d7.tar.zst
Trader-5321200c05b3b693581ec4238c74eb02e0b715d7.zip
Check before processing that credentials are valid
-rw-r--r--market.py5
-rw-r--r--tests/test_market.py11
2 files changed, 15 insertions, 1 deletions
diff --git a/market.py b/market.py
index caa9513..9550b77 100644
--- a/market.py
+++ b/market.py
@@ -1,4 +1,4 @@
1from ccxt import ExchangeError, NotSupported, RequestTimeout, InvalidNonce 1from ccxt import AuthenticationError, ExchangeError, NotSupported, RequestTimeout, InvalidNonce
2import ccxt_wrapper as ccxt 2import ccxt_wrapper as ccxt
3import time 3import time
4import dbs 4import dbs
@@ -88,6 +88,7 @@ class Market:
88 88
89 def process(self, actions, before=False, after=False): 89 def process(self, actions, before=False, after=False):
90 try: 90 try:
91 self.ccxt.check_required_credentials()
91 for action in actions: 92 for action in actions:
92 if bool(before) is bool(after): 93 if bool(before) is bool(after):
93 self.processor.process(action, steps="all") 94 self.processor.process(action, steps="all")
@@ -95,6 +96,8 @@ class Market:
95 self.processor.process(action, steps="before") 96 self.processor.process(action, steps="before")
96 elif after: 97 elif after:
97 self.processor.process(action, steps="after") 98 self.processor.process(action, steps="after")
99 except AuthenticationError:
100 self.report.log_error("market_authentication", message="Impossible to authenticate to market")
98 except Exception as e: 101 except Exception as e:
99 import traceback 102 import traceback
100 self.report.log_error("market_process", exception=e, message=traceback.format_exc()) 103 self.report.log_error("market_process", exception=e, message=traceback.format_exc())
diff --git a/tests/test_market.py b/tests/test_market.py
index 2c92655..c89025b 100644
--- a/tests/test_market.py
+++ b/tests/test_market.py
@@ -890,6 +890,17 @@ class MarketTest(WebMockTestCase):
890 process.reset_mock() 890 process.reset_mock()
891 log_error.reset_mock() 891 log_error.reset_mock()
892 store_report.reset_mock() 892 store_report.reset_mock()
893 with self.subTest(authentication_error=True):
894 m.ccxt.check_required_credentials.side_effect = market.ccxt.AuthenticationError
895
896 m.process(["some_action"], before=True)
897 log_error.assert_called_with("market_authentication", message="Impossible to authenticate to market")
898 store_report.assert_called_once()
899
900 m.ccxt.check_required_credentials.side_effect = True
901 process.reset_mock()
902 log_error.reset_mock()
903 store_report.reset_mock()
893 with self.subTest(unhandled_exception=True): 904 with self.subTest(unhandled_exception=True):
894 process.side_effect = Exception("bouh") 905 process.side_effect = Exception("bouh")
895 906