Skip to content

Commit 7e769f2

Browse files
committed
Added options testnet websocket support - have not been able to test as no activity on the testnet...
1 parent 57d3416 commit 7e769f2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

binance/websockets.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class BinanceSocketManager(threading.Thread):
7272
STREAM_URL = 'wss://stream.binance.com:9443/'
7373
FSTREAM_URL = 'wss://fstream.binance.com/'
7474
VSTREAM_URL = 'wss://vstream.binance.com/'
75+
VSTREAM_TESTNET_URL = 'wss://testnetws.binanceops.com/'
7576

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

101+
self.testnet = self._client.testnet
102+
100103
def _start_socket(self, path, callback, prefix='ws/'):
101104
if path in self._conns:
102105
return False
@@ -132,7 +135,12 @@ def _start_options_socket(self, path, callback, prefix='ws/'):
132135
if path in self._conns:
133136
return False
134137

135-
factory_url = self.VSTREAM_URL + prefix + path
138+
if self.testnet:
139+
url = self.VSTREAM_TESTNET_URL
140+
else:
141+
url = self.VSTREAM_URL
142+
143+
factory_url = url + prefix + path
136144
factory = BinanceClientFactory(factory_url)
137145
factory.protocol = BinanceClientProtocol
138146
factory.callback = callback

0 commit comments

Comments
 (0)