Skip to content

Commit 2297b75

Browse files
committed
docs: update websocket error docs (sammchardy#1591)
* add timeout to jobs * docs: update websocket errors docs * revert change
1 parent adc24e0 commit 2297b75

1 file changed

Lines changed: 44 additions & 6 deletions

File tree

docs/websockets.rst

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,23 +216,61 @@ can do this.
216216
Websocket Errors
217217
----------------
218218

219-
If an error occurs, a message is sent to the callback to indicate this. The format is
219+
If an error occurs, a message is sent to the callback to indicate this. The format is:
220220

221221
.. code:: python
222222
223223
{
224224
'e': 'error',
225-
'type': 'BinanceWebsocketUnableToConnect',
226-
'm': 'Max reconnect retries reached'
225+
'type': '<ErrorType>',
226+
'm': '<Error message>'
227227
}
228228
229-
# check for it like so
229+
Where:
230+
- `'e'`: Always `'error'` for error messages.
231+
- `'type'`: The type of error encountered (see table below).
232+
- `'m'`: A human-readable error message.
233+
234+
**Possible Error Types:**
235+
236+
+-------------------------------+--------------------------------------------------------------+-------------------------------+
237+
| Type | Description | Typical Action |
238+
+===============================+==============================================================+===============================+
239+
| BinanceWebsocketUnableToConnect| The websocket could not connect after maximum retries. | Check network, restart socket |
240+
+-------------------------------+--------------------------------------------------------------+-------------------------------+
241+
| BinanceWebsocketClosed | The websocket connection was closed. The system will attempt | Usually auto-reconnects |
242+
| | to reconnect automatically. | |
243+
+-------------------------------+--------------------------------------------------------------+-------------------------------+
244+
| BinanceWebsocketQueueOverflow | The internal message queue exceeded its maximum size | Process messages faster, or |
245+
| | (default 100). | increase queue size |
246+
+-------------------------------+--------------------------------------------------------------+-------------------------------+
247+
| CancelledError | The websocket task was cancelled (e.g., on shutdown). | Usually safe to ignore |
248+
+-------------------------------+--------------------------------------------------------------+-------------------------------+
249+
| IncompleteReadError | The websocket connection was interrupted during a read. | Will attempt to reconnect |
250+
+-------------------------------+--------------------------------------------------------------+-------------------------------+
251+
| gaierror | Network address-related error (e.g., DNS failure). | Check network |
252+
+-------------------------------+--------------------------------------------------------------+-------------------------------+
253+
| ConnectionClosedError | The websocket connection was closed unexpectedly. | Will attempt to reconnect |
254+
+-------------------------------+--------------------------------------------------------------+-------------------------------+
255+
| *Other Exception Types* | Any other unexpected error. | Check error message |
256+
+-------------------------------+--------------------------------------------------------------+-------------------------------+
257+
258+
**Example error handling in your callback:**
259+
260+
.. code:: python
261+
230262
def process_message(msg):
231-
if msg['e'] == 'error':
232-
# close and restart the socket
263+
if msg.get('e') == 'error':
264+
print(f"WebSocket error: {msg.get('type')} - {msg.get('m')}")
265+
# Optionally close and restart the socket, or handle as needed
233266
else:
234267
# process message normally
235268
269+
**Notes:**
270+
- Most connection-related errors will trigger automatic reconnection attempts up to 5 times.
271+
- If the queue overflows, consider increasing `max_queue_size` or processing messages more quickly.
272+
- For persistent errors, check your network connection and API credentials.
273+
236274
Websocket Examples
237275
----------------
238276

0 commit comments

Comments
 (0)