Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sand #69

Merged
merged 2 commits into from
Dec 4, 2024
Merged

Sand #69

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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
19 changes: 19 additions & 0 deletions trading_backend/exchanges/binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
Loading