From 2a507c4ef3c971aac05feaf73bdf44a1ad324b4a Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Sun, 17 Nov 2024 13:26:01 +0100 Subject: [PATCH 1/2] [IndexTrading] add rebalance logs --- Trading/Mode/index_trading_mode/index_trading.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Trading/Mode/index_trading_mode/index_trading.py b/Trading/Mode/index_trading_mode/index_trading.py index 4c96501dc..82c06d78c 100644 --- a/Trading/Mode/index_trading_mode/index_trading.py +++ b/Trading/Mode/index_trading_mode/index_trading.py @@ -64,10 +64,19 @@ async def _rebalance_portfolio(self, details: dict): orders = [] try: # 1. make sure we can actually rebalance the portfolio + self.logger.info("Step 1/3: ensuring enough funds are available for rebalance") await self._ensure_enough_funds_to_buy_after_selling() # 2. sell indexed coins for reference market + self.logger.info( + f"Step 2/3: selling coins to free " + f"{self.exchange_manager.exchange_personal_data.portfolio_manager.reference_market}" + ) orders += await self._sell_indexed_coins_for_reference_market(details) # 3. split reference market into indexed coins + self.logger.info( + f"Step 3/3: buying coins using " + f"{self.exchange_manager.exchange_personal_data.portfolio_manager.reference_market}" + ) orders += await self._split_reference_market_into_indexed_coins(details) except trading_errors.MissingMinimalExchangeTradeVolume as err: self.logger.warning(f"Aborting rebalance on {self.exchange_manager.exchange_name}: {err}") @@ -75,6 +84,8 @@ async def _rebalance_portfolio(self, details: dict): IndexActivity.REBALANCING_SKIPPED, RebalanceSkipDetails.NOT_ENOUGH_AVAILABLE_FOUNDS.value ) + finally: + self.logger.info("Portoflio rebalance complete") return orders async def _sell_indexed_coins_for_reference_market(self, details: dict) -> list: From 431832924a2df32f7b8cbf6fe88dd72e0846c453 Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Sun, 17 Nov 2024 15:13:25 +0100 Subject: [PATCH 2/2] [Coinbase] handle ccxt ignored errors --- Trading/Exchange/coinbase/coinbase_exchange.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Trading/Exchange/coinbase/coinbase_exchange.py b/Trading/Exchange/coinbase/coinbase_exchange.py index ed85da940..0a0f379e9 100644 --- a/Trading/Exchange/coinbase/coinbase_exchange.py +++ b/Trading/Exchange/coinbase/coinbase_exchange.py @@ -116,6 +116,15 @@ class Coinbase(exchanges.RestExchange): # "User is not allowed to convert crypto","message":"User is not allowed to convert crypto"} ("user is not allowed to convert crypto", ), ] + # text content of errors due to exchange internal synch (like when portfolio is not yet up to date after a trade) + EXCHANGE_INTERNAL_SYNC_ERRORS: typing.List[typing.Iterable[str]] = [ + # BadRequest coinbase {"error":"INVALID_ARGUMENT","error_details":"account is not available","message":"account is not available"} + ("account is not available", ) + ] + # text content of errors due to missing fnuds when creating an order (when not identified as such by ccxt) + EXCHANGE_MISSING_FUNDS_ERRORS: typing.List[typing.Iterable[str]] = [ + ("insufficient balance in source account", ) + ] @classmethod def get_name(cls):