from pymexc import futures
from config import MEXC_API_KEY, MEXC_API_SECRET
def handle_message(message):
print(message)
futures_client = futures.HTTP(api_key=MEXC_API_KEY, api_secret=MEXC_API_SECRET)
ws_futures_client = futures.WebSocket(api_key=MEXC_API_KEY, api_secret=MEXC_API_SECRET)
print(futures_client.index_price("MX_USDT"))
while True:
pass
Getting the "Connection is already closed" exception:
{'success': True, 'code': 0, 'data': {'symbol': 'MX_USDT', 'indexPrice': 4.437, 'timestamp': 1728500725624}}
Exception in thread Thread-2 (<lambda>):
Traceback (most recent call last):
File "C:\Users\pisun\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
self.run()
File "C:\Users\pisun\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\pisun\crypto\pybye\venv\Lib\site-packages\pymexc\base_websocket.py", line 151, in <lambda>
self.wsl = threading.Thread(target=lambda: self._ping_loop(
^^^^^^^^^^^^^^^^
File "C:\Users\pisun\crypto\pybye\venv\Lib\site-packages\pymexc\base_websocket.py", line 101, in _ping_loop
self.ws.send(ping_payload)
File "C:\Users\pisun\crypto\pybye\venv\Lib\site-packages\websocket\_app.py", line 291, in send
raise WebSocketConnectionClosedException("Connection is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
Trying to run:
Getting the "Connection is already closed" exception: