Skip to content

Commit bd42a7b

Browse files
committed
[Exchanges] factorize market parsing and auth check
1 parent a2a6e41 commit bd42a7b

File tree

2 files changed

+7
-31
lines changed

2 files changed

+7
-31
lines changed

Trading/Exchange/coinbase/coinbase_exchange.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,7 @@ async def _load_markets(
121121
market_filter: typing.Optional[typing.Callable[[dict], bool]] = None
122122
):
123123
# override for retrier and populate ALIASED_SYMBOLS
124-
try:
125-
if self.exchange_manager.exchange.FETCH_MIN_EXCHANGE_MARKETS and market_filter:
126-
with ccxt_client_util.filtered_fetched_markets(client, market_filter):
127-
await client.load_markets(reload=reload)
128-
else:
129-
await client.load_markets(reload=reload)
130-
except Exception as err:
131-
# ensure this is not a proxy error, raise dedicated error if it is
132-
if proxy_error := ccxt_client_util.get_proxy_error_if_any(self, err):
133-
raise ccxt_client_util.get_proxy_error_class(proxy_error)(proxy_error) from err
134-
raise
124+
await self._filtered_if_necessary_load_markets(client, reload, market_filter)
135125
# only call _refresh_alias_symbols from here as markets just got reloaded,
136126
# no market can be missing unlike when using cached markets
137127
_refresh_alias_symbols(client)
@@ -260,11 +250,7 @@ async def _ensure_auth(self):
260250
# Override of ccxt_connector._ensure_auth to use get_open_orders instead and propagate authentication errors
261251
try:
262252
# load markets before calling _ensure_auth() to avoid fetching markets status while they are cached
263-
with self.error_describer():
264-
await self.load_symbol_markets(
265-
reload=not self.exchange_manager.use_cached_markets,
266-
market_filter=self.exchange_manager.market_filter,
267-
)
253+
await self._unauth_ensure_exchange_init()
268254
# replace self.exchange_manager.exchange.get_balance by get_open_orders
269255
# to mitigate coinbase balance cache side effect
270256
await self.exchange_manager.exchange.get_open_orders(symbol="BTC/USDC")

Trading/Exchange/kucoin/kucoin_exchange.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,11 @@ async def _load_markets(
7777
market_filter: typing.Optional[typing.Callable[[dict], bool]] = None
7878
):
7979
# override for retrier
80-
try:
81-
if self.exchange_manager.exchange.FETCH_MIN_EXCHANGE_MARKETS and market_filter:
82-
with ccxt_client_util.filtered_fetched_markets(client, market_filter):
83-
await client.load_markets(reload=reload)
84-
else:
85-
await client.load_markets(reload=reload)
86-
# sometimes market fees are missing because they are fetched from all tickers
87-
# and all ticker can miss symbols on kucoin
88-
if client.markets:
89-
ccxt_client_util.fix_client_missing_markets_fees(client, reload, _CACHED_CONFIRMED_FEES_BY_SYMBOL)
90-
except Exception as err:
91-
# ensure this is not a proxy error, raise dedicated error if it is
92-
if proxy_error := ccxt_client_util.get_proxy_error_if_any(self, err):
93-
raise ccxt_client_util.get_proxy_error_class(proxy_error)(proxy_error) from err
94-
raise
80+
await self._filtered_if_necessary_load_markets(client, reload, market_filter)
81+
# sometimes market fees are missing because they are fetched from all tickers
82+
# and all ticker can miss symbols on kucoin
83+
if client.markets:
84+
ccxt_client_util.fix_client_missing_markets_fees(client, reload, _CACHED_CONFIRMED_FEES_BY_SYMBOL)
9585

9686
class Kucoin(exchanges.RestExchange):
9787
FIX_MARKET_STATUS = True

0 commit comments

Comments
 (0)