Skip to content

Commit 2f0da95

Browse files
authored
Raise AuthenticationError (#162)
1 parent 91e7bab commit 2f0da95

File tree

6 files changed

+38
-7
lines changed

6 files changed

+38
-7
lines changed

docs/source/Getting-Started.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,5 @@ Websocket client usage
193193
194194
asyncio.run(client.connect(handle_msg))
195195
196+
.. note::
197+
Raises :code:`AuthError` if invalid API key is provided.

docs/source/WebSocket-Enums.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.. _websocket_enums_header:
2+
3+
WebSocket Enums
4+
==============================
5+
6+
==============================================================
7+
Feed
8+
==============================================================
9+
.. autoclass:: polygon.websocket.models.Feed
10+
:members:
11+
:undoc-members:
12+
13+
==============================================================
14+
Market
15+
==============================================================
16+
.. autoclass:: polygon.websocket.models.Market
17+
:members:
18+
:undoc-members:
19+
20+
==============================================================
21+
EventType
22+
==============================================================
23+
.. autoclass:: polygon.websocket.models.EventType
24+
:members:
25+
:undoc-members:

docs/source/WebSockets.rst renamed to docs/source/WebSocket.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
.. _websockets_header:
1+
.. _websocket_header:
22

3-
WebSockets
3+
WebSocket
44
==========
55

66
===========

docs/source/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ This documentation is for the Python client only. For details about the response
99

1010
Getting-Started
1111
Aggs
12-
WebSockets
12+
WebSocket
1313
Snapshot
1414
Quotes
1515
Reference
1616
Trades
1717
vX
1818
Models
1919
Enums
20-
20+
WebSocket-Enums
2121

2222
Indices and tables
2323
==================

polygon/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .rest import RESTClient
2-
from .websocket import WebSocketClient
2+
from .websocket import WebSocketClient, AuthError

polygon/websocket/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
env_key = "POLYGON_API_KEY"
1414

1515

16+
class AuthError(Exception):
17+
pass
18+
19+
1620
class WebSocketClient:
1721
def __init__(
1822
self,
@@ -71,6 +75,7 @@ async def connect(
7175
7276
:param processor: The callback to process messages.
7377
:param close_timeout: How long to wait for handshake when calling .close.
78+
:raises AuthError: If invalid API key is supplied.
7479
"""
7580
reconnects = 0
7681
isasync = inspect.iscoroutinefunction(processor)
@@ -98,8 +103,7 @@ async def connect(
98103
if self.verbose:
99104
print("authed:", auth_msg)
100105
if auth_msg_parsed[0]["status"] == "auth_failed":
101-
print(auth_msg_parsed[0]["message"])
102-
return
106+
raise AuthError(auth_msg_parsed[0]["message"])
103107
while True:
104108
if self.schedule_resub:
105109
if self.verbose:

0 commit comments

Comments
 (0)