Skip to content

Commit a9f6fa0

Browse files
committed
[CCXT] enable local override for auth balance check
1 parent b466cc2 commit a9f6fa0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

octobot_trading/exchanges/connectors/ccxt/ccxt_connector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def add_options(self, options_dict):
225225
@ccxt_client_util.converted_ccxt_common_errors
226226
async def _ensure_auth(self):
227227
try:
228-
await self.get_balance()
228+
await self.exchange_manager.exchange.get_balance()
229229
except (octobot_trading.errors.AuthenticationError, ccxt.AuthenticationError) as e:
230230
await self.client.close()
231231
self.unauthenticated_exchange_fallback(e)

tests/exchanges/connectors/ccxt/test_ccxt_connector.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# License along with this library.
1717
import decimal
1818

19+
import mock
1920
from mock import patch
2021

2122
import octobot_trading.exchanges.connectors as exchange_connectors
@@ -58,11 +59,13 @@ def set_markets(self, markets):
5859
def setSandboxMode(self, is_sandboxed):
5960
pass
6061

61-
with patch.object(ccxt_connector, 'client', new=MockCCXT()) as mocked_ccxt:
62+
with patch.object(ccxt_connector, 'client', new=MockCCXT()) as mocked_ccxt, \
63+
patch.object(ccxt_connector, '_ensure_auth', new=mock.AsyncMock()) as _ensure_auth_mock:
6264
await ccxt_connector.initialize_impl()
6365
assert ccxt_connector.symbols == set()
6466
assert ccxt_connector.time_frames == set()
6567
assert mocked_ccxt.set_markets_calls in ([[]], []) # depends on call order
68+
_ensure_auth_mock.assert_called_once()
6669

6770

6871
async def test_initialize_impl_with_empty_symbols_and_timeframes(ccxt_connector):
@@ -84,11 +87,13 @@ def set_markets(self, markets):
8487
def setSandboxMode(self, is_sandboxed):
8588
pass
8689

87-
with patch.object(ccxt_connector, 'client', new=MockCCXT()) as mocked_ccxt:
90+
with patch.object(ccxt_connector, 'client', new=MockCCXT()) as mocked_ccxt, \
91+
patch.object(ccxt_connector, '_ensure_auth', new=mock.AsyncMock()) as _ensure_auth_mock:
8892
await ccxt_connector.initialize_impl()
8993
assert ccxt_connector.symbols == set()
9094
assert ccxt_connector.time_frames == set()
9195
assert mocked_ccxt.set_markets_calls in ([[]], []) # depends on call order
96+
_ensure_auth_mock.assert_called_once()
9297

9398

9499
async def test_initialize_impl(ccxt_connector):
@@ -120,7 +125,8 @@ def set_markets(self, markets):
120125
def setSandboxMode(self, is_sandboxed):
121126
pass
122127

123-
with patch.object(ccxt_connector, 'client', new=MockCCXT()) as mocked_ccxt:
128+
with patch.object(ccxt_connector, 'client', new=MockCCXT()) as mocked_ccxt, \
129+
patch.object(ccxt_connector, '_ensure_auth', new=mock.AsyncMock()) as _ensure_auth_mock:
124130
await ccxt_connector.initialize_impl()
125131
assert ccxt_connector.symbols == {
126132
"BTC/USDT",
@@ -133,6 +139,7 @@ def setSandboxMode(self, is_sandboxed):
133139
"4h",
134140
}
135141
assert mocked_ccxt.set_markets_calls in ([[]], []) # depends on call order
142+
_ensure_auth_mock.assert_called_once()
136143

137144

138145
async def test_set_symbol_partial_take_profit_stop_loss(ccxt_connector):

0 commit comments

Comments
 (0)