Closed andreixk closed 6 years ago
I tried the alpha with the url https://socket.bittrex.com/signalr instead of self.url = 'https://socket-stage.bittrex.com/signalr which gave me a connection
Yes, they work interchangeably, unless Bittrex denies the connection. Is this problem solved?
I made yesterday some experiments with the network monitor of firefox. Both websocket and http protocol using a sort of ping. The http api seems to need a request for a file version.txt. I had problems with this api, because the data was always 3 to 4 minutes too old and the call LatestTick is not documented. But I was able to implement the call. I will try to implement the request for the version.txt to get data which is not older than 1minute.
The websocket protocol seems to need a "ping". I saw a ping which is the telegram of the ascii string "ping" to the server. We should investigate further, before we make conclusions. I will work on a fork of the bittrex api, which is used by Bittrex to build the chart, until this api is usable. Because to get all necessary data it needs web socket and the http api.
If this is becoming successful we should merge the projects
@rako233 with respect to the 'ping', do you mean that the websocket needs to ping the server to stay on? I have tested it for a hours in the past and the order flow was up to date. You are right, we should do further testing, I plan to release the revamped code this week.
With respect to API requests, maybe we should have a joined topic with https://github.com/ericsomdahl/python-bittrex since it handles API requests and also the two libraries are still independent for the time being.
I have the suspicion these pings are used for detecting of users like us. Your proposal to work together with ericsomdahl is a good one. The goal should providing a package to record historic data with a Blaze or pandas interface.
So I implemented the request for the version.txt and get_latest_tick for 1min and still no change. The data is always delayed. I shouldn't have done that because even the online charts are delayed.
Periodically I am getting this error as well (using socket.bittrex.com
url), just wondering if it's related:
File "/lib/python3.6/site-packages/websocket/_socket.py", line 93, in recv
"Connection is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
Wed Dec 6 11:37:09 2017 <Greenlet at 0x104b2c508: wrapped_listener> failed with WebSocketConnectionClosedException
Full stack trace:
File "/lib/python3.6/site-packages/gevent/greenlet.py", line 536, in run
result = self._run(*self.args, **self.kwargs)
File "/lib/python3.6/site-packages/signalr/_connection.py", line 53, in wrapped_listener
listener()
File "/lib/python3.6/site-packages/signalr/transports/_ws_transport.py", line 42, in _receive
for notification in self.ws:
File "/lib/python3.6/site-packages/websocket/_core.py", line 105, in __iter__
yield self.recv()
File "/lib/python3.6/site-packages/websocket/_core.py", line 293, in recv
opcode, data = self.recv_data()
File "/lib/python3.6/site-packages/websocket/_core.py", line 310, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "/lib/python3.6/site-packages/websocket/_core.py", line 323, in recv_data_frame
frame = self.recv_frame()
File "/lib/python3.6/site-packages/websocket/_core.py", line 357, in recv_frame
return self.frame_buffer.recv_frame()
File "/lib/python3.6/site-packages/websocket/_abnf.py", line 340, in recv_frame
self.recv_header()
File "/lib/python3.6/site-packages/websocket/_abnf.py", line 288, in recv_header
header = self.recv_strict(2)
File "/lib/python3.6/site-packages/websocket/_abnf.py", line 375, in recv_strict
bytes_ = self.recv(min(16384, shortage))
File "/lib/python3.6/site-packages/websocket/_core.py", line 427, in _recv
return recv(self.sock, bufsize)
File "/lib/python3.6/site-packages/websocket/_socket.py", line 93, in recv
"Connection is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
Wed Dec 6 11:37:09 2017 <Greenlet at 0x104b2c508: wrapped_listener> failed with WebSocketConnectionClosedExceptio
Are you closing the socket with ws.close()
prematurely?
On average how much time passes before you receive websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
I've left the socket to run for hours before closing it and haven't experienced that error. Are you sure your internet connection is not being disconnected?
Nevertheless, there are plans to integrate reconnection.
I have ws.close()
at the very end of the .py file (which should only be reached if i press ctrl+c). so if it closed, it would've exited, but it stays running after that error. it happens after about an hour of running. Also, I noticed, this issue does NOT happen on http://socket-stage.bittrex.com for some reason (when that URL works).
@andreixk v0.0.2 has been pushed, please reinstall and post back. Make sure you check the updated documentation because there have been some major changes to how the socket functions.
In my experience http://socket-stage.bittrex.com has always been more stable. I have added it as the primary connection URL.
Issue still happens, but after about 5-6 hours of connection. after the error, although it says connection established, there are no updates coming through
Traceback (most recent call last):
File "/lib/python3.6/site-packages/gevent/greenlet.py", line 536, in run
result = self._run(*self.args, **self.kwargs)
File "/lib/python3.6/site-packages/signalr/_connection.py", line 53, in wrapped_listener
listener()
File "/lib/python3.6/site-packages/signalr/transports/_ws_transport.py", line 42, in _receive
for notification in self.ws:
File "/lib/python3.6/site-packages/websocket/_core.py", line 105, in __iter__
yield self.recv()
File "/lib/python3.6/site-packages/websocket/_core.py", line 293, in recv
opcode, data = self.recv_data()
File "/lib/python3.6/site-packages/websocket/_core.py", line 310, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "/lib/python3.6/site-packages/websocket/_core.py", line 323, in recv_data_frame
frame = self.recv_frame()
File "/lib/python3.6/site-packages/websocket/_core.py", line 357, in recv_frame
return self.frame_buffer.recv_frame()
File "/lib/python3.6/site-packages/websocket/_abnf.py", line 340, in recv_frame
self.recv_header()
File "/lib/python3.6/site-packages/websocket/_abnf.py", line 288, in recv_header
header = self.recv_strict(2)
File "/lib/python3.6/site-packages/websocket/_abnf.py", line 375, in recv_strict
bytes_ = self.recv(min(16384, shortage))
File "/lib/python3.6/site-packages/websocket/_core.py", line 427, in _recv
return recv(self.sock, bufsize)
File "/lib/python3.6/site-packages/websocket/_socket.py", line 93, in recv
"Connection is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
Fri Dec 15 07:30:19 2017 <Greenlet at 0x1073d6800: wrapped_listener> failed with WebSocketConnectionClosedException
DEBUG:root:Trying to establish connection to Bittrex through https://socket.bittrex.com/signalr.
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): socket.bittrex.com
DEBUG:urllib3.connectionpool:https://socket.bittrex.com:443 "GET /signalr/negotiate?connectionData=%5B%7B%22name%22%3A+%22coreHub%22%7D%5D&clientProtocol=1.5 HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:https://socket.bittrex.com:443 "GET /signalr/start?transport=webSockets&connectionToken=9Nmo1LoMNWiYMm6o4z68S4FWgRdo7oJZol0rFUF%2FhB4zYFz2D1PwdbVo8YKb6uMkWOODLuEiUJr4uIRCmmn%2BNmnAl1a4gKsY0XE9VfV%2B3IH0HmI&connectionData=%5B%7B%22name%22%3A+%22coreHub%22%7D%5D&clientProtocol=1.5 HTTP/1.1" 200 None
DEBUG:root:Connection to Bittrex established successfully through https://socket.bittrex.com/signalr.
I haven't applied reconnection mechanisms yet, they are in order. For the time being, apply own logic to check if connection is active and restart the whole socket.
I made a test yesterday and the reconnect worked. Anyway tje JS code on the webpage makes a HTTPS request for https://bittrex.com/Content/version.txt every minute and a ping via
https://socket.bittrex.com/signalr/ping?_=
Maybe you can get it with cfscrape?
Running your examples yields:
530 Server Error: for url: http://socket-stage.bittrex.com/signalr/negotiate?connectionData=%5B%7B%22name%22%3A+%22coreHub%22%7D%5D&clientProtocol=1.5 Failed to establish connection