Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions tests/exchanges/connectors/ccxt/test_ccxt_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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",
Expand All @@ -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):
Expand Down