]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/commitdiff
Fix ccxt switching currency codes
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 9 Apr 2018 09:52:45 +0000 (11:52 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 9 Apr 2018 09:52:45 +0000 (11:52 +0200)
ccxt_wrapper.py
portfolio.py
tests/test_ccxt_wrapper.py
tests/test_portfolio.py

index 366586ce1e0885f4a396011b282a9045b920a1c1..d2c9b4ce26550b0074f6632ddc2bdc972eb17bd2 100644 (file)
@@ -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
index 146ee79b29611da8b58c8bfc9cf2c83663fd7712..1067b0b0e50084283efe3c7d61477312ae9336d8 100644 (file)
@@ -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"]
index f07674e7927e130ce94efb680c2420243cf56c65..18feab32da53f3252541b116aee3fa13052ba11e 100644 (file)
@@ -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"))
index 2a42d0cd5507dc453ba76ff4fa54585bc47404cf..14dc9954f63679c03a12a087c2f69102c3109705 100644 (file)
@@ -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")