Skip to content

Commit c8f801f

Browse files
committed
Reconnection bug.
1 parent 085f381 commit c8f801f

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ pip install bittrex-websocket-aio
5555
```
5656

5757
# Methods
58+
#### Custom URL
59+
Custom URLs can be passed to the client upon instantiating.
60+
```python
61+
# 'https://socket.bittrex.com/signalr' is currently Cloudflare protected
62+
# 'https://beta.bittrex.com/signalr' (DEFAULT) is not
63+
64+
# Create the socket instance
65+
ws = MySocket(url=None)
66+
# rest of your code
67+
```
5868
#### Subscribe Methods
5969
```python
6070
def subscribe_to_exchange_deltas(self, tickers):
@@ -153,6 +163,10 @@ def on_error(self, error):
153163
Check the examples folder.
154164

155165
# Change log
166+
0.0.0.2.5 - 22/04/2018
167+
* Custom urls can now be passed to the client
168+
* If `cfscrape` is installed, the client will automatically use it
169+
156170
0.0.2 - 14/04/2018
157171
* Implemented reconnection
158172
* Implemented private account-level methods. Check `authenticate(self, api_key, api_secret)`.

bittrex_websocket/websocket_client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,24 @@
1515
from ._exceptions import *
1616
from signalr_aio import Connection
1717

18+
try:
19+
from cfscrape import create_scraper as Session
20+
except ImportError:
21+
from requests import Session
22+
1823
logger = logging.getLogger(__name__)
1924

2025

2126
class BittrexSocket(WebSocket):
2227

23-
def __init__(self):
28+
def __init__(self, url=None):
2429
self.control_queue = None
2530
self.invokes = []
2631
self.tickers = None
2732
self.connection = None
2833
self.threads = []
2934
self.credentials = None
35+
self.url = BittrexParameters.URL if url is None else url
3036
self._start_main_thread()
3137

3238
def _start_main_thread(self):
@@ -50,7 +56,7 @@ def control_queue_handler(self):
5056
self.control_queue.task_done()
5157

5258
def _handle_connect(self):
53-
connection = Connection(BittrexParameters.URL)
59+
connection = Connection(BittrexParameters.URL, Session())
5460
hub = connection.register_hub(BittrexParameters.HUB)
5561
connection.received += self._on_debug
5662
connection.error += self.on_error
@@ -66,7 +72,7 @@ def _handle_connect(self):
6672

6773
def _connection_handler(self):
6874
try:
69-
logger.info('Establishing connection to Bittrex.')
75+
logger.info('Establishing connection to Bittrex through {}.'.format(self.url))
7076
self.connection.conn.start()
7177
except ConnectionClosed as e:
7278
if e.code == 1000:

examples/ticker_updates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
def main():
1919
class MySocket(BittrexSocket):
20-
def __init__(self):
21-
super().__init__()
20+
def __init__(self, url=None):
21+
super().__init__(url)
2222
self.ticker_updates_container = {}
2323

2424
async def on_public(self, msg):

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
uvloop>=0.9.1
21
websockets>=4.0.1
32
signalr-client-aio>=0.0.1.6.1

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
install_requires = \
66
[
7-
'uvloop>=0.9.1',
87
'websockets>=4.0.1',
98
'signalr-client-aio>=0.0.1.6.1'
109
]
1110

1211
setup(
1312
name='bittrex-websocket-aio',
14-
version='0.0.0.2.3',
13+
version='0.0.0.2.5',
1514
author='Stanislav Lazarov',
1615
author_email='[email protected]',
1716
license='MIT',

0 commit comments

Comments
 (0)