Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 111b4e6

Browse files
authored
Merge pull request #43 from slazarov/0.0.7.0
0.0.7.0
2 parents 8bd4c69 + ad621d3 commit 111b4e6

6 files changed

Lines changed: 58 additions & 7 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ if __name__ == "__main__":
413413
main()
414414
```
415415
# Change log
416+
0.0.7.0 - 25/02/2018
417+
* New reconnection methods implemented. Problem was within `gevent`, because connection failures within it are not raised in the main script.
418+
* Added wsaccel for better socket performance.
419+
* Set websocket-client minimum version to 0.47.0
420+
421+
wsaccel
416422
0.0.6.4 - 24/02/2018
417423
* Fixed order book syncing bug when more than 1 connection is online due to wrong connection/thread name.
418424

bittrex_websocket/_signalr.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import signalr
2+
import gevent
3+
from ._exceptions import WebSocketConnectionClosedException
4+
5+
6+
class Connection(signalr.Connection):
7+
def __init__(self, url, session):
8+
super(Connection, self).__init__(url, session)
9+
self.error_trap = None
10+
11+
def start(self):
12+
self.starting.fire()
13+
14+
negotiate_data = self.__transport.negotiate()
15+
self.token = negotiate_data['ConnectionToken']
16+
17+
listener = self.__transport.start()
18+
19+
def wrapped_listener():
20+
21+
# listener()
22+
# gevent.sleep()
23+
24+
try:
25+
listener()
26+
gevent.sleep()
27+
except Exception as e:
28+
self.close()
29+
self.error_trap = e
30+
31+
self.__greenlet = gevent.spawn(wrapped_listener)
32+
self.started = True
33+
34+
def wait(self, timeout=30):
35+
gevent.joinall([self.__greenlet], timeout)
36+
if self.error_trap is not None:
37+
return self.error_trap

bittrex_websocket/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@
4949
MSG_ERROR_SOCKET_WEBSOCKETCONNECTIONCLOSED = 'Please report error to ' \
5050
'https://github.com/slazarov/python-bittrex-websocket, ' \
5151
'Error:Init_connection_WebSocketConnectionClosedException'
52+
MSG_ERROR_GEVENT = _CONN_PREFIX + 'Caught {} in gevent. Don\'t worry.'
5253
MSG_ERROR_CONN_MISSING_SCHEMA = _CONN_PREFIX + 'Invalid URL: {}'
5354
MSG_ERROR_CONN_HTTP = _CONN_PREFIX + 'Failed to establish connection through {}'

bittrex_websocket/websocket_client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
from __future__ import print_function
88

9-
from signalr import Connection
9+
# from signalr import Connection
10+
from ._signalr import Connection
1011
import logging
1112
from abc import ABCMeta, abstractmethod
1213
from threading import Thread, current_thread
@@ -330,11 +331,15 @@ def is_next_url():
330331
# Add handlers
331332
corehub.client.on('updateExchangeState', self._on_tick_update)
332333
corehub.client.on('updateSummaryState', self._on_ticker_update)
333-
conn.wait(5400)
334+
run = conn.wait(5400)
334335
# When we purposely close the connection, the script will exit conn.wait()
335336
# so we need to inform the script that it should not try to reconnect.
336337
if conn_obj.close_me is True:
337338
return
339+
elif run is not None:
340+
logger.error(MSG_ERROR_GEVENT.format(conn_id, type(run)))
341+
self._empty_conn_id(conn_id)
342+
return
338343
is_next_url()
339344
except HTTPError:
340345
# Related to wrong url. Will be raised in case Bittrex changes it's url or you touched it!

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ cfscrape>=1.9.4
22
signalr-client==0.0.7
33
requests[security]==2.18.4
44
Events==0.3
5-
websocket-client==0.46.0
6-
gevent>=1.3a1
5+
websocket-client==0.47.0
6+
gevent>=1.3a1
7+
wsaccel>=0.6.2

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
'signalr-client==0.0.7',
99
'requests[security]==2.18.4',
1010
'Events==0.3',
11-
'websocket-client>=0.46.0',
12-
'gevent>=1.3a1'
11+
'websocket-client>=0.47.0',
12+
'gevent>=1.3a1',
13+
'wsaccel>=0.6.2'
1314
]
1415

1516
setup(
1617
name='bittrex_websocket',
17-
version='0.0.6.3',
18+
version='0.0.7.0',
1819
author='Stanislav Lazarov',
1920
author_email='s.a.lazarov@gmail.com',
2021
license='MIT',

0 commit comments

Comments
 (0)