From a96eeb25d291a59c7faf524cbc2a161a6c05f50d Mon Sep 17 00:00:00 2001 From: Deepak Pandey Date: Fri, 3 Apr 2026 01:00:14 +0530 Subject: [PATCH] docs: add error handling example to README Added error handling section with example code for API exceptions. --- README.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.rst b/README.rst index 48efec45..cb7d7def 100755 --- a/README.rst +++ b/README.rst @@ -156,6 +156,22 @@ pass `testnet=True` when creating the client. # get a deposit address for BTC address = client.get_deposit_address(coin='BTC') +# Error Handling +It's a best practice to handle API exceptions to prevent your app from crashing during network issues or invalid requests. + +```python +from binance.exceptions import BinanceAPIException, BinanceOrderException + +try: + # Example: Fetching a non-existent symbol to trigger an error + ticker = client.get_symbol_ticker(symbol="INVALID_SYMBOL") +except BinanceAPIException as e: + # Handles errors returned by the Binance API + print(f"API Error: {e.status_code} - {e.message}") +except Exception as e: + # Handles other Python related errors + print(f"An unexpected error occurred: {e}") + # get historical kline data from any date range # fetch 1 minute klines for the last day up until now