Repository: ccxt/ccxt
Issue category: Bug Report

Issue:
binance myLiquidations uninitialized before accessed
### Operating System

Ubuntu

### Programming Languages

Python

### CCXT Version

4.4.27

### Description

Got following error while watching binance websocket.

### Code



```
2024-11-26 05:56:31,267 - 875 - exchanges.binance - ERROR - 'NoneType' object does not support item assignment
Traceback (most recent call last):
  File "/home/sytd/test/src/exchanges/future_exchange_base.py", line 118, in watch_balances
    event = await self._exchange.watch_balance()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sytd/test/.venv/lib/python3.11/site-packages/ccxt/pro/binance.py", line 2503, in watch_balance
    return await self.watch(url, messageHash, message, type)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sytd/test/.venv/lib/python3.11/site-packages/ccxt/async_support/base/ws/fast_client.py", line 27, in handler
    self.handle_message(message)
  File "/home/sytd/test/.venv/lib/python3.11/site-packages/ccxt/async_support/base/ws/aiohttp_client.py", line 34, in handle_message
    self.handle_text_or_binary_message(message.data)
  File "/home/sytd/test/.venv/lib/python3.11/site-packages/ccxt/async_support/base/ws/aiohttp_client.py", line 29, in handle_text_or_binary_message
    self.on_message_callback(self, decoded)
  File "/home/sytd/test/.venv/lib/python3.11/site-packages/ccxt/pro/binance.py", line 3966, in handle_message
    method(client, message)
  File "/home/sytd/test/.venv/lib/python3.11/site-packages/ccxt/pro/binance.py", line 3396, in handle_order_update
    self.handle_my_liquidation(client, message)
  File "/home/sytd/test/.venv/lib/python3.11/site-packages/ccxt/pro/binance.py", line 518, in handle_my_liquidation
    self.myLiquidations[symbol] = myLiquidations
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^
TypeError: 'NoneType' object does not support item assignment
```



Hints:
Hello @sytranvn,

Thanks for reporting it, we will fix it asap
@sytranvn Btw, what's the best way of reproducing the issue? 
I was just listening for balance events only. Maybe place a future position and wait for it to be liquidated.

Patch:
diff --git a/python/ccxt/base/exchange.py b/python/ccxt/base/exchange.py
index 9b79354f89c5..66f8170154a4 100644
--- a/python/ccxt/base/exchange.py
+++ b/python/ccxt/base/exchange.py
@@ -382,6 +382,7 @@ def __init__(self, config={}):
         self.transactions = dict() if self.transactions is None else self.transactions
         self.ohlcvs = dict() if self.ohlcvs is None else self.ohlcvs
         self.liquidations = dict() if self.liquidations is None else self.liquidations
+        self.myLiquidations = dict() if self.myLiquidations is None else self.myLiquidations
         self.currencies = dict() if self.currencies is None else self.currencies
         self.options = self.get_default_options() if self.options is None else self.options  # Python does not allow to define properties in run-time with setattr
         self.decimal_to_precision = decimal_to_precision


Test patch: