From 7a232157f15a9236ac154771bb96fb115f891e74 Mon Sep 17 00:00:00 2001 From: cf <64846322+at-cf@users.noreply.github.com> Date: Mon, 26 Sep 2022 18:14:59 -0300 Subject: [PATCH 1/5] feat: provide custom json module --- polygon/rest/base.py | 7 ++++++- polygon/websocket/__init__.py | 17 +++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/polygon/rest/base.py b/polygon/rest/base.py index 8afbd330..f56e416d 100644 --- a/polygon/rest/base.py +++ b/polygon/rest/base.py @@ -28,6 +28,7 @@ def __init__( retries: int, base: str, verbose: bool, + custom_json: Optional[Any] = None ): if api_key is None: raise AuthError( @@ -51,9 +52,13 @@ def __init__( self.retries = retries if verbose: logger.setLevel(logging.DEBUG) + if custom_json: + self.json = custom_json + else: + self.json = json def _decode(self, resp): - return json.loads(resp.data.decode("utf-8")) + return self.json.loads(resp.data.decode("utf-8")) def _get( self, diff --git a/polygon/websocket/__init__.py b/polygon/websocket/__init__.py index 66a9dd9a..0bda5326 100644 --- a/polygon/websocket/__init__.py +++ b/polygon/websocket/__init__.py @@ -1,6 +1,6 @@ import os from enum import Enum -from typing import Optional, Union, List, Set, Callable, Awaitable +from typing import Optional, Union, List, Set, Callable, Awaitable, Any import logging import json import asyncio @@ -28,6 +28,7 @@ def __init__( subscriptions: Optional[List[str]] = None, max_reconnects: Optional[int] = 5, secure: bool = True, + custom_json: Optional[Any] = None, **kwargs, ): """ @@ -65,6 +66,10 @@ def __init__( subscriptions = [] self.scheduled_subs: Set[str] = set(subscriptions) self.schedule_resub = True + if custom_json: + self.json = custom_json + else: + self.json = json # https://websockets.readthedocs.io/en/stable/reference/client.html#opening-a-connection async def connect( @@ -99,9 +104,9 @@ async def connect( msg = await s.recv() logger.debug("connected: %s", msg) logger.debug("authing...") - await s.send(json.dumps({"action": "auth", "params": self.api_key})) + await s.send(self.json.dumps({"action": "auth", "params": self.api_key})) auth_msg = await s.recv() - auth_msg_parsed = json.loads(auth_msg) + auth_msg_parsed = self.json.loads(auth_msg) logger.debug("authed: %s", auth_msg) if auth_msg_parsed[0]["status"] == "auth_failed": raise AuthError(auth_msg_parsed[0]["message"]) @@ -127,7 +132,7 @@ async def connect( if not self.raw: # we know cmsg is Data - msgJson = json.loads(cmsg) # type: ignore + msgJson = self.json.loads(cmsg) # type: ignore for m in msgJson: if m["ev"] == "status": logger.debug("status: %s", m["message"]) @@ -176,14 +181,14 @@ async def _subscribe(self, topics: Union[List[str], Set[str]]): return subs = ",".join(topics) logger.debug("subbing: %s", subs) - await self.websocket.send(json.dumps({"action": "subscribe", "params": subs})) + await self.websocket.send(self.json.dumps({"action": "subscribe", "params": subs})) async def _unsubscribe(self, topics: Union[List[str], Set[str]]): if self.websocket is None or len(topics) == 0: return subs = ",".join(topics) logger.debug("unsubbing: %s", subs) - await self.websocket.send(json.dumps({"action": "unsubscribe", "params": subs})) + await self.websocket.send(self.json.dumps({"action": "unsubscribe", "params": subs})) @staticmethod def _parse_subscription(s: str): From c1198dc847f105eecc325f48f6d6148c84896e65 Mon Sep 17 00:00:00 2001 From: cf <64846322+at-cf@users.noreply.github.com> Date: Sat, 1 Oct 2022 10:26:17 -0300 Subject: [PATCH 2/5] fix: custom json module missing/formatting --- examples/custom_json/orjson.py | 13 +++++++++++++ examples/rest/custom-json-get.py | 7 +++++++ examples/websocket/custom-json.py | 14 ++++++++++++++ polygon/rest/__init__.py | 3 +++ polygon/rest/base.py | 4 ++-- polygon/websocket/__init__.py | 5 +++-- 6 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 examples/custom_json/orjson.py create mode 100644 examples/rest/custom-json-get.py create mode 100644 examples/websocket/custom-json.py diff --git a/examples/custom_json/orjson.py b/examples/custom_json/orjson.py new file mode 100644 index 00000000..aa4016ba --- /dev/null +++ b/examples/custom_json/orjson.py @@ -0,0 +1,13 @@ +import orjson # https://github.com/ijl/orjson + +# this demonstrates wrapping orjson json parsing library +# (wrapping required since orjson decodes to bytes) +# other json libraries can often be used directly + + +def loads(o, **kwargs): + return orjson.loads(o) + + +def dumps(o, **kwargs): + return orjson.dumps(o).decode("utf-8") diff --git a/examples/rest/custom-json-get.py b/examples/rest/custom-json-get.py new file mode 100644 index 00000000..324b2838 --- /dev/null +++ b/examples/rest/custom-json-get.py @@ -0,0 +1,7 @@ +from polygon import RESTClient +from examples.custom_json import orjson + +client = RESTClient(custom_json=orjson) + +aggs = client.get_aggs("AAPL", 1, "day", "2022-04-04", "2022-04-04") +print(aggs) diff --git a/examples/websocket/custom-json.py b/examples/websocket/custom-json.py new file mode 100644 index 00000000..bdab223e --- /dev/null +++ b/examples/websocket/custom-json.py @@ -0,0 +1,14 @@ +from polygon import WebSocketClient +from polygon.websocket.models import WebSocketMessage +from typing import List +from examples.custom_json import orjson + +c = WebSocketClient(subscriptions=["T.*"], custom_json=orjson) + + +def handle_msg(msgs: List[WebSocketMessage]): + for m in msgs: + print(m) + + +c.run(handle_msg) diff --git a/polygon/rest/__init__.py b/polygon/rest/__init__.py index a7cdbf95..b7c42a97 100644 --- a/polygon/rest/__init__.py +++ b/polygon/rest/__init__.py @@ -44,6 +44,7 @@ def __init__( retries: int = 3, base: str = BASE, verbose: bool = False, + custom_json: Optional[Any] = None ): super().__init__( api_key=api_key, @@ -53,6 +54,7 @@ def __init__( retries=retries, base=base, verbose=verbose, + custom_json=custom_json, ) self.vx = VXClient( api_key=api_key, @@ -62,4 +64,5 @@ def __init__( retries=retries, base=base, verbose=verbose, + custom_json=custom_json, ) diff --git a/polygon/rest/base.py b/polygon/rest/base.py index f56e416d..6f0f0454 100644 --- a/polygon/rest/base.py +++ b/polygon/rest/base.py @@ -53,9 +53,9 @@ def __init__( if verbose: logger.setLevel(logging.DEBUG) if custom_json: - self.json = custom_json + self.json = custom_json else: - self.json = json + self.json = json def _decode(self, resp): return self.json.loads(resp.data.decode("utf-8")) diff --git a/polygon/websocket/__init__.py b/polygon/websocket/__init__.py index 0bda5326..c7934de4 100644 --- a/polygon/websocket/__init__.py +++ b/polygon/websocket/__init__.py @@ -40,6 +40,7 @@ def __init__( :param verbose: Whether to log client and server status messages. :param subscriptions: List of subscription parameters. :param max_reconnects: How many times to reconnect on network outage before ending .connect event loop. + :param custom_json: Optional module exposing loads/dumps functions (similar to Python's json module) to be used for JSON conversions. :return: A client. """ if api_key is None: @@ -67,9 +68,9 @@ def __init__( self.scheduled_subs: Set[str] = set(subscriptions) self.schedule_resub = True if custom_json: - self.json = custom_json + self.json = custom_json else: - self.json = json + self.json = json # https://websockets.readthedocs.io/en/stable/reference/client.html#opening-a-connection async def connect( From bcb879d46f5b81b7fad01b0c819d6b4f56845da0 Mon Sep 17 00:00:00 2001 From: cf <64846322+at-cf@users.noreply.github.com> Date: Sat, 1 Oct 2022 10:27:49 -0300 Subject: [PATCH 3/5] docs: provide custom json module --- docs/source/Getting-Started.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/source/Getting-Started.rst b/docs/source/Getting-Started.rst index 15b9321e..a723f93f 100644 --- a/docs/source/Getting-Started.rst +++ b/docs/source/Getting-Started.rst @@ -53,6 +53,10 @@ If it is a paginated :code:`list_*` response it's up to you to handle the "next_ .. literalinclude:: ../../examples/rest/raw-list.py +To provide your own JSON processing library (exposing loads/dumps functions) pass :code:`custom_json=my_module`: + +.. literalinclude:: ../../examples/websocket/custom-json-get.py + WebSocket client usage ---------------------- @@ -80,3 +84,6 @@ To handle raw string or byte messages yourself pass :code:`raw=True`: .. literalinclude:: ../../examples/websocket/raw.py +To provide your own JSON processing library (exposing loads/dumps functions) pass :code:`custom_json=my_module`: + +.. literalinclude:: ../../examples/websocket/custom-json.py From 43426a20da336d38056b724a400a5d1bbd42ac37 Mon Sep 17 00:00:00 2001 From: cf <64846322+at-cf@users.noreply.github.com> Date: Wed, 5 Oct 2022 17:10:43 -0300 Subject: [PATCH 4/5] fix: custom json import typos --- examples/rest/custom-json-get.py | 4 ++-- examples/websocket/custom-json.py | 4 ++-- polygon/rest/__init__.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/rest/custom-json-get.py b/examples/rest/custom-json-get.py index 324b2838..424f8f55 100644 --- a/examples/rest/custom-json-get.py +++ b/examples/rest/custom-json-get.py @@ -1,7 +1,7 @@ from polygon import RESTClient -from examples.custom_json import orjson +from examples import custom_json -client = RESTClient(custom_json=orjson) +client = RESTClient(custom_json=custom_json) aggs = client.get_aggs("AAPL", 1, "day", "2022-04-04", "2022-04-04") print(aggs) diff --git a/examples/websocket/custom-json.py b/examples/websocket/custom-json.py index bdab223e..fac7f8fc 100644 --- a/examples/websocket/custom-json.py +++ b/examples/websocket/custom-json.py @@ -1,9 +1,9 @@ from polygon import WebSocketClient from polygon.websocket.models import WebSocketMessage from typing import List -from examples.custom_json import orjson +from examples import custom_json -c = WebSocketClient(subscriptions=["T.*"], custom_json=orjson) +c = WebSocketClient(subscriptions=["T.*"], custom_json=custom_json) def handle_msg(msgs: List[WebSocketMessage]): diff --git a/polygon/rest/__init__.py b/polygon/rest/__init__.py index b7c42a97..c2dfb442 100644 --- a/polygon/rest/__init__.py +++ b/polygon/rest/__init__.py @@ -13,7 +13,7 @@ ContractsClient, ) from .vX import VXClient -from typing import Optional +from typing import Optional, Any import os From deed25343d7a6fbb034428f587d042db86a4daf2 Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Fri, 28 Oct 2022 17:37:40 -0400 Subject: [PATCH 5/5] fixup examples --- docs/requirements.txt | 2 +- examples/custom_json/orjson.py | 13 --- examples/rest/custom-json-get.py | 6 +- examples/websocket/custom-json.py | 6 +- poetry.lock | 161 +++++++++--------------------- polygon/rest/__init__.py | 2 +- polygon/rest/base.py | 2 +- polygon/websocket/__init__.py | 12 ++- pyproject.toml | 1 + 9 files changed, 68 insertions(+), 137 deletions(-) delete mode 100644 examples/custom_json/orjson.py diff --git a/docs/requirements.txt b/docs/requirements.txt index b72deef5..e8c712fd 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,2 +1,2 @@ -sphinx-autodoc-typehints~=1.18.1 +sphinx-autodoc-typehints~=1.19.2 websockets~=10.3 diff --git a/examples/custom_json/orjson.py b/examples/custom_json/orjson.py deleted file mode 100644 index aa4016ba..00000000 --- a/examples/custom_json/orjson.py +++ /dev/null @@ -1,13 +0,0 @@ -import orjson # https://github.com/ijl/orjson - -# this demonstrates wrapping orjson json parsing library -# (wrapping required since orjson decodes to bytes) -# other json libraries can often be used directly - - -def loads(o, **kwargs): - return orjson.loads(o) - - -def dumps(o, **kwargs): - return orjson.dumps(o).decode("utf-8") diff --git a/examples/rest/custom-json-get.py b/examples/rest/custom-json-get.py index 424f8f55..c10d0a03 100644 --- a/examples/rest/custom-json-get.py +++ b/examples/rest/custom-json-get.py @@ -1,7 +1,9 @@ from polygon import RESTClient -from examples import custom_json -client = RESTClient(custom_json=custom_json) +# type: ignore +import orjson + +client = RESTClient(custom_json=orjson) aggs = client.get_aggs("AAPL", 1, "day", "2022-04-04", "2022-04-04") print(aggs) diff --git a/examples/websocket/custom-json.py b/examples/websocket/custom-json.py index fac7f8fc..a659e767 100644 --- a/examples/websocket/custom-json.py +++ b/examples/websocket/custom-json.py @@ -1,9 +1,11 @@ from polygon import WebSocketClient from polygon.websocket.models import WebSocketMessage from typing import List -from examples import custom_json -c = WebSocketClient(subscriptions=["T.*"], custom_json=custom_json) +# type: ignore +import orjson + +c = WebSocketClient(subscriptions=["T.*"], custom_json=orjson) def handle_msg(msgs: List[WebSocketMessage]): diff --git a/poetry.lock b/poetry.lock index 015cff68..ab8c5f15 100644 --- a/poetry.lock +++ b/poetry.lock @@ -15,10 +15,10 @@ optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [package.extras] -dev = ["cloudpickle", "coverage[toml] (>=5.0.2)", "furo", "hypothesis", "mypy", "pre-commit", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "six", "sphinx", "sphinx-notfound-page", "zope.interface"] -docs = ["furo", "sphinx", "sphinx-notfound-page", "zope.interface"] -tests = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "six", "zope.interface"] -tests_no_zope = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "six"] +dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit", "cloudpickle"] +docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] +tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "cloudpickle"] +tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "cloudpickle"] [[package]] name = "babel" @@ -139,9 +139,9 @@ python-versions = ">=3.7" zipp = ">=0.5" [package.extras] -docs = ["jaraco.packaging (>=9)", "rst.linker (>=1.9)", "sphinx"] +docs = ["sphinx", "jaraco.packaging (>=9)", "rst.linker (>=1.9)"] perf = ["ipython"] -testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.0.1)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf (>=0.9.2)"] +testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pyfakefs", "flufl.flake8", "pytest-perf (>=0.9.2)", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)", "importlib-resources (>=1.3)"] [[package]] name = "importlib-resources" @@ -155,8 +155,8 @@ python-versions = ">=3.7" zipp = {version = ">=3.1.0", markers = "python_version < \"3.10\""} [package.extras] -docs = ["jaraco.packaging (>=9)", "rst.linker (>=1.9)", "sphinx"] -testing = ["pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.0.1)", "pytest-flake8", "pytest-mypy (>=0.9.1)"] +docs = ["sphinx", "jaraco.packaging (>=9)", "rst.linker (>=1.9)"] +testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)"] [[package]] name = "jinja2" @@ -234,6 +234,14 @@ python-versions = "*" [package.dependencies] six = ">=1.8.0" +[[package]] +name = "orjson" +version = "3.8.1" +description = "Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy" +category = "dev" +optional = false +python-versions = ">=3.7" + [[package]] name = "packaging" version = "21.3" @@ -262,8 +270,8 @@ optional = false python-versions = ">=3.7" [package.extras] -docs = ["furo (>=2021.7.5b38)", "proselint (>=0.10.2)", "sphinx (>=4)", "sphinx-autodoc-typehints (>=1.12)"] -test = ["appdirs (==1.4.4)", "pytest (>=6)", "pytest-cov (>=2.7)", "pytest-mock (>=3.6)"] +docs = ["furo (>=2021.7.5b38)", "proselint (>=0.10.2)", "sphinx-autodoc-typehints (>=1.12)", "sphinx (>=4)"] +test = ["appdirs (==1.4.4)", "pytest-cov (>=2.7)", "pytest-mock (>=3.6)", "pytest (>=6)"] [[package]] name = "pook" @@ -295,7 +303,7 @@ optional = false python-versions = ">=3.6.8" [package.extras] -diagrams = ["jinja2", "railroad-diagrams"] +diagrams = ["railroad-diagrams", "jinja2"] [[package]] name = "pyrsistent" @@ -348,7 +356,7 @@ optional = false python-versions = "*" [[package]] -name = "Sphinx" +name = "sphinx" version = "5.2.3" description = "Python documentation generator" category = "dev" @@ -376,8 +384,8 @@ sphinxcontrib-serializinghtml = ">=1.1.5" [package.extras] docs = ["sphinxcontrib-websupport"] -lint = ["docutils-stubs", "flake8 (>=3.5.0)", "flake8-bugbear", "flake8-comprehensions", "flake8-simplify", "isort", "mypy (>=0.981)", "sphinx-lint", "types-requests", "types-typed-ast"] -test = ["cython", "html5lib", "pytest (>=4.6)", "typed_ast"] +lint = ["flake8 (>=3.5.0)", "flake8-comprehensions", "flake8-bugbear", "flake8-simplify", "isort", "mypy (>=0.981)", "sphinx-lint", "docutils-stubs", "types-typed-ast", "types-requests"] +test = ["pytest (>=4.6)", "html5lib", "typed-ast", "cython"] [[package]] name = "sphinx-autodoc-typehints" @@ -407,7 +415,7 @@ docutils = "<0.18" sphinx = ">=1.6" [package.extras] -dev = ["bump2version", "sphinxcontrib-httpdomain", "transifex-client"] +dev = ["transifex-client", "sphinxcontrib-httpdomain", "bump2version"] [[package]] name = "sphinxcontrib-applehelp" @@ -418,7 +426,7 @@ optional = false python-versions = ">=3.5" [package.extras] -lint = ["docutils-stubs", "flake8", "mypy"] +lint = ["flake8", "mypy", "docutils-stubs"] test = ["pytest"] [[package]] @@ -430,7 +438,7 @@ optional = false python-versions = ">=3.5" [package.extras] -lint = ["docutils-stubs", "flake8", "mypy"] +lint = ["flake8", "mypy", "docutils-stubs"] test = ["pytest"] [[package]] @@ -442,8 +450,8 @@ optional = false python-versions = ">=3.6" [package.extras] -lint = ["docutils-stubs", "flake8", "mypy"] -test = ["html5lib", "pytest"] +lint = ["flake8", "mypy", "docutils-stubs"] +test = ["pytest", "html5lib"] [[package]] name = "sphinxcontrib-jsmath" @@ -454,7 +462,7 @@ optional = false python-versions = ">=3.5" [package.extras] -test = ["flake8", "mypy", "pytest"] +test = ["pytest", "flake8", "mypy"] [[package]] name = "sphinxcontrib-qthelp" @@ -465,7 +473,7 @@ optional = false python-versions = ">=3.5" [package.extras] -lint = ["docutils-stubs", "flake8", "mypy"] +lint = ["flake8", "mypy", "docutils-stubs"] test = ["pytest"] [[package]] @@ -477,7 +485,7 @@ optional = false python-versions = ">=3.5" [package.extras] -lint = ["docutils-stubs", "flake8", "mypy"] +lint = ["flake8", "mypy", "docutils-stubs"] test = ["pytest"] [[package]] @@ -529,8 +537,8 @@ optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, <4" [package.extras] -brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"] -secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "ipaddress", "pyOpenSSL (>=0.14)", "urllib3-secure-extra"] +brotli = ["brotlicffi (>=0.8.0)", "brotli (>=1.0.9)", "brotlipy (>=0.6.0)"] +secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "urllib3-secure-extra", "ipaddress"] socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] [[package]] @@ -558,13 +566,13 @@ optional = false python-versions = ">=3.7" [package.extras] -docs = ["jaraco.packaging (>=9)", "rst.linker (>=1.9)", "sphinx"] -testing = ["func-timeout", "jaraco.itertools", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.0.1)", "pytest-flake8", "pytest-mypy (>=0.9.1)"] +docs = ["sphinx", "jaraco.packaging (>=9)", "rst.linker (>=1.9)"] +testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)"] [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "bfc00d1ae1ef2a1b942958071d18ae46ff153a5cf60e62c91d1874e7ef47b803" +content-hash = "942105a0735db0c6d96be7ad18d13b46a9f1ddb0a0abf6afb1e52447f3fb539b" [metadata.files] alabaster = [ @@ -579,35 +587,8 @@ babel = [ {file = "Babel-2.10.1-py3-none-any.whl", hash = "sha256:3f349e85ad3154559ac4930c3918247d319f21910d5ce4b25d439ed8693b98d2"}, {file = "Babel-2.10.1.tar.gz", hash = "sha256:98aeaca086133efb3e1e2aad0396987490c8425929ddbcfe0550184fdc54cd13"}, ] -black = [ - {file = "black-22.8.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:ce957f1d6b78a8a231b18e0dd2d94a33d2ba738cd88a7fe64f53f659eea49fdd"}, - {file = "black-22.8.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:5107ea36b2b61917956d018bd25129baf9ad1125e39324a9b18248d362156a27"}, - {file = "black-22.8.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:e8166b7bfe5dcb56d325385bd1d1e0f635f24aae14b3ae437102dedc0c186747"}, - {file = "black-22.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dd82842bb272297503cbec1a2600b6bfb338dae017186f8f215c8958f8acf869"}, - {file = "black-22.8.0-cp310-cp310-win_amd64.whl", hash = "sha256:d839150f61d09e7217f52917259831fe2b689f5c8e5e32611736351b89bb2a90"}, - {file = "black-22.8.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:a05da0430bd5ced89176db098567973be52ce175a55677436a271102d7eaa3fe"}, - {file = "black-22.8.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4a098a69a02596e1f2a58a2a1c8d5a05d5a74461af552b371e82f9fa4ada8342"}, - {file = "black-22.8.0-cp36-cp36m-win_amd64.whl", hash = "sha256:5594efbdc35426e35a7defa1ea1a1cb97c7dbd34c0e49af7fb593a36bd45edab"}, - {file = "black-22.8.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:a983526af1bea1e4cf6768e649990f28ee4f4137266921c2c3cee8116ae42ec3"}, - {file = "black-22.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3b2c25f8dea5e8444bdc6788a2f543e1fb01494e144480bc17f806178378005e"}, - {file = "black-22.8.0-cp37-cp37m-win_amd64.whl", hash = "sha256:78dd85caaab7c3153054756b9fe8c611efa63d9e7aecfa33e533060cb14b6d16"}, - {file = "black-22.8.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:cea1b2542d4e2c02c332e83150e41e3ca80dc0fb8de20df3c5e98e242156222c"}, - {file = "black-22.8.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:5b879eb439094751185d1cfdca43023bc6786bd3c60372462b6f051efa6281a5"}, - {file = "black-22.8.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:0a12e4e1353819af41df998b02c6742643cfef58282915f781d0e4dd7a200411"}, - {file = "black-22.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c3a73f66b6d5ba7288cd5d6dad9b4c9b43f4e8a4b789a94bf5abfb878c663eb3"}, - {file = "black-22.8.0-cp38-cp38-win_amd64.whl", hash = "sha256:e981e20ec152dfb3e77418fb616077937378b322d7b26aa1ff87717fb18b4875"}, - {file = "black-22.8.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:8ce13ffed7e66dda0da3e0b2eb1bdfc83f5812f66e09aca2b0978593ed636b6c"}, - {file = "black-22.8.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:32a4b17f644fc288c6ee2bafdf5e3b045f4eff84693ac069d87b1a347d861497"}, - {file = "black-22.8.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:0ad827325a3a634bae88ae7747db1a395d5ee02cf05d9aa7a9bd77dfb10e940c"}, - {file = "black-22.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:53198e28a1fb865e9fe97f88220da2e44df6da82b18833b588b1883b16bb5d41"}, - {file = "black-22.8.0-cp39-cp39-win_amd64.whl", hash = "sha256:bc4d4123830a2d190e9cc42a2e43570f82ace35c3aeb26a512a2102bce5af7ec"}, - {file = "black-22.8.0-py3-none-any.whl", hash = "sha256:d2c21d439b2baf7aa80d6dd4e3659259be64c6f49dfd0f32091063db0e006db4"}, - {file = "black-22.8.0.tar.gz", hash = "sha256:792f7eb540ba9a17e8656538701d3eb1afcb134e3b45b71f20b25c77a8db7e6e"}, -] -certifi = [ - {file = "certifi-2022.9.24-py3-none-any.whl", hash = "sha256:90c1a32f1d68f940488354e36370f6cca89f0f106db09518524c88d6ed83f382"}, - {file = "certifi-2022.9.24.tar.gz", hash = "sha256:0d9c601124e5a6ba9712dbc60d9c53c21e34f5f641fe83002317394311bdce14"}, -] +black = [] +certifi = [] charset-normalizer = [ {file = "charset-normalizer-2.0.12.tar.gz", hash = "sha256:2857e29ff0d34db842cd7ca3230549d1a697f96ee6d3fb071cfa6c7393832597"}, {file = "charset_normalizer-2.0.12-py3-none-any.whl", hash = "sha256:6881edbebdb17b39b4eaaa821b438bf6eddffb4468cf344f09f89def34a8b1df"}, @@ -616,10 +597,7 @@ click = [ {file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"}, {file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"}, ] -colorama = [ - {file = "colorama-0.4.5-py2.py3-none-any.whl", hash = "sha256:854bf444933e37f5824ae7bfc1e98d5bce2ebe4160d46b5edf346a89358e99da"}, - {file = "colorama-0.4.5.tar.gz", hash = "sha256:e6c6b4334fc50988a639d9b98aa429a0b57da6e17b9a44f0451f930b6967b7a4"}, -] +colorama = [] docutils = [ {file = "docutils-0.17.1-py2.py3-none-any.whl", hash = "sha256:cf316c8370a737a022b72b56874f6602acf974a37a9fba42ec2876387549fc61"}, {file = "docutils-0.17.1.tar.gz", hash = "sha256:686577d2e4c32380bb50cbb22f575ed742d58168cee37e99117a854bcd88f125"}, @@ -694,32 +672,7 @@ markupsafe = [ {file = "MarkupSafe-2.1.1-cp39-cp39-win_amd64.whl", hash = "sha256:46d00d6cfecdde84d40e572d63735ef81423ad31184100411e6e3388d405e247"}, {file = "MarkupSafe-2.1.1.tar.gz", hash = "sha256:7f91197cc9e48f989d12e4e6fbc46495c446636dfc81b9ccf50bb0ec74b91d4b"}, ] -mypy = [ - {file = "mypy-0.982-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:5085e6f442003fa915aeb0a46d4da58128da69325d8213b4b35cc7054090aed5"}, - {file = "mypy-0.982-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:41fd1cf9bc0e1c19b9af13a6580ccb66c381a5ee2cf63ee5ebab747a4badeba3"}, - {file = "mypy-0.982-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:f793e3dd95e166b66d50e7b63e69e58e88643d80a3dcc3bcd81368e0478b089c"}, - {file = "mypy-0.982-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:86ebe67adf4d021b28c3f547da6aa2cce660b57f0432617af2cca932d4d378a6"}, - {file = "mypy-0.982-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:175f292f649a3af7082fe36620369ffc4661a71005aa9f8297ea473df5772046"}, - {file = "mypy-0.982-cp310-cp310-win_amd64.whl", hash = "sha256:8ee8c2472e96beb1045e9081de8e92f295b89ac10c4109afdf3a23ad6e644f3e"}, - {file = "mypy-0.982-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:58f27ebafe726a8e5ccb58d896451dd9a662a511a3188ff6a8a6a919142ecc20"}, - {file = "mypy-0.982-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d6af646bd46f10d53834a8e8983e130e47d8ab2d4b7a97363e35b24e1d588947"}, - {file = "mypy-0.982-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:e7aeaa763c7ab86d5b66ff27f68493d672e44c8099af636d433a7f3fa5596d40"}, - {file = "mypy-0.982-cp37-cp37m-win_amd64.whl", hash = "sha256:724d36be56444f569c20a629d1d4ee0cb0ad666078d59bb84f8f887952511ca1"}, - {file = "mypy-0.982-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:14d53cdd4cf93765aa747a7399f0961a365bcddf7855d9cef6306fa41de01c24"}, - {file = "mypy-0.982-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:26ae64555d480ad4b32a267d10cab7aec92ff44de35a7cd95b2b7cb8e64ebe3e"}, - {file = "mypy-0.982-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:6389af3e204975d6658de4fb8ac16f58c14e1bacc6142fee86d1b5b26aa52bda"}, - {file = "mypy-0.982-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7b35ce03a289480d6544aac85fa3674f493f323d80ea7226410ed065cd46f206"}, - {file = "mypy-0.982-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:c6e564f035d25c99fd2b863e13049744d96bd1947e3d3d2f16f5828864506763"}, - {file = "mypy-0.982-cp38-cp38-win_amd64.whl", hash = "sha256:cebca7fd333f90b61b3ef7f217ff75ce2e287482206ef4a8b18f32b49927b1a2"}, - {file = "mypy-0.982-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:a705a93670c8b74769496280d2fe6cd59961506c64f329bb179970ff1d24f9f8"}, - {file = "mypy-0.982-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:75838c649290d83a2b83a88288c1eb60fe7a05b36d46cbea9d22efc790002146"}, - {file = "mypy-0.982-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:91781eff1f3f2607519c8b0e8518aad8498af1419e8442d5d0afb108059881fc"}, - {file = "mypy-0.982-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eaa97b9ddd1dd9901a22a879491dbb951b5dec75c3b90032e2baa7336777363b"}, - {file = "mypy-0.982-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:a692a8e7d07abe5f4b2dd32d731812a0175626a90a223d4b58f10f458747dd8a"}, - {file = "mypy-0.982-cp39-cp39-win_amd64.whl", hash = "sha256:eb7a068e503be3543c4bd329c994103874fa543c1727ba5288393c21d912d795"}, - {file = "mypy-0.982-py3-none-any.whl", hash = "sha256:1021c241e8b6e1ca5a47e4d52601274ac078a89845cfde66c6d5f769819ffa1d"}, - {file = "mypy-0.982.tar.gz", hash = "sha256:85f7a343542dc8b1ed0a888cdd34dca56462654ef23aa673907305b260b3d746"}, -] +mypy = [] mypy-extensions = [ {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, @@ -728,6 +681,7 @@ orderedmultidict = [ {file = "orderedmultidict-1.0.1-py2.py3-none-any.whl", hash = "sha256:43c839a17ee3cdd62234c47deca1a8508a3f2ca1d0678a3bf791c87cf84adbf3"}, {file = "orderedmultidict-1.0.1.tar.gz", hash = "sha256:04070bbb5e87291cc9bfa51df413677faf2141c73c61d2a5f7b26bea3cd882ad"}, ] +orjson = [] packaging = [ {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, @@ -749,10 +703,7 @@ pygments = [ {file = "Pygments-2.12.0-py3-none-any.whl", hash = "sha256:dc9c10fb40944260f6ed4c688ece0cd2048414940f1cea51b8b226318411c519"}, {file = "Pygments-2.12.0.tar.gz", hash = "sha256:5eb116118f9612ff1ee89ac96437bb6b49e8f04d8a13b514ba26f620208e26eb"}, ] -pyparsing = [ - {file = "pyparsing-3.0.9-py3-none-any.whl", hash = "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"}, - {file = "pyparsing-3.0.9.tar.gz", hash = "sha256:2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb"}, -] +pyparsing = [] pyrsistent = [ {file = "pyrsistent-0.18.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:df46c854f490f81210870e509818b729db4488e1f30f2a1ce1698b2295a878d1"}, {file = "pyrsistent-0.18.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5d45866ececf4a5fff8742c25722da6d4c9e180daa7b405dc0a2a2790d668c26"}, @@ -792,14 +743,8 @@ snowballstemmer = [ {file = "snowballstemmer-2.2.0-py2.py3-none-any.whl", hash = "sha256:c8e1716e83cc398ae16824e5572ae04e0d9fc2c6b985fb0f900f5f0c96ecba1a"}, {file = "snowballstemmer-2.2.0.tar.gz", hash = "sha256:09b16deb8547d3412ad7b590689584cd0fe25ec8db3be37788be3810cbf19cb1"}, ] -Sphinx = [ - {file = "Sphinx-5.2.3.tar.gz", hash = "sha256:5b10cb1022dac8c035f75767799c39217a05fc0fe2d6fe5597560d38e44f0363"}, - {file = "sphinx-5.2.3-py3-none-any.whl", hash = "sha256:7abf6fabd7b58d0727b7317d5e2650ef68765bbe0ccb63c8795fa8683477eaa2"}, -] -sphinx-autodoc-typehints = [ - {file = "sphinx_autodoc_typehints-1.19.2-py3-none-any.whl", hash = "sha256:3d761de928d5a86901331133d6d4a2552afa2e798ebcfc0886791792aeb4dd9a"}, - {file = "sphinx_autodoc_typehints-1.19.2.tar.gz", hash = "sha256:872fb2d7b3d794826c28e36edf6739e93549491447dcabeb07c58855e9f914de"}, -] +sphinx = [] +sphinx-autodoc-typehints = [] sphinx-rtd-theme = [ {file = "sphinx_rtd_theme-1.0.0-py2.py3-none-any.whl", hash = "sha256:4d35a56f4508cfee4c4fb604373ede6feae2a306731d533f409ef5c3496fdbd8"}, {file = "sphinx_rtd_theme-1.0.0.tar.gz", hash = "sha256:eec6d497e4c2195fa0e8b2016b337532b8a699a68bcb22a512870e16925c6a5c"}, @@ -832,26 +777,14 @@ tomli = [ {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] -types-certifi = [ - {file = "types-certifi-2021.10.8.3.tar.gz", hash = "sha256:72cf7798d165bc0b76e1c10dd1ea3097c7063c42c21d664523b928e88b554a4f"}, - {file = "types_certifi-2021.10.8.3-py3-none-any.whl", hash = "sha256:b2d1e325e69f71f7c78e5943d410e650b4707bb0ef32e4ddf3da37f54176e88a"}, -] -types-setuptools = [ - {file = "types-setuptools-65.4.0.0.tar.gz", hash = "sha256:d9021d6a70690b34e7bd2947e7ab10167c646fbf062508cb56581be2e2a1615e"}, - {file = "types_setuptools-65.4.0.0-py3-none-any.whl", hash = "sha256:ce178b3f7dbd6c0e67f8eee7ae29c1be280ade7e5188bdd9e620843de4060d85"}, -] -types-urllib3 = [ - {file = "types-urllib3-1.26.25.tar.gz", hash = "sha256:5aef0e663724eef924afa8b320b62ffef2c1736c1fa6caecfc9bc6c8ae2c3def"}, - {file = "types_urllib3-1.26.25-py3-none-any.whl", hash = "sha256:c1d78cef7bd581e162e46c20a57b2e1aa6ebecdcf01fd0713bb90978ff3e3427"}, -] +types-certifi = [] +types-setuptools = [] +types-urllib3 = [] typing-extensions = [ {file = "typing_extensions-4.2.0-py3-none-any.whl", hash = "sha256:6657594ee297170d19f67d55c05852a874e7eb634f4f753dbd667855e07c1708"}, {file = "typing_extensions-4.2.0.tar.gz", hash = "sha256:f1c24655a0da0d1b67f07e17a5e6b2a105894e6824b92096378bb3668ef02376"}, ] -urllib3 = [ - {file = "urllib3-1.26.12-py2.py3-none-any.whl", hash = "sha256:b930dd878d5a8afb066a637fbb35144fe7901e3b209d1cd4f524bd0e9deee997"}, - {file = "urllib3-1.26.12.tar.gz", hash = "sha256:3fa96cf423e6987997fc326ae8df396db2a8b7c667747d47ddd8ecba91f4a74e"}, -] +urllib3 = [] websockets = [ {file = "websockets-10.3-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:661f641b44ed315556a2fa630239adfd77bd1b11cb0b9d96ed8ad90b0b1e4978"}, {file = "websockets-10.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:b529fdfa881b69fe563dbd98acce84f3e5a67df13de415e143ef053ff006d500"}, diff --git a/polygon/rest/__init__.py b/polygon/rest/__init__.py index c2dfb442..98bdf27b 100644 --- a/polygon/rest/__init__.py +++ b/polygon/rest/__init__.py @@ -44,7 +44,7 @@ def __init__( retries: int = 3, base: str = BASE, verbose: bool = False, - custom_json: Optional[Any] = None + custom_json: Optional[Any] = None, ): super().__init__( api_key=api_key, diff --git a/polygon/rest/base.py b/polygon/rest/base.py index 97bbdf20..a2e914f9 100644 --- a/polygon/rest/base.py +++ b/polygon/rest/base.py @@ -28,7 +28,7 @@ def __init__( retries: int, base: str, verbose: bool, - custom_json: Optional[Any] = None + custom_json: Optional[Any] = None, ): if api_key is None: raise AuthError( diff --git a/polygon/websocket/__init__.py b/polygon/websocket/__init__.py index c7934de4..4875a1ac 100644 --- a/polygon/websocket/__init__.py +++ b/polygon/websocket/__init__.py @@ -105,7 +105,9 @@ async def connect( msg = await s.recv() logger.debug("connected: %s", msg) logger.debug("authing...") - await s.send(self.json.dumps({"action": "auth", "params": self.api_key})) + await s.send( + self.json.dumps({"action": "auth", "params": self.api_key}) + ) auth_msg = await s.recv() auth_msg_parsed = self.json.loads(auth_msg) logger.debug("authed: %s", auth_msg) @@ -182,14 +184,18 @@ async def _subscribe(self, topics: Union[List[str], Set[str]]): return subs = ",".join(topics) logger.debug("subbing: %s", subs) - await self.websocket.send(self.json.dumps({"action": "subscribe", "params": subs})) + await self.websocket.send( + self.json.dumps({"action": "subscribe", "params": subs}) + ) async def _unsubscribe(self, topics: Union[List[str], Set[str]]): if self.websocket is None or len(topics) == 0: return subs = ",".join(topics) logger.debug("unsubbing: %s", subs) - await self.websocket.send(self.json.dumps({"action": "unsubscribe", "params": subs})) + await self.websocket.send( + self.json.dumps({"action": "unsubscribe", "params": subs}) + ) @staticmethod def _parse_subscription(s: str): diff --git a/pyproject.toml b/pyproject.toml index 51697a94..ca055ba9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,7 @@ sphinx-autodoc-typehints = "^1.19.2" types-certifi = "^2021.10.8" types-setuptools = "^65.4.0" pook = "^1.0.2" +orjson = "^3.8.1" [build-system] requires = ["poetry-core>=1.0.0"]