sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
5.98k stars 2.2k forks source link

Error in connecting Binance testnet; API Secret required for private endpoints #1194

Closed maromato closed 2 years ago

maromato commented 2 years ago

When I tried to connect Binance testnet, I had a secret key issue. Does anybody know how to fix this?

api_key = os.environ.get('API KEY FOR TESTNET')
api_secret = os.environ.get('SCRET KEY FOR TESTNET')
client = Client(api_key, api_secret, testnet=True)
client.API_URL = 'https://testnet.binance.vision/api'
# get balances for all assets & some account information

print(client.get_account())

gave an error as below.

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
[<ipython-input-55-846f84a8d6eb>](https://localhost:8080/#) in <module>()
      1 # get balances for all assets & some account information
----> 2 print(client.get_account())

5 frames
[/usr/local/lib/python3.7/dist-packages/binance/client.py](https://localhost:8080/#) in _generate_signature(self, data)
    218 
    219     def _generate_signature(self, data: Dict) -> str:
--> 220         assert self.API_SECRET, "API Secret required for private endpoints"
    221         ordered_data = self._order_params(data)
    222         query_string = '&'.join([f"{d[0]}={d[1]}" fo

However, the code below gave a correct response.

btc_price = client.get_symbol_ticker(symbol="BTCUSDT")

print(btc_price)

{'symbol': 'BTCUSDT', 'price': '29186.56000000'}

I think this would be a secret key recognition issue??

Environment (please complete the following information):

maromato commented 2 years ago

Sorry. The below worked 👍

# init
api_key = 'API KEY FOR TESTNET'
api_secret ='SECRET KEY FOR TESTNET'
client = Client(api_key, api_secret, testnet=True)
client.API_URL = 'https://testnet.binance.vision/api'
#client.API_URL = 'https://testnet.binancefuture.com