diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-03-01 15:22:58 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-03-01 15:22:58 +0100 |
commit | 7192b2e1315c3dfd1204d609d716dd07e90f3bf4 (patch) | |
tree | b81bd8b33ab270421d1bbd6b32a8648c35e0a965 | |
parent | 3f41520799b97b3c440a6daeba684a6202e5a678 (diff) | |
download | Trader-7192b2e1315c3dfd1204d609d716dd07e90f3bf4.tar.gz Trader-7192b2e1315c3dfd1204d609d716dd07e90f3bf4.tar.zst Trader-7192b2e1315c3dfd1204d609d716dd07e90f3bf4.zip |
Fix ticker fetcher
-rw-r--r-- | market.py | 11 | ||||
-rw-r--r-- | test.py | 2 |
2 files changed, 7 insertions, 6 deletions
@@ -88,23 +88,22 @@ class Market: | |||
88 | "inverted": False, | 88 | "inverted": False, |
89 | "average": (ticker["bid"] + ticker["ask"] ) / 2, | 89 | "average": (ticker["bid"] + ticker["ask"] ) / 2, |
90 | }) | 90 | }) |
91 | return ticker | ||
91 | 92 | ||
92 | tickers = self.get_tickers() | 93 | tickers = self.get_tickers() |
93 | if tickers is None: | 94 | if tickers is None: |
94 | try: | 95 | try: |
95 | ticker = self.ccxt.fetch_ticker("{}/{}".format(c1, c2)) | 96 | ticker = augment_ticker(self.ccxt.fetch_ticker("{}/{}".format(c1, c2))) |
96 | augment_ticker(ticker) | ||
97 | except ExchangeError: | 97 | except ExchangeError: |
98 | try: | 98 | try: |
99 | ticker = invert(self.ccxt.fetch_ticker("{}/{}".format(c2, c1))) | 99 | ticker = invert(augment_ticker(self.ccxt.fetch_ticker("{}/{}".format(c2, c1)))) |
100 | except ExchangeError: | 100 | except ExchangeError: |
101 | ticker = None | 101 | ticker = None |
102 | else: | 102 | else: |
103 | if "{}/{}".format(c1, c2) in tickers: | 103 | if "{}/{}".format(c1, c2) in tickers: |
104 | ticker = tickers["{}/{}".format(c1, c2)] | 104 | ticker = augment_ticker(tickers["{}/{}".format(c1, c2)]) |
105 | augment_ticker(ticker) | ||
106 | elif "{}/{}".format(c2, c1) in tickers: | 105 | elif "{}/{}".format(c2, c1) in tickers: |
107 | ticker = invert(tickers["{}/{}".format(c2, c1)]) | 106 | ticker = invert(augment_ticker(tickers["{}/{}".format(c2, c1)])) |
108 | else: | 107 | else: |
109 | ticker = None | 108 | ticker = None |
110 | return ticker | 109 | return ticker |
@@ -693,6 +693,7 @@ class MarketTest(WebMockTestCase): | |||
693 | self.assertTrue(ticker["inverted"]) | 693 | self.assertTrue(ticker["inverted"]) |
694 | self.assertIn("original", ticker) | 694 | self.assertIn("original", ticker) |
695 | self.assertEqual(10, ticker["original"]["bid"]) | 695 | self.assertEqual(10, ticker["original"]["bid"]) |
696 | self.assertEqual(25, ticker["original"]["average"]) | ||
696 | 697 | ||
697 | ticker = m.get_ticker("XVG", "XMR") | 698 | ticker = m.get_ticker("XVG", "XMR") |
698 | self.assertIsNone(ticker) | 699 | self.assertIsNone(ticker) |
@@ -721,6 +722,7 @@ class MarketTest(WebMockTestCase): | |||
721 | self.assertTrue(ticker["inverted"]) | 722 | self.assertTrue(ticker["inverted"]) |
722 | self.assertIn("original", ticker) | 723 | self.assertIn("original", ticker) |
723 | self.assertEqual(10, ticker["original"]["bid"]) | 724 | self.assertEqual(10, ticker["original"]["bid"]) |
725 | self.assertEqual(25, ticker["original"]["average"]) | ||
724 | 726 | ||
725 | ticker = m.get_ticker("XVG", "XMR") | 727 | ticker = m.get_ticker("XVG", "XMR") |
726 | self.assertIsNone(ticker) | 728 | self.assertIsNone(ticker) |