diff --git a/octobot_trading/exchanges/connectors/ccxt/ccxt_connector.py b/octobot_trading/exchanges/connectors/ccxt/ccxt_connector.py index 22111269f..aca89a1a9 100644 --- a/octobot_trading/exchanges/connectors/ccxt/ccxt_connector.py +++ b/octobot_trading/exchanges/connectors/ccxt/ccxt_connector.py @@ -225,7 +225,7 @@ def add_options(self, options_dict): @ccxt_client_util.converted_ccxt_common_errors async def _ensure_auth(self): try: - await self.get_balance() + await self.exchange_manager.exchange.get_balance() except (octobot_trading.errors.AuthenticationError, ccxt.AuthenticationError) as e: await self.client.close() self.unauthenticated_exchange_fallback(e) diff --git a/tests/exchanges/connectors/ccxt/test_ccxt_connector.py b/tests/exchanges/connectors/ccxt/test_ccxt_connector.py index 46d9566a1..c0ca7ef10 100644 --- a/tests/exchanges/connectors/ccxt/test_ccxt_connector.py +++ b/tests/exchanges/connectors/ccxt/test_ccxt_connector.py @@ -16,6 +16,7 @@ # License along with this library. import decimal +import mock from mock import patch import octobot_trading.exchanges.connectors as exchange_connectors @@ -58,11 +59,13 @@ def set_markets(self, markets): def setSandboxMode(self, is_sandboxed): pass - with patch.object(ccxt_connector, 'client', new=MockCCXT()) as mocked_ccxt: + with patch.object(ccxt_connector, 'client', new=MockCCXT()) as mocked_ccxt, \ + patch.object(ccxt_connector, '_ensure_auth', new=mock.AsyncMock()) as _ensure_auth_mock: await ccxt_connector.initialize_impl() assert ccxt_connector.symbols == set() assert ccxt_connector.time_frames == set() assert mocked_ccxt.set_markets_calls in ([[]], []) # depends on call order + _ensure_auth_mock.assert_called_once() async def test_initialize_impl_with_empty_symbols_and_timeframes(ccxt_connector): @@ -84,11 +87,13 @@ def set_markets(self, markets): def setSandboxMode(self, is_sandboxed): pass - with patch.object(ccxt_connector, 'client', new=MockCCXT()) as mocked_ccxt: + with patch.object(ccxt_connector, 'client', new=MockCCXT()) as mocked_ccxt, \ + patch.object(ccxt_connector, '_ensure_auth', new=mock.AsyncMock()) as _ensure_auth_mock: await ccxt_connector.initialize_impl() assert ccxt_connector.symbols == set() assert ccxt_connector.time_frames == set() assert mocked_ccxt.set_markets_calls in ([[]], []) # depends on call order + _ensure_auth_mock.assert_called_once() async def test_initialize_impl(ccxt_connector): @@ -120,7 +125,8 @@ def set_markets(self, markets): def setSandboxMode(self, is_sandboxed): pass - with patch.object(ccxt_connector, 'client', new=MockCCXT()) as mocked_ccxt: + with patch.object(ccxt_connector, 'client', new=MockCCXT()) as mocked_ccxt, \ + patch.object(ccxt_connector, '_ensure_auth', new=mock.AsyncMock()) as _ensure_auth_mock: await ccxt_connector.initialize_impl() assert ccxt_connector.symbols == { "BTC/USDT", @@ -133,6 +139,7 @@ def setSandboxMode(self, is_sandboxed): "4h", } assert mocked_ccxt.set_markets_calls in ([[]], []) # depends on call order + _ensure_auth_mock.assert_called_once() async def test_set_symbol_partial_take_profit_stop_loss(ccxt_connector):