From: Ismaƫl Bouya Date: Mon, 9 Apr 2018 09:52:45 +0000 (+0200) Subject: Fix ccxt switching currency codes X-Git-Tag: v1.2.2^2 X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git;a=commitdiff_plain;h=18de421e455ab4b125a6684d703a296562097e6b Fix ccxt switching currency codes --- diff --git a/ccxt_wrapper.py b/ccxt_wrapper.py index 366586c..d2c9b4c 100644 --- a/ccxt_wrapper.py +++ b/ccxt_wrapper.py @@ -391,4 +391,14 @@ class poloniexE(poloniex): else: raise NotImplementedError + def common_currency_code(self, currency): + """ + Wrapped to avoid the currency translation + """ + return currency + def currency_id(self, currency): + """ + Wrapped to avoid the currency translation + """ + return currency diff --git a/portfolio.py b/portfolio.py index 146ee79..1067b0b 100644 --- a/portfolio.py +++ b/portfolio.py @@ -311,6 +311,10 @@ class Trade: if self.action is None: return None ticker = self.market.get_ticker(self.currency, self.base_currency) + if ticker is None: + self.market.report.log_error("prepare_order", + message="Unknown ticker {}/{}".format(self.currency, self.base_currency)) + return None self.inverted = ticker["inverted"] if self.inverted: ticker = ticker["original"] diff --git a/tests/test_ccxt_wrapper.py b/tests/test_ccxt_wrapper.py index f07674e..18feab3 100644 --- a/tests/test_ccxt_wrapper.py +++ b/tests/test_ccxt_wrapper.py @@ -477,4 +477,8 @@ class poloniexETest(unittest.TestCase): create_order.assert_called_once_with("symbol", "type", "side", "amount", price="price", params="params") + def test_common_currency_code(self): + self.assertEqual("FOO", self.s.common_currency_code("FOO")) + def test_currency_id(self): + self.assertEqual("FOO", self.s.currency_id("FOO")) diff --git a/tests/test_portfolio.py b/tests/test_portfolio.py index 2a42d0c..14dc995 100644 --- a/tests/test_portfolio.py +++ b/tests/test_portfolio.py @@ -218,6 +218,26 @@ class TradeTest(WebMockTestCase): self.assertEqual(0, len(trade.orders)) Order.assert_not_called() + self.m.get_ticker.return_value = None + with self.subTest(desc="Unknown ticker"): + filled_amount.return_value = portfolio.Amount("BTC", "3") + compute_value.return_value = D("0.125") + + value_from = portfolio.Amount("BTC", "1") + value_from.rate = D("0.1") + value_from.linked_to = portfolio.Amount("FOO", "10") + value_to = portfolio.Amount("BTC", "10") + trade = portfolio.Trade(value_from, value_to, "FOO", self.m) + + trade.prepare_order() + + filled_amount.assert_not_called() + compute_value.assert_not_called() + self.assertEqual(0, len(trade.orders)) + Order.assert_not_called() + self.m.report.log_error.assert_called_once_with('prepare_order', + message='Unknown ticker FOO/BTC') + self.m.get_ticker.return_value = { "inverted": False } with self.subTest(desc="Already filled"): filled_amount.return_value = portfolio.Amount("FOO", "100")