From 18de421e455ab4b125a6684d703a296562097e6b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 9 Apr 2018 11:52:45 +0200 Subject: [PATCH] Fix ccxt switching currency codes --- ccxt_wrapper.py | 10 ++++++++++ portfolio.py | 4 ++++ tests/test_ccxt_wrapper.py | 4 ++++ tests/test_portfolio.py | 20 ++++++++++++++++++++ 4 files changed, 38 insertions(+) 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") -- 2.41.0