Skip to content

Commit 8c54311

Browse files
at-cfclickingbuttonsclickingbuttons
authored
feat: provide custom json module (#306)
* feat: provide custom json module * fix: custom json module missing/formatting * docs: provide custom json module * fix: custom json import typos * fixup examples Co-authored-by: clickingbuttons <[email protected]> Co-authored-by: zack <[email protected]>
1 parent 24764cd commit 8c54311

File tree

9 files changed

+168
-257
lines changed

9 files changed

+168
-257
lines changed

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
sphinx-autodoc-typehints~=1.18.1
1+
sphinx-autodoc-typehints~=1.19.2
22
websockets~=10.3

docs/source/Getting-Started.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ If it is a paginated :code:`list_*` response it's up to you to handle the "next_
5353

5454
.. literalinclude:: ../../examples/rest/raw-list.py
5555

56+
To provide your own JSON processing library (exposing loads/dumps functions) pass :code:`custom_json=my_module`:
57+
58+
.. literalinclude:: ../../examples/websocket/custom-json-get.py
59+
5660
WebSocket client usage
5761
----------------------
5862

@@ -80,3 +84,6 @@ To handle raw string or byte messages yourself pass :code:`raw=True`:
8084

8185
.. literalinclude:: ../../examples/websocket/raw.py
8286

87+
To provide your own JSON processing library (exposing loads/dumps functions) pass :code:`custom_json=my_module`:
88+
89+
.. literalinclude:: ../../examples/websocket/custom-json.py

examples/rest/custom-json-get.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from polygon import RESTClient
2+
3+
# type: ignore
4+
import orjson
5+
6+
client = RESTClient(custom_json=orjson)
7+
8+
aggs = client.get_aggs("AAPL", 1, "day", "2022-04-04", "2022-04-04")
9+
print(aggs)

examples/websocket/custom-json.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from polygon import WebSocketClient
2+
from polygon.websocket.models import WebSocketMessage
3+
from typing import List
4+
5+
# type: ignore
6+
import orjson
7+
8+
c = WebSocketClient(subscriptions=["T.*"], custom_json=orjson)
9+
10+
11+
def handle_msg(msgs: List[WebSocketMessage]):
12+
for m in msgs:
13+
print(m)
14+
15+
16+
c.run(handle_msg)

0 commit comments

Comments
 (0)