diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index afb92d9c..76bc9a45 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.8', '3.9', '3.10'] + python-version: ['3.10'] name: Lint ${{ matrix.python-version }} steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dfc5498e..baecc7a2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,13 +10,17 @@ permissions: contents: read jobs: test: - runs-on: ubuntu-latest strategy: fail-fast: false matrix: + os: [ubuntu-latest, windows-latest] python-version: ['3.8', '3.9', '3.10'] - name: Unit test ${{ matrix.python-version }} + runs-on: ${{ matrix.os }} + name: ${{ matrix.os }} Unit test ${{ matrix.python-version }} steps: + - name: Windows hack + run: git config --system core.longpaths true + if: ${{ matrix.os == 'windows-latest' }} - uses: actions/checkout@v3 - name: Setup Python uses: actions/setup-python@v3 diff --git a/poetry.lock b/poetry.lock index 0199d3a0..ab3e1a5e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -6,6 +6,20 @@ category = "dev" optional = false python-versions = "*" +[[package]] +name = "attrs" +version = "21.4.0" +description = "Classes Without Boilerplate" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[package.extras] +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" version = "2.10.1" @@ -86,12 +100,16 @@ optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [[package]] -name = "httpretty" -version = "1.1.4" -description = "HTTP client mock for Python" +name = "furl" +version = "2.1.3" +description = "URL manipulation made simple." category = "dev" optional = false -python-versions = ">=3" +python-versions = "*" + +[package.dependencies] +orderedmultidict = ">=1.0.1" +six = ">=1.8.0" [[package]] name = "idna" @@ -125,6 +143,21 @@ docs = ["sphinx", "jaraco.packaging (>=9)", "rst.linker (>=1.9)"] perf = ["ipython"] 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" +version = "5.7.1" +description = "Read resources from Python packages" +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +zipp = {version = ">=3.1.0", markers = "python_version < \"3.10\""} + +[package.extras] +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" version = "3.1.2" @@ -139,6 +172,25 @@ MarkupSafe = ">=2.0" [package.extras] i18n = ["Babel (>=2.7)"] +[[package]] +name = "jsonschema" +version = "4.5.1" +description = "An implementation of JSON Schema validation for Python" +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +attrs = ">=17.4.0" +importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} +importlib-resources = {version = ">=1.4.0", markers = "python_version < \"3.9\""} +pyrsistent = ">=0.14.0,<0.17.0 || >0.17.0,<0.17.1 || >0.17.1,<0.17.2 || >0.17.2" +typing-extensions = {version = "*", markers = "python_version < \"3.8\""} + +[package.extras] +format = ["fqdn", "idna", "isoduration", "jsonpointer (>1.13)", "rfc3339-validator", "rfc3987", "uri-template", "webcolors (>=1.11)"] +format_nongpl = ["fqdn", "idna", "isoduration", "jsonpointer (>1.13)", "rfc3339-validator", "rfc3986-validator (>0.1.0)", "uri-template", "webcolors (>=1.11)"] + [[package]] name = "markupsafe" version = "2.1.1" @@ -173,6 +225,17 @@ category = "dev" optional = false python-versions = "*" +[[package]] +name = "orderedmultidict" +version = "1.0.1" +description = "Ordered Multivalue Dictionary" +category = "dev" +optional = false +python-versions = "*" + +[package.dependencies] +six = ">=1.8.0" + [[package]] name = "packaging" version = "21.3" @@ -204,6 +267,19 @@ python-versions = ">=3.7" 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" +version = "1.0.2" +description = "HTTP traffic mocking and expectations made easy" +category = "dev" +optional = false +python-versions = "*" + +[package.dependencies] +furl = ">=0.5.6" +jsonschema = ">=2.5.1" +xmltodict = ">=0.11.0" + [[package]] name = "pygments" version = "2.12.0" @@ -223,6 +299,14 @@ python-versions = ">=3.6.8" [package.extras] diagrams = ["railroad-diagrams", "jinja2"] +[[package]] +name = "pyrsistent" +version = "0.18.1" +description = "Persistent/Functional/Immutable data structures" +category = "dev" +optional = false +python-versions = ">=3.7" + [[package]] name = "pytz" version = "2022.1" @@ -249,6 +333,14 @@ urllib3 = ">=1.21.1,<1.27" socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"] use_chardet_on_py3 = ["chardet (>=3.0.2,<5)"] +[[package]] +name = "six" +version = "1.16.0" +description = "Python 2 and 3 compatibility utilities" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" + [[package]] name = "snowballstemmer" version = "2.2.0" @@ -451,6 +543,14 @@ category = "main" optional = false python-versions = ">=3.7" +[[package]] +name = "xmltodict" +version = "0.13.0" +description = "Makes working with XML feel like you are working with JSON" +category = "dev" +optional = false +python-versions = ">=3.4" + [[package]] name = "zipp" version = "3.8.0" @@ -473,6 +573,10 @@ alabaster = [ {file = "alabaster-0.7.12-py2.py3-none-any.whl", hash = "sha256:446438bdcca0e05bd45ea2de1668c1d9b032e1a9154c2c259092d77031ddd359"}, {file = "alabaster-0.7.12.tar.gz", hash = "sha256:a661d72d58e6ea8a57f7a86e37d86716863ee5e92788398526d58b26a4e4dc02"}, ] +attrs = [ + {file = "attrs-21.4.0-py2.py3-none-any.whl", hash = "sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4"}, + {file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"}, +] babel = [ {file = "Babel-2.10.1-py3-none-any.whl", hash = "sha256:3f349e85ad3154559ac4930c3918247d319f21910d5ce4b25d439ed8693b98d2"}, {file = "Babel-2.10.1.tar.gz", hash = "sha256:98aeaca086133efb3e1e2aad0396987490c8425929ddbcfe0550184fdc54cd13"}, @@ -522,8 +626,9 @@ docutils = [ {file = "docutils-0.17.1-py2.py3-none-any.whl", hash = "sha256:cf316c8370a737a022b72b56874f6602acf974a37a9fba42ec2876387549fc61"}, {file = "docutils-0.17.1.tar.gz", hash = "sha256:686577d2e4c32380bb50cbb22f575ed742d58168cee37e99117a854bcd88f125"}, ] -httpretty = [ - {file = "httpretty-1.1.4.tar.gz", hash = "sha256:20de0e5dd5a18292d36d928cc3d6e52f8b2ac73daec40d41eb62dee154933b68"}, +furl = [ + {file = "furl-2.1.3-py2.py3-none-any.whl", hash = "sha256:9ab425062c4217f9802508e45feb4a83e54324273ac4b202f1850363309666c0"}, + {file = "furl-2.1.3.tar.gz", hash = "sha256:5a6188fe2666c484a12159c18be97a1977a71d632ef5bb867ef15f54af39cc4e"}, ] idna = [ {file = "idna-3.3-py3-none-any.whl", hash = "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff"}, @@ -537,10 +642,18 @@ importlib-metadata = [ {file = "importlib_metadata-4.11.3-py3-none-any.whl", hash = "sha256:1208431ca90a8cca1a6b8af391bb53c1a2db74e5d1cef6ddced95d4b2062edc6"}, {file = "importlib_metadata-4.11.3.tar.gz", hash = "sha256:ea4c597ebf37142f827b8f39299579e31685c31d3a438b59f469406afd0f2539"}, ] +importlib-resources = [ + {file = "importlib_resources-5.7.1-py3-none-any.whl", hash = "sha256:e447dc01619b1e951286f3929be820029d48c75eb25d265c28b92a16548212b8"}, + {file = "importlib_resources-5.7.1.tar.gz", hash = "sha256:b6062987dfc51f0fcb809187cffbd60f35df7acb4589091f154214af6d0d49d3"}, +] jinja2 = [ {file = "Jinja2-3.1.2-py3-none-any.whl", hash = "sha256:6088930bfe239f0e6710546ab9c19c9ef35e29792895fed6e6e31a023a182a61"}, {file = "Jinja2-3.1.2.tar.gz", hash = "sha256:31351a702a408a9e7595a8fc6150fc3f43bb6bf7e319770cbc0db9df9437e852"}, ] +jsonschema = [ + {file = "jsonschema-4.5.1-py3-none-any.whl", hash = "sha256:71b5e39324422543546572954ce71c67728922c104902cb7ce252e522235b33f"}, + {file = "jsonschema-4.5.1.tar.gz", hash = "sha256:7c6d882619340c3347a1bf7315e147e6d3dae439033ae6383d6acb908c101dfc"}, +] markupsafe = [ {file = "MarkupSafe-2.1.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:86b1f75c4e7c2ac2ccdaec2b9022845dbb81880ca318bb7a0a01fbf7813e3812"}, {file = "MarkupSafe-2.1.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:f121a1420d4e173a5d96e47e9a0c0dcff965afdf1626d28de1460815f7c4ee7a"}, @@ -612,6 +725,10 @@ 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"}, ] +orderedmultidict = [ + {file = "orderedmultidict-1.0.1-py2.py3-none-any.whl", hash = "sha256:43c839a17ee3cdd62234c47deca1a8508a3f2ca1d0678a3bf791c87cf84adbf3"}, + {file = "orderedmultidict-1.0.1.tar.gz", hash = "sha256:04070bbb5e87291cc9bfa51df413677faf2141c73c61d2a5f7b26bea3cd882ad"}, +] packaging = [ {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, @@ -624,6 +741,11 @@ platformdirs = [ {file = "platformdirs-2.5.2-py3-none-any.whl", hash = "sha256:027d8e83a2d7de06bbac4e5ef7e023c02b863d7ea5d079477e722bb41ab25788"}, {file = "platformdirs-2.5.2.tar.gz", hash = "sha256:58c8abb07dcb441e6ee4b11d8df0ac856038f944ab98b7be6b27b2a3c7feef19"}, ] +pook = [ + {file = "pook-1.0.2-py2-none-any.whl", hash = "sha256:cd3cbfe280d544e672f41a5b9482883841ba247f865858b57fd59f729e37616a"}, + {file = "pook-1.0.2-py3-none-any.whl", hash = "sha256:2e16d231ec9fe071c14cad7fe41261f65b401f6cb30935a169cf6fc229bd0a1d"}, + {file = "pook-1.0.2.tar.gz", hash = "sha256:f28112db062d17db245b351c80f2bb5bf1e56ebfa93d3d75cc44f500c15c40eb"}, +] pygments = [ {file = "Pygments-2.12.0-py3-none-any.whl", hash = "sha256:dc9c10fb40944260f6ed4c688ece0cd2048414940f1cea51b8b226318411c519"}, {file = "Pygments-2.12.0.tar.gz", hash = "sha256:5eb116118f9612ff1ee89ac96437bb6b49e8f04d8a13b514ba26f620208e26eb"}, @@ -632,6 +754,29 @@ pyparsing = [ {file = "pyparsing-3.0.9-py3-none-any.whl", hash = "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"}, {file = "pyparsing-3.0.9.tar.gz", hash = "sha256:2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb"}, ] +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"}, + {file = "pyrsistent-0.18.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4ed6784ceac462a7d6fcb7e9b663e93b9a6fb373b7f43594f9ff68875788e01e"}, + {file = "pyrsistent-0.18.1-cp310-cp310-win32.whl", hash = "sha256:e4f3149fd5eb9b285d6bfb54d2e5173f6a116fe19172686797c056672689daf6"}, + {file = "pyrsistent-0.18.1-cp310-cp310-win_amd64.whl", hash = "sha256:636ce2dc235046ccd3d8c56a7ad54e99d5c1cd0ef07d9ae847306c91d11b5fec"}, + {file = "pyrsistent-0.18.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:e92a52c166426efbe0d1ec1332ee9119b6d32fc1f0bbfd55d5c1088070e7fc1b"}, + {file = "pyrsistent-0.18.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d7a096646eab884bf8bed965bad63ea327e0d0c38989fc83c5ea7b8a87037bfc"}, + {file = "pyrsistent-0.18.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cdfd2c361b8a8e5d9499b9082b501c452ade8bbf42aef97ea04854f4a3f43b22"}, + {file = "pyrsistent-0.18.1-cp37-cp37m-win32.whl", hash = "sha256:7ec335fc998faa4febe75cc5268a9eac0478b3f681602c1f27befaf2a1abe1d8"}, + {file = "pyrsistent-0.18.1-cp37-cp37m-win_amd64.whl", hash = "sha256:6455fc599df93d1f60e1c5c4fe471499f08d190d57eca040c0ea182301321286"}, + {file = "pyrsistent-0.18.1-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:fd8da6d0124efa2f67d86fa70c851022f87c98e205f0594e1fae044e7119a5a6"}, + {file = "pyrsistent-0.18.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7bfe2388663fd18bd8ce7db2c91c7400bf3e1a9e8bd7d63bf7e77d39051b85ec"}, + {file = "pyrsistent-0.18.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0e3e1fcc45199df76053026a51cc59ab2ea3fc7c094c6627e93b7b44cdae2c8c"}, + {file = "pyrsistent-0.18.1-cp38-cp38-win32.whl", hash = "sha256:b568f35ad53a7b07ed9b1b2bae09eb15cdd671a5ba5d2c66caee40dbf91c68ca"}, + {file = "pyrsistent-0.18.1-cp38-cp38-win_amd64.whl", hash = "sha256:d1b96547410f76078eaf66d282ddca2e4baae8964364abb4f4dcdde855cd123a"}, + {file = "pyrsistent-0.18.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:f87cc2863ef33c709e237d4b5f4502a62a00fab450c9e020892e8e2ede5847f5"}, + {file = "pyrsistent-0.18.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6bc66318fb7ee012071b2792024564973ecc80e9522842eb4e17743604b5e045"}, + {file = "pyrsistent-0.18.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:914474c9f1d93080338ace89cb2acee74f4f666fb0424896fcfb8d86058bf17c"}, + {file = "pyrsistent-0.18.1-cp39-cp39-win32.whl", hash = "sha256:1b34eedd6812bf4d33814fca1b66005805d3640ce53140ab8bbb1e2651b0d9bc"}, + {file = "pyrsistent-0.18.1-cp39-cp39-win_amd64.whl", hash = "sha256:e24a828f57e0c337c8d8bb9f6b12f09dfdf0273da25fda9e314f0b684b415a07"}, + {file = "pyrsistent-0.18.1.tar.gz", hash = "sha256:d4d61f8b993a7255ba714df3aca52700f8125289f84f704cf80916517c46eb96"}, +] pytz = [ {file = "pytz-2022.1-py2.py3-none-any.whl", hash = "sha256:e68985985296d9a66a881eb3193b0906246245294a881e7c8afe623866ac6a5c"}, {file = "pytz-2022.1.tar.gz", hash = "sha256:1e760e2fe6a8163bc0b3d9a19c4f84342afa0a2affebfaa84b01b978a02ecaa7"}, @@ -640,6 +785,10 @@ requests = [ {file = "requests-2.27.1-py2.py3-none-any.whl", hash = "sha256:f22fa1e554c9ddfd16e6e41ac79759e17be9e492b3587efa038054674760e72d"}, {file = "requests-2.27.1.tar.gz", hash = "sha256:68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61"}, ] +six = [ + {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, + {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, +] snowballstemmer = [ {file = "snowballstemmer-2.2.0-py2.py3-none-any.whl", hash = "sha256:c8e1716e83cc398ae16824e5572ae04e0d9fc2c6b985fb0f900f5f0c96ecba1a"}, {file = "snowballstemmer-2.2.0.tar.gz", hash = "sha256:09b16deb8547d3412ad7b590689584cd0fe25ec8db3be37788be3810cbf19cb1"}, @@ -754,6 +903,10 @@ websockets = [ {file = "websockets-10.3-pp37-pypy37_pp73-win_amd64.whl", hash = "sha256:3eda1cb7e9da1b22588cefff09f0951771d6ee9fa8dbe66f5ae04cc5f26b2b55"}, {file = "websockets-10.3.tar.gz", hash = "sha256:fc06cc8073c8e87072138ba1e431300e2d408f054b27047d047b549455066ff4"}, ] +xmltodict = [ + {file = "xmltodict-0.13.0-py2.py3-none-any.whl", hash = "sha256:aa89e8fd76320154a40d19a0df04a4695fb9dc5ba977cbb68ab3e4eb225e7852"}, + {file = "xmltodict-0.13.0.tar.gz", hash = "sha256:341595a488e3e01a85a9d8911d8912fd922ede5fecc4dce437eb4b6c8d037e56"}, +] zipp = [ {file = "zipp-3.8.0-py3-none-any.whl", hash = "sha256:c4f6e5bbf48e74f7a38e7cc5b0480ff42b0ae5178957d564d18932525d5cf099"}, {file = "zipp-3.8.0.tar.gz", hash = "sha256:56bf8aadb83c24db6c4b577e13de374ccfb67da2078beba1d037c17980bf43ad"}, diff --git a/polygon/rest/__init__.py b/polygon/rest/__init__.py index b0c31594..5607cc46 100644 --- a/polygon/rest/__init__.py +++ b/polygon/rest/__init__.py @@ -15,8 +15,8 @@ import os -base = "https://api.polygon.io" -env_key = "POLYGON_API_KEY" +BASE = "https://api.polygon.io" +ENV_KEY = "POLYGON_API_KEY" class RESTClient( @@ -33,12 +33,12 @@ class RESTClient( ): def __init__( self, - api_key: Optional[str] = os.getenv(env_key), + api_key: Optional[str] = os.getenv(ENV_KEY), connect_timeout: float = 10.0, read_timeout: float = 10.0, num_pools: int = 10, retries: int = 3, - base: str = base, + base: str = BASE, verbose: bool = False, ): super().__init__( diff --git a/polygon/rest/base.py b/polygon/rest/base.py index 3f96b963..ca2ca4dd 100644 --- a/polygon/rest/base.py +++ b/polygon/rest/base.py @@ -129,7 +129,14 @@ def _get_params( elif isinstance(val, datetime): val = int(val.timestamp() * self.time_mult(datetime_res)) if val is not None: - params[argname.replace("_", ".")] = val + if ( + argname.endswith("_lt") + or argname.endswith("_lte") + or argname.endswith("_gt") + or argname.endswith("_gte") + ): + argname = argname.replace("_", ".") + params[argname] = val return params diff --git a/polygon/rest/snapshot.py b/polygon/rest/snapshot.py index 8784ae39..e43836f8 100644 --- a/polygon/rest/snapshot.py +++ b/polygon/rest/snapshot.py @@ -13,7 +13,7 @@ class SnapshotClient(BaseClient): def get_snapshot_all( self, - market_type: Optional[Union[str, SnapshotMarketType]] = "stocks", + market_type: Optional[Union[str, SnapshotMarketType]], tickers: Optional[Union[str, List[str]]] = None, params: Optional[Dict[str, Any]] = None, raw: bool = False, @@ -40,8 +40,8 @@ def get_snapshot_all( def get_snapshot_direction( self, + market_type: Optional[Union[str, SnapshotMarketType]], direction: Union[str, Direction], - market_type: Optional[Union[str, SnapshotMarketType]] = "stocks", params: Optional[Dict[str, Any]] = None, raw: bool = False, ) -> Union[List[TickerSnapshot], HTTPResponse]: @@ -67,8 +67,8 @@ def get_snapshot_direction( def get_snapshot_ticker( self, + market_type: Optional[Union[str, SnapshotMarketType]], ticker: str, - market_type: Optional[Union[str, SnapshotMarketType]] = "stocks", params: Optional[Dict[str, Any]] = None, raw: bool = False, ) -> Union[TickerSnapshot, HTTPResponse]: diff --git a/pyproject.toml b/pyproject.toml index 0bfe1a8a..a57d8a4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,13 +33,13 @@ certifi = "^2021.10.8" black = "^22.3.0" mypy = "^0.942" types-urllib3 = "^1.26.13" -httpretty = "^1.1.4" Sphinx = "^4.5.0" sphinx-rtd-theme = "^1.0.0" # keep this in sync with docs/requirements.txt for readthedocs.org sphinx-autodoc-typehints = "^1.18.1" types-certifi = "^2021.10.8" types-setuptools = "^57.4.14" +pook = "^1.0.2" [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/test_rest/base.py b/test_rest/base.py index 69e94acb..45aa168e 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -1,8 +1,9 @@ from polygon import RESTClient import os +import re import unittest -import httpretty # type: ignore +import pook # type: ignore # mocks are stored in file tree mocks = [] @@ -13,9 +14,20 @@ if fname.endswith(".json"): abspath = os.path.join(dname, fname) with open(abspath, "r") as f: - urllpath = abspath.replace(mockdir, "").replace(".json", "") + urllpath = abspath.replace(mockdir, "").replace("\\", "/") + urllpath = re.sub(".json$", "", urllpath) + urllpath = re.sub("/index$", "", urllpath) + # Windows will be sad. We support dev on Windows. + if "?" in urllpath: + raise Exception(f"use & instead of ? in path ${urllpath}") + urllpath = urllpath.replace("&", "?", 1) + if ":" in urllpath: + raise Exception(f"use ; instead of : in path ${urllpath}") + urllpath = urllpath.replace(";", ":", 1) + # print(abspath, urllpath) mocks.append((urllpath, f.read())) + unittest.util._MAX_LENGTH = 30000 # type: ignore @@ -24,8 +36,8 @@ class BaseTest(unittest.TestCase): def setUpClass(cls): cls.maxDiff = None cls.c = RESTClient("", verbose=True) - httpretty.enable(verbose=True, allow_net_connect=False) + pook.on() for m in mocks: url = cls.c.BASE + m[0] - # print('register', url) - httpretty.register_uri(httpretty.GET, url, m[1], match_querystring=True) + # print("register", url) + pook.get(url, reply=200, response_body=m[1]) diff --git a/test_rest/mocks/v1/conversion/AUD/USD?amount=100&precision=2.json b/test_rest/mocks/v1/conversion/AUD/USD&amount=100&precision=2.json similarity index 100% rename from test_rest/mocks/v1/conversion/AUD/USD?amount=100&precision=2.json rename to test_rest/mocks/v1/conversion/AUD/USD&amount=100&precision=2.json diff --git a/test_rest/mocks/v1/open-close/AAPL/2005-04-01?adjusted=True.json b/test_rest/mocks/v1/open-close/AAPL/2005-04-01&adjusted=True.json similarity index 100% rename from test_rest/mocks/v1/open-close/AAPL/2005-04-01?adjusted=True.json rename to test_rest/mocks/v1/open-close/AAPL/2005-04-01&adjusted=True.json diff --git a/test_rest/mocks/v2/aggs/grouped/locale/us/market/stocks/2005-04-04?adjusted=True.json b/test_rest/mocks/v2/aggs/grouped/locale/us/market/stocks/2005-04-04&adjusted=True.json similarity index 100% rename from test_rest/mocks/v2/aggs/grouped/locale/us/market/stocks/2005-04-04?adjusted=True.json rename to test_rest/mocks/v2/aggs/grouped/locale/us/market/stocks/2005-04-04&adjusted=True.json diff --git a/test_rest/mocks/v2/reference/news?ticker=NFLX.json b/test_rest/mocks/v2/reference/news&ticker=NFLX.json similarity index 100% rename from test_rest/mocks/v2/reference/news?ticker=NFLX.json rename to test_rest/mocks/v2/reference/news&ticker=NFLX.json diff --git a/test_rest/mocks/v2/snapshot/locale/global/markets/crypto/tickers/X:BTCUSD/book.json b/test_rest/mocks/v2/snapshot/locale/global/markets/crypto/tickers/X;BTCUSD/book.json similarity index 100% rename from test_rest/mocks/v2/snapshot/locale/global/markets/crypto/tickers/X:BTCUSD/book.json rename to test_rest/mocks/v2/snapshot/locale/global/markets/crypto/tickers/X;BTCUSD/book.json diff --git a/test_rest/mocks/v2/snapshot/locale/us/markets/stocks/gainers?market.type=stocks.json b/test_rest/mocks/v2/snapshot/locale/us/markets/stocks/gainers.json similarity index 100% rename from test_rest/mocks/v2/snapshot/locale/us/markets/stocks/gainers?market.type=stocks.json rename to test_rest/mocks/v2/snapshot/locale/us/markets/stocks/gainers.json diff --git a/test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers/AAPL?market.type=stocks.json b/test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers/AAPL.json similarity index 100% rename from test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers/AAPL?market.type=stocks.json rename to test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers/AAPL.json diff --git a/test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers?market.type=stocks.json b/test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers/index.json similarity index 100% rename from test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers?market.type=stocks.json rename to test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers/index.json diff --git a/test_rest/mocks/v3/quotes/AAPL?cursor=YXA9MTkyODgxNjYmYXM9JmxpbWl0PTEwJm9yZGVyPWRlc2Mmc29ydD10aW1lc3RhbXAmdGltZXN0YW1wLmx0ZT0yMDIyLTA1LTEwVDE0JTNBMTElM0ExMi42OTA2NjExODla.json b/test_rest/mocks/v3/quotes/AAPL&cursor=YXA9MTkyODgxNjYmYXM9JmxpbWl0PTEwJm9yZGVyPWRlc2Mmc29ydD10aW1lc3RhbXAmdGltZXN0YW1wLmx0ZT0yMDIyLTA1LTEwVDE0JTNBMTElM0ExMi42OTA2NjExODla.json similarity index 100% rename from test_rest/mocks/v3/quotes/AAPL?cursor=YXA9MTkyODgxNjYmYXM9JmxpbWl0PTEwJm9yZGVyPWRlc2Mmc29ydD10aW1lc3RhbXAmdGltZXN0YW1wLmx0ZT0yMDIyLTA1LTEwVDE0JTNBMTElM0ExMi42OTA2NjExODla.json rename to test_rest/mocks/v3/quotes/AAPL&cursor=YXA9MTkyODgxNjYmYXM9JmxpbWl0PTEwJm9yZGVyPWRlc2Mmc29ydD10aW1lc3RhbXAmdGltZXN0YW1wLmx0ZT0yMDIyLTA1LTEwVDE0JTNBMTElM0ExMi42OTA2NjExODla.json diff --git a/test_rest/mocks/v3/reference/conditions?asset.class=stocks.json b/test_rest/mocks/v3/reference/conditions&asset_class=stocks.json similarity index 100% rename from test_rest/mocks/v3/reference/conditions?asset.class=stocks.json rename to test_rest/mocks/v3/reference/conditions&asset_class=stocks.json diff --git a/test_rest/mocks/v3/reference/tickers?cursor=YWN0aXZlPXRydWUmZGF0ZT0yMDIyLTA0LTI3JmxpbWl0PTImb3JkZXI9YXNjJnBhZ2VfbWFya2VyPUFBJTdDZjEyMmJjYmY4YWQwNzRmZmJlMTZmNjkxOWQ0ZDc3NjZlMzA3MWNmNmU1Nzg3OGE0OGU1NjQ1YzQyM2U3NzJhOSZzb3J0PXRpY2tlcg.json b/test_rest/mocks/v3/reference/tickers&cursor=YWN0aXZlPXRydWUmZGF0ZT0yMDIyLTA0LTI3JmxpbWl0PTImb3JkZXI9YXNjJnBhZ2VfbWFya2VyPUFBJTdDZjEyMmJjYmY4YWQwNzRmZmJlMTZmNjkxOWQ0ZDc3NjZlMzA3MWNmNmU1Nzg3OGE0OGU1NjQ1YzQyM2U3NzJhOSZzb3J0PXRpY2tlcg.json similarity index 100% rename from test_rest/mocks/v3/reference/tickers?cursor=YWN0aXZlPXRydWUmZGF0ZT0yMDIyLTA0LTI3JmxpbWl0PTImb3JkZXI9YXNjJnBhZ2VfbWFya2VyPUFBJTdDZjEyMmJjYmY4YWQwNzRmZmJlMTZmNjkxOWQ0ZDc3NjZlMzA3MWNmNmU1Nzg3OGE0OGU1NjQ1YzQyM2U3NzJhOSZzb3J0PXRpY2tlcg.json rename to test_rest/mocks/v3/reference/tickers&cursor=YWN0aXZlPXRydWUmZGF0ZT0yMDIyLTA0LTI3JmxpbWl0PTImb3JkZXI9YXNjJnBhZ2VfbWFya2VyPUFBJTdDZjEyMmJjYmY4YWQwNzRmZmJlMTZmNjkxOWQ0ZDc3NjZlMzA3MWNmNmU1Nzg3OGE0OGU1NjQ1YzQyM2U3NzJhOSZzb3J0PXRpY2tlcg.json diff --git a/test_rest/mocks/v3/snapshot/options/AAPL/O:AAPL230616C00150000.json b/test_rest/mocks/v3/snapshot/options/AAPL/O;AAPL230616C00150000.json similarity index 100% rename from test_rest/mocks/v3/snapshot/options/AAPL/O:AAPL230616C00150000.json rename to test_rest/mocks/v3/snapshot/options/AAPL/O;AAPL230616C00150000.json diff --git a/test_rest/mocks/v3/trades/AAPL?limit=2.json b/test_rest/mocks/v3/trades/AAPL&limit=2.json similarity index 100% rename from test_rest/mocks/v3/trades/AAPL?limit=2.json rename to test_rest/mocks/v3/trades/AAPL&limit=2.json diff --git a/test_rest/test_snapshots.py b/test_rest/test_snapshots.py index f8f4023a..806e9a8a 100644 --- a/test_rest/test_snapshots.py +++ b/test_rest/test_snapshots.py @@ -16,7 +16,7 @@ class SnapshotsTest(BaseTest): def test_get_snapshot_all(self): - snapshots = self.c.get_snapshot_all() + snapshots = self.c.get_snapshot_all("stocks") expected = [ TickerSnapshot( day=Agg( @@ -50,7 +50,7 @@ def test_get_snapshot_all(self): self.assertEqual(snapshots, expected) def test_get_snapshot_ticker(self): - snapshots = self.c.get_snapshot_ticker("AAPL") + snapshots = self.c.get_snapshot_ticker("stocks", "AAPL") expected = TickerSnapshot( day=Agg( open=161.84,