Skip to content

Bug: Sub-account transfers fail with AttributeError or APIError on v1.0.29 #1592

Open
@ImpactoVerdeResponsable

Description

Environment Details

  • python-binance version: 1.0.29
  • Python version: 3.11
  • Operating System: Windows

Bug Description

When trying to transfer assets between a master account and a sub-account, multiple methods fail, making the operation impossible on version 1.0.29. The universal_transfer function, as well as specific functions like sub_account_transfer_to_master, seem to be broken or have a signature mismatch with the current Binance API requirements.

We tried the following methods to perform a Sub-Account to Main Account transfer, and all of them failed:

  1. client.sub_account_transfer(..., type=2) -> AttributeError
  2. client.universal_transfer(..., type="SUB_MAIN") -> APIError(code=-1102): Mandatory parameter 'type' was not sent...
  3. client.universal_transfer(..., fromAccountType='SPOT', ...) -> APIError(code=-1102): Mandatory parameter 'type' was not sent...
  4. client.sub_account_transfer_to_master(...) -> AttributeError

This indicates a deep issue with how the library handles this specific SAPI endpoint.

Steps to Reproduce

This minimal script reproduces the final error we encountered. It attempts to transfer a small amount of SOL from a sub-account to the master account.

# Prerequisite: A .env file with valid master account API keys
# BINANCE_API_KEY="YOUR_KEY"
# BINANCE_API_SECRET="YOUR_SECRET"

import os
from dotenv import load_dotenv
from binance.client import Client
from binance.exceptions import BinanceAPIException

load_dotenv()

API_KEY = os.environ.get('BINANCE_API_KEY')
API_SECRET = os.environ.get('BINANCE_API_SECRET')
# This should be a real sub-account email linked to the master account
SUBACCOUNT_EMAIL = "[email protected]" 

client = Client(API_KEY, API_SECRET)

print("Attempting to transfer 0.001 SOL from Sub-Account to Master Account...")

try:
    # This call fails with AttributeError in v1.0.29
    # client.sub_account_transfer_to_master(asset='SOL', amount=0.001)

    # This call also fails with APIError(code=-1102) in v1.0.29
    client.universal_transfer(
        fromEmail=SUBACCOUNT_EMAIL,
        asset='SOL',
        amount=0.001,
        type="SUB_MAIN"
    )

    print("Transfer successful!")

except BinanceAPIException as e:
    print(f"ERROR: Transfer failed with BinanceAPIException.")
    print(f" -> Status Code: {e.status_code}")
    print(f" -> Error Code: {e.code}")
    print(f" -> Error Message: {e.message}")
except AttributeError as e:
    print(f"ERROR: Transfer failed with AttributeError.")
    print(f" -> Error Message: {e}")

Expected Behavior
The script should successfully execute the transfer from the sub-account to the master account without errors.

Actual Behavior
The script fails with the following error, indicating the type parameter is not being sent correctly by the library, even when specified.

ERROR: Transfer failed with BinanceAPIException.
 -> Status Code: 400
 -> Error Code: -1102
 -> Error Message: Mandatory parameter 'type' was not sent, was empty/null, or malformed.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions