Skip to content

Commit 0efbbcb

Browse files
author
Sam McHardy
committed
Remove option for update time when creating websockets
1 parent d4b3e73 commit 0efbbcb

5 files changed

Lines changed: 12 additions & 48 deletions

File tree

‎binance/depthcache.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from operator import itemgetter
55

6-
from .enums import WEBSOCKET_UPDATE_0SECOND
76
from .websockets import BinanceSocketManager
87

98

@@ -153,7 +152,7 @@ def _init_cache(self):
153152
def _start_socket(self):
154153
self._bm = BinanceSocketManager(self._client)
155154

156-
self._bm.start_depth_socket(self._symbol, self._depth_event, update_time=WEBSOCKET_UPDATE_0SECOND)
155+
self._bm.start_depth_socket(self._symbol, self._depth_event)
157156

158157
self._bm.start()
159158

‎binance/enums.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
TIME_IN_FORCE_GTC = 'GTC' # Good till cancelled
3737
TIME_IN_FORCE_IOC = 'IOC' # Immediate or cancel
3838

39-
WEBSOCKET_UPDATE_0SECOND = '0ms'
40-
WEBSOCKET_UPDATE_1SECOND = '1000ms'
41-
4239
WEBSOCKET_DEPTH_1 = '1'
4340
WEBSOCKET_DEPTH_5 = '5'
4441
WEBSOCKET_DEPTH_10 = '10'

‎binance/websockets.py‎

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from twisted.internet.protocol import ReconnectingClientFactory
1212
from twisted.internet.error import ReactorAlreadyRunning
1313

14-
from .enums import KLINE_INTERVAL_1MINUTE, WEBSOCKET_UPDATE_1SECOND, WEBSOCKET_DEPTH_1
14+
from .enums import KLINE_INTERVAL_1MINUTE, WEBSOCKET_DEPTH_1
1515

1616
BINANCE_STREAM_URL = 'wss://stream.binance.com:9443/ws/'
1717

@@ -66,10 +66,7 @@ def __init__(self, client):
6666
self._user_listen_key = None
6767
self._client = client
6868

69-
def _start_socket(self, path, callback, update_time=WEBSOCKET_UPDATE_1SECOND):
70-
if update_time != WEBSOCKET_UPDATE_1SECOND:
71-
path = '{}@{}'.format(path, update_time)
72-
69+
def _start_socket(self, path, callback):
7370
if path in self._conns:
7471
return False
7572

@@ -81,7 +78,7 @@ def _start_socket(self, path, callback, update_time=WEBSOCKET_UPDATE_1SECOND):
8178
self._conns[path] = connectWS(factory, context_factory)
8279
return path
8380

