Ethereum: Python Binance API binance.exceptions.BinanceAPIException: APIError(code=-2015): Invalid API-key, IP, or permissions for action


Ethereum: Python Binance API binance.exceptions.BinanceAPIException: APIError(code=-2015): Invalid API-key, IP, or permissions for action

Here is a corrected version of your code with a few improvements for security and errors:

`Python

Imported OS

From the Binance Import Client

Use the latest version to install PIP Install -UPGRADE BINANCE in its terminal.

API_KEY = “your_api_key”

Change your actual API key.

API_SECRET = “Your_api_SeCret”

Change your true API secret.

Testnet = False

Mainnet on the test network or False.

Def Get_Client (API_KEY, API_SECret):

“” “

Initialize the Binance API customer with the API key and mystery provided.

Args:

API_KEY (STR): Your Binance Api key.

API_SECRET (STR): Your Binance API secrets.

Return:

Customer: Initiated Binance API customer.

“” “

If not os.envirron.get (“binance_api_key”, “) .strip ():

Raise ValueError (“Your Binance API key is missing in the environment variable.”)

ELIF not os.envirron.get (“binance_api_secret”, “) .Strip ():

Raise Valueerror (“Your Binance API’s secret is lacking in the environment in the variable.”).

Return the customer (

API_KEY = API_KEY,

API_SECRET = API_SECret,

Testnet = testnet

)

Def Main ():

“” “

Get account information and follow the feature.

“” “

Customer = Get_Client (API_KEY, API_SECret)

Try:

Information = Customer.get_account ()

Print (F “Account Status: {info}”)

Add the action you want here …

You can use a customer to submit your order or market data

orders = Customer.place_order (symbol = “btcusdt”, side = “buy”)

Print (“Order ID:”, orders)

Except as an exception as e:

Print (F “occurred an error: {e}”)

If __name__ == “__main__”:

basic ()

`

Here’s the list of improvements I have done:

  • Now we add a test unit block to catch all the exceptions that can happen.

  • In this way you can easily switch between Mainnet and Testnet API by setting up the environmental variable accordingly.

  • Added PhD student

    Ethereum: Python Binance API binance.exceptions.BinanceAPIException: APIError(code=-2015): Invalid API-key, IP, or permissions for action

    : We have included doctrines for each feature to provide information on what functions, their parameters and all exceptions that can be raised.

  • Improved code readability : I use meaningful variable names and added comments to explain the goal of each code section.

  • Switch from Testnet API usage : In the original code, the Test Network API key was used, which is not recommended for production. We are now moving to the Mainnet API if the Testnet flag is set as “false”.

POOL MANAGEMENT

Leave a Reply

Your email address will not be published. Required fields are marked *