diff --git a/CHANGELOG.md b/CHANGELOG.md index b28f84b..cdd6140 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ 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). +## [1.2.30] - 2024-12-02 +### Updated +- [Binance] handle sandbox + ## [1.2.29] - 2024-10-02 ### Added - log on invalid creds diff --git a/README.md b/README.md index 7d3d1a8..1a73732 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# trading-backend [1.2.29](https://github.com/Drakkar-Software/trading-backend/tree/master/CHANGELOG.md) +# trading-backend [1.2.30](https://github.com/Drakkar-Software/trading-backend/tree/master/CHANGELOG.md) [![PyPI](https://img.shields.io/pypi/v/trading-backend.svg)](https://pypi.python.org/pypi/trading-backend/) [![Downloads](https://pepy.tech/badge/trading-backend/month)](https://pepy.tech/project/trading-backend) [![Github-Action-CI](https://github.com/Drakkar-Software/trading-backend/workflows/trading-backend-CI/badge.svg)](https://github.com/Drakkar-Software/trading-backend/actions) diff --git a/trading_backend/exchanges/binance.py b/trading_backend/exchanges/binance.py index 646bde6..083b813 100644 --- a/trading_backend/exchanges/binance.py +++ b/trading_backend/exchanges/binance.py @@ -81,6 +81,16 @@ async def _get_api_key_rights(self) -> list[trading_backend.enums.APIKeyRights]: restrictions = await self._exchange.connector.client.sapi_get_account_apirestrictions() except ValueError as err: raise ccxt.AuthenticationError(f"Invalid key format ({err})") + except ccxt.NotSupported: + if self._exchange.exchange_manager.is_sandboxed: + # API not available on testnet: return all rights + return [ + trading_backend.enums.APIKeyRights.READING, + trading_backend.enums.APIKeyRights.SPOT_TRADING, + trading_backend.enums.APIKeyRights.FUTURES_TRADING, + trading_backend.enums.APIKeyRights.MARGIN_TRADING, + ] + raise rights = [] if restrictions.get('enableReading'): rights.append(trading_backend.enums.APIKeyRights.READING) @@ -107,6 +117,15 @@ async def _inner_is_valid_account(self) -> (bool, str): if not details.get("ifNewUser", False): return False, "Binance requires accounts that were created after july 1st 2021, " \ "this account is too old." + except ccxt.NotSupported: + if self._exchange.exchange_manager.is_sandboxed: + # API not available on testnet + try: + await self._exchange.get_balance() + return True, None + except Exception as err: + raise ccxt.AuthenticationError(f"Invalid auth details ({err})") + raise except ValueError as err: raise ccxt.AuthenticationError(f"Invalid key format ({err})") except AttributeError: