n1nj4z33 / iqoptionapi

IQ Option API 4.x (Python 2.7) The project is obsolete and is not supported because of problems with access to IQ Options in Russia
120 stars 545 forks source link

api.buy, api.getcandles and api.profile.balance produces WebSocketConnectionClosedException #15

Open Olascoaga opened 7 years ago

Olascoaga commented 7 years ago

I was trying to use the api and really i getting it, it works greatly but i have only one trouble, after some time of use api.getcandles or api.profile.balance or api.buy it is produced an exception in websocket

this is the exception:

File "C:\Python\lib\site-packages\websocket\_socket.py", line 113, in send
    raise WebSocketConnectionClosedException("socket is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: socket is already closed. 

I was trying to handle it with try-except and recovery the connection but i can't if i try to use the api.connect method after the exception looks like it is connected but if i use any function return the same exception, so how to reconnect the api after an exception like this

Niks005 commented 7 years ago

Something like this

def reconnect(self):
        if(self.websocket):
            self.websocket.close()
        self.websocket_client.wss = None
        self.set_session_cookies()
        self.websocket_client = WebsocketClient(self)
        websocket_thread = threading.Thread(target=self.websocket.run_forever)
        websocket_thread.daemon = True
        websocket_thread.start()
        time.sleep(5)
        self.ssid(self.sid)
Olascoaga commented 7 years ago

thanks a lot

keinbuck commented 6 years ago

I added the previous lines to

api.py.

If I use

api.reconnect()

I get the error:

AttributeError: 'IQOptionApi' object has no attribute 'sid'

I replaced it with ssid and get another error. Can someone help please how do use the reconnection correctly?