Skip to content
Merged

Ref #1304

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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.4.233] - 2024-11-27
### Updated
[CCXTConnector] refactor to simplify factorization in subclasses
[CCXTExchange] improve exchange load error

## [2.4.232] - 2024-11-26
### Added
[Requirements] [full] requirements installation
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OctoBot-Trading [2.4.232](https://github.com/Drakkar-Software/OctoBot-Trading/blob/master/CHANGELOG.md)
# OctoBot-Trading [2.4.233](https://github.com/Drakkar-Software/OctoBot-Trading/blob/master/CHANGELOG.md)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/903b6b22bceb4661b608a86fea655f69)](https://app.codacy.com/gh/Drakkar-Software/OctoBot-Trading?utm_source=github.com&utm_medium=referral&utm_content=Drakkar-Software/OctoBot-Trading&utm_campaign=Badge_Grade_Dashboard)
[![PyPI](https://img.shields.io/pypi/v/OctoBot-Trading.svg)](https://pypi.python.org/pypi/OctoBot-Trading/)
[![Coverage Status](https://coveralls.io/repos/github/Drakkar-Software/OctoBot-Trading/badge.svg?branch=master)](https://coveralls.io/github/Drakkar-Software/OctoBot-Trading?branch=master)
Expand Down
2 changes: 1 addition & 1 deletion octobot_trading/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# License along with this library.

PROJECT_NAME = "OctoBot-Trading"
VERSION = "2.4.232" # major.minor.revision
VERSION = "2.4.233" # major.minor.revision
58 changes: 34 additions & 24 deletions octobot_trading/exchanges/connectors/ccxt/ccxt_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,7 @@ async def initialize_impl(self):
ccxt_client_util.set_sandbox_mode(
self, self.exchange_manager.is_sandboxed
)

if self.force_authentication or (
self._should_authenticate() and not self.exchange_manager.exchange_only
):
await self._ensure_auth()
else:
with self.error_describer():
await self.load_symbol_markets(
reload=not self.exchange_manager.use_cached_markets,
market_filter=self.exchange_manager.market_filter,
)
await self._ensure_exchange_init()

# initialize symbols and timeframes
self.symbols = self.exchange_manager.exchange.get_all_available_symbols(active_only=True)
Expand All @@ -110,6 +100,22 @@ async def initialize_impl(self):
except (ccxt.ExchangeNotAvailable, ccxt.RequestTimeout) as e:
raise octobot_trading.errors.UnreachableExchange(e) from e

async def _ensure_exchange_init(self):
if self.force_authentication or (
self._should_authenticate() and not self.exchange_manager.exchange_only
):
await self._ensure_auth()
else:
await self._unauth_ensure_exchange_init()

async def _unauth_ensure_exchange_init(self):
with self.error_describer():
# already called in _ensure_auth
await self.load_symbol_markets(
reload=not self.exchange_manager.use_cached_markets,
market_filter=self.exchange_manager.market_filter,
)

def get_adapter_class(self, adapter_class):
return adapter_class or ccxt_adapter.CCXTAdapter

Expand All @@ -118,15 +124,12 @@ def load_user_inputs_from_class(cls, tentacles_setup_config, tentacle_config):
# no user input in connector
pass

async def _load_markets(
self,
client,
reload: bool,
market_filter: typing.Optional[typing.Callable[[dict], bool]] = None
async def _filtered_if_necessary_load_markets(
self,
client,
reload: bool,
market_filter: typing.Optional[typing.Callable[[dict], bool]]
):
"""
Override if necessary
"""
try:
if self.exchange_manager.exchange.FETCH_MIN_EXCHANGE_MARKETS and market_filter:
with ccxt_client_util.filtered_fetched_markets(client, market_filter):
Expand All @@ -139,6 +142,17 @@ async def _load_markets(
raise ccxt_client_util.get_proxy_error_class(proxy_error)(proxy_error) from err
raise

async def _load_markets(
self,
client,
reload: bool,
market_filter: typing.Optional[typing.Callable[[dict], bool]] = None
):
"""
Override if necessary
"""
await self._filtered_if_necessary_load_markets(client, reload, market_filter)

@ccxt_client_util.converted_ccxt_common_errors
@connectors_util.retried_failed_network_request()
async def load_symbol_markets(
Expand Down Expand Up @@ -249,11 +263,7 @@ def add_options(self, options_dict):
async def _ensure_auth(self):
try:
# load markets before calling _ensure_auth() to avoid fetching markets status while they are cached
with self.error_describer():
await self.load_symbol_markets(
reload=not self.exchange_manager.use_cached_markets,
market_filter=self.exchange_manager.market_filter,
)
await self._unauth_ensure_exchange_init()
await self.exchange_manager.exchange.get_balance()
except (
octobot_trading.errors.AuthenticationError,
Expand Down