84-
def start_depth_socket(self, symbol, callback, depth=WEBSOCKET_DEPTH_1, update_time=WEBSOCKET_UPDATE_1SECOND):
81+
def start_depth_socket(self, symbol, callback, depth=WEBSOCKET_DEPTH_1):
8582
"""Start a websocket for symbol market depth
8683
8784
https://www.binance.com/restapipub.html#depth-wss-endpoint
@@ -92,8 +89,6 @@ def start_depth_socket(self, symbol, callback, depth=WEBSOCKET_DEPTH_1, update_t
9289
:type callback: function
9390
:param depth: Number of depth entries to return, default WEBSOCKET_DEPTH_1
9491
:type depth: enum
95-
:param update_time: Update time interval, default WEBSOCKET_UPDATE_1SECOND
96-
:type update_time: enum
9792
9893
:returns: connection key string if successful, False otherwise
9994
@@ -135,9 +130,9 @@ def start_depth_socket(self, symbol, callback, depth=WEBSOCKET_DEPTH_1, update_t
135130
socket_name = symbol.lower() + '@depth'
136131
if depth != WEBSOCKET_DEPTH_1:
137132
socket_name = '{}{}'.format(socket_name, depth)
138-
return self._start_socket(socket_name, callback, update_time=update_time)
133+
return self._start_socket(socket_name, callback)
139134

140-
def start_kline_socket(self, symbol, callback, interval=KLINE_INTERVAL_1MINUTE, update_time=WEBSOCKET_UPDATE_1SECOND):
135+
def start_kline_socket(self, symbol, callback, interval=KLINE_INTERVAL_1MINUTE):
141136
"""Start a websocket for symbol kline data
142137
143138
https://www.binance.com/restapipub.html#kline-wss-endpoint
@@ -148,8 +143,6 @@ def start_kline_socket(self, symbol, callback, interval=KLINE_INTERVAL_1MINUTE,
148143
:type callback: function
149144
:param interval: Kline interval, default KLINE_INTERVAL_1MINUTE
150145
:type interval: enum
151-
:param update_time: Update time interval, default WEBSOCKET_UPDATE_1SECOND
152-
:type update_time: enum
153146
154147
:returns: connection key string if successful, False otherwise
155148
@@ -183,7 +176,7 @@ def start_kline_socket(self, symbol, callback, interval=KLINE_INTERVAL_1MINUTE,
183176
}
184177
"""
185178
socket_name = '{}@kline_{}'.format(symbol.lower(), interval)
186-
return self._start_socket(socket_name, callback, update_time=update_time)
179+
return self._start_socket(socket_name, callback)
187180

188181
def start_trade_socket(self, symbol, callback):
189182
"""Start a websocket for symbol trade data
@@ -216,17 +209,13 @@ def start_trade_socket(self, symbol, callback):
216209
"""
217210
return self._start_socket(symbol.lower() + '@trade', callback)
218211

219-
def start_ticker_socket(self, callback, update_time=WEBSOCKET_UPDATE_1SECOND):
212+
def start_ticker_socket(self, callback):
220213
"""Start a websocket for ticker data
221214
222215
By default all markets are included in an array.
223216
224-
Using a 0ms update time will split markets into separate messages.
225-
226217
:param callback: callback function to handle messages
227218
:type callback: function
228-
:param update_time: Update time interval, default WEBSOCKET_UPDATE_1SECOND
229-
:type update_time: enum
230219
231220
:returns: connection key string if successful, False otherwise
232221
@@ -260,17 +249,15 @@ def start_ticker_socket(self, callback, update_time=WEBSOCKET_UPDATE_1SECOND):
260249
}
261250
]
262251
"""
263-
return self._start_socket('!ticker@arr', callback, update_time=update_time)
252+
return self._start_socket('!ticker@arr', callback)
264253

265-
def start_user_socket(self, callback, update_time=WEBSOCKET_UPDATE_1SECOND):
254+
def start_user_socket(self, callback):
266255
"""Start a websocket for user data
267256
268257
https://www.binance.com/restapipub.html#user-wss-endpoint
269258
270259
:param callback: callback function to handle messages
271260
:type callback: function
272-
:param update_time: Update time interval, default WEBSOCKET_UPDATE_1SECOND
273-
:type update_time: enum
274261
275262
:returns: connection key string if successful, False otherwise
276263
@@ -283,7 +270,7 @@ def start_user_socket(self, callback, update_time=WEBSOCKET_UPDATE_1SECOND):
283270
self.stop_socket(conn_key)
284271
break
285272
self._user_listen_key = self._client.stream_get_listen_key()
286-
conn_key = self._start_socket(self._user_listen_key, callback, update_time=update_time)
273+
conn_key = self._start_socket(self._user_listen_key, callback)
287274
if conn_key:
288275
# start timer to keep socket alive
289276
self._start_user_timer()

‎docs/enums.rst‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ Binance defines Enumerated Types for Order Types, Order Side, Time in Force and
4040
TIME_IN_FORCE_GTC = 'GTC'
4141
TIME_IN_FORCE_IOC = 'IOC'
4242
43-
WEBSOCKET_UPDATE_0SECOND = '0ms'
44-
WEBSOCKET_UPDATE_1SECOND = '1000ms'
45-
4643
WEBSOCKET_DEPTH_1 = '1'
4744
WEBSOCKET_DEPTH_5 = '5'
4845
WEBSOCKET_DEPTH_10 = '10'

‎docs/websockets.rst‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,6 @@ Messages are received as dictionary objects relating to the message formats defi
1414

1515
Websockets are setup to reconnect with a maximum of 5 retries.
1616

17-
Websocket Update Time
18-
---------------------
19-
20-
By default sockets push aggregated content once a second.
21-
22-
When creating a sockets there is an `update_time` parameter, with valid values being 0ms and 1000ms `defined as enums <enums.html>`_.
23-
24-
Using 0ms forces the socket to send updates as soon as they are available.
25-
26-
An example of setting the update time to 0ms is shown below for the Ticker Socket.
27-
28-
This parameter is not available for the Trade Socket.
29-
3017
Websocket Usage
3118
---------------
3219

@@ -78,8 +65,6 @@ Valid interval values are `defined as enums <enums.html>`_.
7865
`Aggregated Trade Socket <binance.html#binance.websockets.BinanceSocketManager.start_trade_socket>`_
7966
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8067

81-
This socket does not support the `update_time` parameter
82-
8368
.. code:: python
8469
8570
conn_key = bm.start_trade_socket('BNBBTC', process_message)
@@ -90,8 +75,7 @@ This socket does not support the `update_time` parameter
9075

9176
.. code:: python
9277
93-
from binance.enums import *
94-
conn_key = bm.start_ticker_socket(process_message, update_time=WEBSOCKET_UPDATE_0SECOND)
78+
conn_key = bm.start_ticker_socket(process_message)
9579
9680
9781
`User Socket <binance.html#binance.websockets.BinanceSocketManager.start_user_socket>`_

0 commit comments

Comments
 (0)