Skip to content

Commit

Permalink
Added options testnet websocket support - have not been able to test …
Browse files Browse the repository at this point in the history
…as no activity on the testnet...
  • Loading branch information
Ollie-Hooper committed Apr 9, 2021
1 parent 57d3416 commit 7e769f2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion binance/websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class BinanceSocketManager(threading.Thread):
STREAM_URL = 'wss://stream.binance.com:9443/'
FSTREAM_URL = 'wss://fstream.binance.com/'
VSTREAM_URL = 'wss://vstream.binance.com/'
VSTREAM_TESTNET_URL = 'wss://testnetws.binanceops.com/'

WEBSOCKET_DEPTH_5 = '5'
WEBSOCKET_DEPTH_10 = '10'
Expand All @@ -97,6 +98,8 @@ def __init__(self, client, user_timeout=DEFAULT_USER_TIMEOUT):
self._account_callbacks = {'user': None, 'margin': None}
# Isolated margin sockets will be opened under the 'symbol' name

self.testnet = self._client.testnet

def _start_socket(self, path, callback, prefix='ws/'):
if path in self._conns:
return False
Expand Down Expand Up @@ -132,7 +135,12 @@ def _start_options_socket(self, path, callback, prefix='ws/'):
if path in self._conns:
return False

factory_url = self.VSTREAM_URL + prefix + path
if self.testnet:
url = self.VSTREAM_TESTNET_URL
else:
url = self.VSTREAM_URL

factory_url = url + prefix + path
factory = BinanceClientFactory(factory_url)
factory.protocol = BinanceClientProtocol
factory.callback = callback
Expand Down

0 comments on commit 7e769f2

Please sign in to comment.