]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/commitdiff
Fix ticker fetcher
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Thu, 1 Mar 2018 14:22:58 +0000 (15:22 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Thu, 1 Mar 2018 14:22:58 +0000 (15:22 +0100)
market.py
test.py

index 9122fc07256ce7d30e9e3490912ea54a15c842d7..0d91f17e35c988086c69b5a5f6d816f403cc699d 100644 (file)
--- a/market.py
+++ b/market.py
@@ -88,23 +88,22 @@ class Market:
                 "inverted": False,
                 "average": (ticker["bid"] + ticker["ask"] ) / 2,
                 })
+            return ticker
 
         tickers = self.get_tickers()
         if tickers is None:
             try:
-                ticker = self.ccxt.fetch_ticker("{}/{}".format(c1, c2))
-                augment_ticker(ticker)
+                ticker = augment_ticker(self.ccxt.fetch_ticker("{}/{}".format(c1, c2)))
             except ExchangeError:
                 try:
-                    ticker = invert(self.ccxt.fetch_ticker("{}/{}".format(c2, c1)))
+                    ticker = invert(augment_ticker(self.ccxt.fetch_ticker("{}/{}".format(c2, c1))))
                 except ExchangeError:
                     ticker = None
         else:
             if "{}/{}".format(c1, c2) in tickers:
-                ticker = tickers["{}/{}".format(c1, c2)]
-                augment_ticker(ticker)
+                ticker = augment_ticker(tickers["{}/{}".format(c1, c2)])
             elif "{}/{}".format(c2, c1) in tickers:
-                ticker = invert(tickers["{}/{}".format(c2, c1)])
+                ticker = invert(augment_ticker(tickers["{}/{}".format(c2, c1)]))
             else:
                 ticker = None
         return ticker
diff --git a/test.py b/test.py
index 37b0e881f65405422c1a8d57e04ec7ce36e39c16..fbc857dbc64729a7969c9f0655b312c5827fd967 100644 (file)
--- a/test.py
+++ b/test.py
@@ -693,6 +693,7 @@ class MarketTest(WebMockTestCase):
             self.assertTrue(ticker["inverted"])
             self.assertIn("original", ticker)
             self.assertEqual(10, ticker["original"]["bid"])
+            self.assertEqual(25, ticker["original"]["average"])
 
             ticker = m.get_ticker("XVG", "XMR")
             self.assertIsNone(ticker)
@@ -721,6 +722,7 @@ class MarketTest(WebMockTestCase):
             self.assertTrue(ticker["inverted"])
             self.assertIn("original", ticker)
             self.assertEqual(10, ticker["original"]["bid"])
+            self.assertEqual(25, ticker["original"]["average"])
 
             ticker = m.get_ticker("XVG", "XMR")
             self.assertIsNone(ticker)