From 4a36b119b4020b48a09f8d38c4e3cd7c50587de5 Mon Sep 17 00:00:00 2001 From: Ray Garcia Date: Tue, 27 Jun 2023 11:16:02 -0500 Subject: [PATCH 1/3] added support for all time series end points. next, i'll need to support ticker search and global market status --- alphavantage_api_client/client.py | 94 +++++++++++- alphavantage_api_client/models.py | 9 +- examples/getting_started.py | 17 ++- poetry.lock | 204 +++++-------------------- pyproject.toml | 1 + tests/test_multi_client_integration.py | 90 +++++++++-- 6 files changed, 228 insertions(+), 187 deletions(-) diff --git a/alphavantage_api_client/client.py b/alphavantage_api_client/client.py index 5aa9b30..4934fd3 100644 --- a/alphavantage_api_client/client.py +++ b/alphavantage_api_client/client.py @@ -188,8 +188,100 @@ def get_daily_quote(self, event: dict) -> Quote: return Quote.parse_obj(json_response) + def get_daily_adjusted_quote(self, event: dict) -> Quote: + """ + This API returns raw (as-traded) daily open/high/low/close/volume values, + daily adjusted close values, and historical split/dividend events of the global + equity specified, covering 20+ years of historical data. + Args: + event: dict, required + + Returns: Quote + + """ + # default params + defaults = {"datatype": "json", "function": "TIME_SERIES_DAILY_ADJUSTED", + "outputsize": "compact"} + json_request = self.__create_api_request_from__(defaults, event) + json_response = self.get_data_from_alpha_vantage(json_request, self.__retry__) + + return Quote.parse_obj(json_response) + + def get_weekly_quote(self, event: dict) -> Quote: + """ + This API returns weekly time series (last trading day of each week, weekly open, + weekly high, weekly low, weekly close, weekly volume) of the global equity + specified, covering 20+ years of historical data. + Args: + event: dict, required + + Returns: Quote + + """ + # default params + defaults = {"datatype": "json", "function": "TIME_SERIES_WEEKLY", + "outputsize": "compact"} + json_request = self.__create_api_request_from__(defaults, event) + json_response = self.get_data_from_alpha_vantage(json_request, self.__retry__) + + return Quote.parse_obj(json_response) + + def get_weekly_adjusted_quote(self, event: dict) -> Quote: + """ + This API returns weekly adjusted time series (last trading day of each week, weekly open, + weekly high, weekly low, weekly close, weekly adjusted close, weekly volume, weekly dividend) + of the global equity specified, covering 20+ years of historical data. + Args: + event: dict, required + + Returns: Quote + + """ + # default params + defaults = {"datatype": "json", "function": "TIME_SERIES_WEEKLY_ADJUSTED"} + json_request = self.__create_api_request_from__(defaults, event) + json_response = self.get_data_from_alpha_vantage(json_request, self.__retry__) + + return Quote.parse_obj(json_response) + + def get_monthly_quote(self, event: dict) -> Quote: + """ + This API returns monthly time series (last trading day of each month, monthly open, + monthly high, monthly low, monthly close, monthly volume) of the global equity specified, + covering 20+ years of historical data. + Args: + event: dict, required + + Returns: Quote + + """ + # default params + defaults = {"datatype": "json", "function": "TIME_SERIES_MONTHLY"} + json_request = self.__create_api_request_from__(defaults, event) + json_response = self.get_data_from_alpha_vantage(json_request, self.__retry__) + + return Quote.parse_obj(json_response) + + def get_monthly_adjusted_quote(self, event: dict) -> Quote: + """ + This API returns monthly time series (last trading day of each month, monthly open, + monthly high, monthly low, monthly close, monthly volume) of the global equity specified, + covering 20+ years of historical data. + Args: + event: dict, required + + Returns: Quote + + """ + # default params + defaults = {"datatype": "json", "function": "TIME_SERIES_MONTHLY_ADJUSTED"} + json_request = self.__create_api_request_from__(defaults, event) + json_response = self.get_data_from_alpha_vantage(json_request, self.__retry__) + + return Quote.parse_obj(json_response) + def get_intraday_quote(self, event: dict) -> Quote: - """ Intraday time series data covering extened trading hours. + """ Intraday time series data covering extended trading hours. This API returns intraday time series of the equity specified, covering extended trading hours where applicable (e.g., 4:00am to 8:00pm Eastern Time for the US market). The intraday data is derived from the Securities diff --git a/alphavantage_api_client/models.py b/alphavantage_api_client/models.py index 62c317d..b6572ce 100644 --- a/alphavantage_api_client/models.py +++ b/alphavantage_api_client/models.py @@ -33,7 +33,12 @@ class Quote(BaseQuote): @pydantic.root_validator(pre=True) def normalize_fields(cls, values): return { - "data" if k.startswith("Technical Analysis: ") or k.startswith("Time Series (") + "data" if k.startswith("Weekly Adjusted Time Series") + or k.startswith("Monthly Adjusted Time Series") + or k.startswith("Monthly Time Series") + or k.startswith("Weekly Time Series") + or k.startswith("Technical Analysis: ") + or k.startswith("Time Series (") or k.startswith("Time Series Crypto (") else k: v for k, v in values.items() } @@ -49,7 +54,7 @@ def get_most_recent_value(self) -> Optional[dict]: def get_oldest_value(self) -> Optional[dict]: if len(self.data) > 0: quote_dates = list(self.data.keys()) - last_quote_date = quote_dates[len(quote_dates)-1] + last_quote_date = quote_dates[len(quote_dates) - 1] quote = self.data[last_quote_date] quote["query_date"] = last_quote_date diff --git a/examples/getting_started.py b/examples/getting_started.py index 834dea0..06dfb7f 100644 --- a/examples/getting_started.py +++ b/examples/getting_started.py @@ -1,5 +1,5 @@ from alphavantage_api_client import AlphavantageClient, GlobalQuote, Quote, AccountingReport, CompanyOverview, Ticker - +import logging def sample_global_quote(): client = AlphavantageClient() @@ -104,8 +104,9 @@ def sample_cash_flow(): def sample_retry_when_limit_reached(): + logging.basicConfig(level=logging.INFO) client = AlphavantageClient().use_simple_cache().should_retry_once() - symbols = ["TSLA", "F", "C", "WFC", "ZIM", "PXD", "PXD", "POOL", "INTC", "INTU"] # more than 5 calls so should fail + symbols = ["TSLA", "F", "C", "WFC", "ZIM", "PXD", "PXD", "POOL", "INTC", "INTU", "AAPL"] # more than 5 calls so should fail for symbol in symbols: event = { "symbol": symbol @@ -150,6 +151,16 @@ def sample_ticker_usage(): combined_financial_statements = correlated_financial_statements[fiscal_date_ending] print(f"{fiscal_date_ending} = {combined_financial_statements}") +def sample_direct_access(): + client = AlphavantageClient() + event = { + "symbol" : "AAPL", + "function" : "GLOBAL_QUOTE" + } # EACH ATTRIBUTE IS EXACTLY SUPPORTED BY END POINTS + + response = client.get_data_from_alpha_vantage(event) + print(response) # a dictionary with exact response from Alpha Vantage End point you requested + if __name__ == "__main__": - sample_ticker_usage() + sample_direct_access() diff --git a/poetry.lock b/poetry.lock index 9b147ef..eed9e05 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,121 +1,34 @@ -# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. - [[package]] name = "certifi" version = "2023.5.7" description = "Python package for providing Mozilla's CA Bundle." +category = "main" optional = false python-versions = ">=3.6" -files = [ - {file = "certifi-2023.5.7-py3-none-any.whl", hash = "sha256:c6c2e98f5c7869efca1f8916fed228dd91539f9f1b444c314c06eef02980c716"}, - {file = "certifi-2023.5.7.tar.gz", hash = "sha256:0f0d56dc5a6ad56fd4ba36484d6cc34451e1c6548c61daad8c320169f91eddc7"}, -] [[package]] name = "charset-normalizer" version = "3.1.0" description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." +category = "main" optional = false python-versions = ">=3.7.0" -files = [ - {file = "charset-normalizer-3.1.0.tar.gz", hash = "sha256:34e0a2f9c370eb95597aae63bf85eb5e96826d81e3dcf88b8886012906f509b5"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:e0ac8959c929593fee38da1c2b64ee9778733cdf03c482c9ff1d508b6b593b2b"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d7fc3fca01da18fbabe4625d64bb612b533533ed10045a2ac3dd194bfa656b60"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:04eefcee095f58eaabe6dc3cc2262f3bcd776d2c67005880894f447b3f2cb9c1"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:20064ead0717cf9a73a6d1e779b23d149b53daf971169289ed2ed43a71e8d3b0"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1435ae15108b1cb6fffbcea2af3d468683b7afed0169ad718451f8db5d1aff6f"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:c84132a54c750fda57729d1e2599bb598f5fa0344085dbde5003ba429a4798c0"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:75f2568b4189dda1c567339b48cba4ac7384accb9c2a7ed655cd86b04055c795"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:11d3bcb7be35e7b1bba2c23beedac81ee893ac9871d0ba79effc7fc01167db6c"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:891cf9b48776b5c61c700b55a598621fdb7b1e301a550365571e9624f270c203"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:5f008525e02908b20e04707a4f704cd286d94718f48bb33edddc7d7b584dddc1"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-musllinux_1_1_ppc64le.whl", hash = "sha256:b06f0d3bf045158d2fb8837c5785fe9ff9b8c93358be64461a1089f5da983137"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-musllinux_1_1_s390x.whl", hash = "sha256:49919f8400b5e49e961f320c735388ee686a62327e773fa5b3ce6721f7e785ce"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:22908891a380d50738e1f978667536f6c6b526a2064156203d418f4856d6e86a"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-win32.whl", hash = "sha256:12d1a39aa6b8c6f6248bb54550efcc1c38ce0d8096a146638fd4738e42284448"}, - {file = "charset_normalizer-3.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:65ed923f84a6844de5fd29726b888e58c62820e0769b76565480e1fdc3d062f8"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:9a3267620866c9d17b959a84dd0bd2d45719b817245e49371ead79ed4f710d19"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6734e606355834f13445b6adc38b53c0fd45f1a56a9ba06c2058f86893ae8017"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f8303414c7b03f794347ad062c0516cee0e15f7a612abd0ce1e25caf6ceb47df"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:aaf53a6cebad0eae578f062c7d462155eada9c172bd8c4d250b8c1d8eb7f916a"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3dc5b6a8ecfdc5748a7e429782598e4f17ef378e3e272eeb1340ea57c9109f41"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e1b25e3ad6c909f398df8921780d6a3d120d8c09466720226fc621605b6f92b1"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0ca564606d2caafb0abe6d1b5311c2649e8071eb241b2d64e75a0d0065107e62"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b82fab78e0b1329e183a65260581de4375f619167478dddab510c6c6fb04d9b6"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:bd7163182133c0c7701b25e604cf1611c0d87712e56e88e7ee5d72deab3e76b5"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:11d117e6c63e8f495412d37e7dc2e2fff09c34b2d09dbe2bee3c6229577818be"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-musllinux_1_1_ppc64le.whl", hash = "sha256:cf6511efa4801b9b38dc5546d7547d5b5c6ef4b081c60b23e4d941d0eba9cbeb"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-musllinux_1_1_s390x.whl", hash = "sha256:abc1185d79f47c0a7aaf7e2412a0eb2c03b724581139193d2d82b3ad8cbb00ac"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:cb7b2ab0188829593b9de646545175547a70d9a6e2b63bf2cd87a0a391599324"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-win32.whl", hash = "sha256:c36bcbc0d5174a80d6cccf43a0ecaca44e81d25be4b7f90f0ed7bcfbb5a00909"}, - {file = "charset_normalizer-3.1.0-cp311-cp311-win_amd64.whl", hash = "sha256:cca4def576f47a09a943666b8f829606bcb17e2bc2d5911a46c8f8da45f56755"}, - {file = "charset_normalizer-3.1.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:0c95f12b74681e9ae127728f7e5409cbbef9cd914d5896ef238cc779b8152373"}, - {file = "charset_normalizer-3.1.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fca62a8301b605b954ad2e9c3666f9d97f63872aa4efcae5492baca2056b74ab"}, - {file = "charset_normalizer-3.1.0-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ac0aa6cd53ab9a31d397f8303f92c42f534693528fafbdb997c82bae6e477ad9"}, - {file = "charset_normalizer-3.1.0-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:c3af8e0f07399d3176b179f2e2634c3ce9c1301379a6b8c9c9aeecd481da494f"}, - {file = "charset_normalizer-3.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3a5fc78f9e3f501a1614a98f7c54d3969f3ad9bba8ba3d9b438c3bc5d047dd28"}, - {file = "charset_normalizer-3.1.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:628c985afb2c7d27a4800bfb609e03985aaecb42f955049957814e0491d4006d"}, - {file = "charset_normalizer-3.1.0-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:74db0052d985cf37fa111828d0dd230776ac99c740e1a758ad99094be4f1803d"}, - {file = "charset_normalizer-3.1.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:1e8fcdd8f672a1c4fc8d0bd3a2b576b152d2a349782d1eb0f6b8e52e9954731d"}, - {file = "charset_normalizer-3.1.0-cp37-cp37m-musllinux_1_1_ppc64le.whl", hash = "sha256:04afa6387e2b282cf78ff3dbce20f0cc071c12dc8f685bd40960cc68644cfea6"}, - {file = "charset_normalizer-3.1.0-cp37-cp37m-musllinux_1_1_s390x.whl", hash = "sha256:dd5653e67b149503c68c4018bf07e42eeed6b4e956b24c00ccdf93ac79cdff84"}, - {file = "charset_normalizer-3.1.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:d2686f91611f9e17f4548dbf050e75b079bbc2a82be565832bc8ea9047b61c8c"}, - {file = "charset_normalizer-3.1.0-cp37-cp37m-win32.whl", hash = "sha256:4155b51ae05ed47199dc5b2a4e62abccb274cee6b01da5b895099b61b1982974"}, - {file = "charset_normalizer-3.1.0-cp37-cp37m-win_amd64.whl", hash = "sha256:322102cdf1ab682ecc7d9b1c5eed4ec59657a65e1c146a0da342b78f4112db23"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:e633940f28c1e913615fd624fcdd72fdba807bf53ea6925d6a588e84e1151531"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:3a06f32c9634a8705f4ca9946d667609f52cf130d5548881401f1eb2c39b1e2c"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:7381c66e0561c5757ffe616af869b916c8b4e42b367ab29fedc98481d1e74e14"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3573d376454d956553c356df45bb824262c397c6e26ce43e8203c4c540ee0acb"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e89df2958e5159b811af9ff0f92614dabf4ff617c03a4c1c6ff53bf1c399e0e1"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:78cacd03e79d009d95635e7d6ff12c21eb89b894c354bd2b2ed0b4763373693b"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:de5695a6f1d8340b12a5d6d4484290ee74d61e467c39ff03b39e30df62cf83a0"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1c60b9c202d00052183c9be85e5eaf18a4ada0a47d188a83c8f5c5b23252f649"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:f645caaf0008bacf349875a974220f1f1da349c5dbe7c4ec93048cdc785a3326"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:ea9f9c6034ea2d93d9147818f17c2a0860d41b71c38b9ce4d55f21b6f9165a11"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-musllinux_1_1_ppc64le.whl", hash = "sha256:80d1543d58bd3d6c271b66abf454d437a438dff01c3e62fdbcd68f2a11310d4b"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-musllinux_1_1_s390x.whl", hash = "sha256:73dc03a6a7e30b7edc5b01b601e53e7fc924b04e1835e8e407c12c037e81adbd"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:6f5c2e7bc8a4bf7c426599765b1bd33217ec84023033672c1e9a8b35eaeaaaf8"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-win32.whl", hash = "sha256:12a2b561af122e3d94cdb97fe6fb2bb2b82cef0cdca131646fdb940a1eda04f0"}, - {file = "charset_normalizer-3.1.0-cp38-cp38-win_amd64.whl", hash = "sha256:3160a0fd9754aab7d47f95a6b63ab355388d890163eb03b2d2b87ab0a30cfa59"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:38e812a197bf8e71a59fe55b757a84c1f946d0ac114acafaafaf21667a7e169e"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:6baf0baf0d5d265fa7944feb9f7451cc316bfe30e8df1a61b1bb08577c554f31"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:8f25e17ab3039b05f762b0a55ae0b3632b2e073d9c8fc88e89aca31a6198e88f"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3747443b6a904001473370d7810aa19c3a180ccd52a7157aacc264a5ac79265e"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b116502087ce8a6b7a5f1814568ccbd0e9f6cfd99948aa59b0e241dc57cf739f"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:d16fd5252f883eb074ca55cb622bc0bee49b979ae4e8639fff6ca3ff44f9f854"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:21fa558996782fc226b529fdd2ed7866c2c6ec91cee82735c98a197fae39f706"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6f6c7a8a57e9405cad7485f4c9d3172ae486cfef1344b5ddd8e5239582d7355e"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:ac3775e3311661d4adace3697a52ac0bab17edd166087d493b52d4f4f553f9f0"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:10c93628d7497c81686e8e5e557aafa78f230cd9e77dd0c40032ef90c18f2230"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-musllinux_1_1_ppc64le.whl", hash = "sha256:6f4f4668e1831850ebcc2fd0b1cd11721947b6dc7c00bf1c6bd3c929ae14f2c7"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-musllinux_1_1_s390x.whl", hash = "sha256:0be65ccf618c1e7ac9b849c315cc2e8a8751d9cfdaa43027d4f6624bd587ab7e"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:53d0a3fa5f8af98a1e261de6a3943ca631c526635eb5817a87a59d9a57ebf48f"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-win32.whl", hash = "sha256:a04f86f41a8916fe45ac5024ec477f41f886b3c435da2d4e3d2709b22ab02af1"}, - {file = "charset_normalizer-3.1.0-cp39-cp39-win_amd64.whl", hash = "sha256:830d2948a5ec37c386d3170c483063798d7879037492540f10a475e3fd6f244b"}, - {file = "charset_normalizer-3.1.0-py3-none-any.whl", hash = "sha256:3d9098b479e78c85080c98e1e35ff40b4a31d8953102bb0fd7d1b6f8a2111a3d"}, -] [[package]] name = "colorama" version = "0.4.6" description = "Cross-platform colored terminal text." +category = "main" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" -files = [ - {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, - {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, -] [[package]] name = "exceptiongroup" version = "1.1.1" description = "Backport of PEP 654 (exception groups)" +category = "main" optional = false python-versions = ">=3.7" -files = [ - {file = "exceptiongroup-1.1.1-py3-none-any.whl", hash = "sha256:232c37c63e4f682982c8b6459f33a8981039e5fb8756b2074364e5055c498c9e"}, - {file = "exceptiongroup-1.1.1.tar.gz", hash = "sha256:d484c3090ba2889ae2928419117447a14daf3c1231d5e30d0aae34f354f01785"}, -] [package.extras] test = ["pytest (>=6)"] @@ -124,45 +37,33 @@ test = ["pytest (>=6)"] name = "idna" version = "3.4" description = "Internationalized Domain Names in Applications (IDNA)" +category = "main" optional = false python-versions = ">=3.5" -files = [ - {file = "idna-3.4-py3-none-any.whl", hash = "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2"}, - {file = "idna-3.4.tar.gz", hash = "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4"}, -] [[package]] name = "iniconfig" version = "2.0.0" description = "brain-dead simple config-ini parsing" +category = "main" optional = false python-versions = ">=3.7" -files = [ - {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, - {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, -] [[package]] name = "packaging" version = "23.1" description = "Core utilities for Python packages" +category = "main" optional = false python-versions = ">=3.7" -files = [ - {file = "packaging-23.1-py3-none-any.whl", hash = "sha256:994793af429502c4ea2ebf6bf664629d07c1a9fe974af92966e4b8d2df7edc61"}, - {file = "packaging-23.1.tar.gz", hash = "sha256:a392980d2b6cffa644431898be54b0045151319d1e7ec34f0cfed48767dd334f"}, -] [[package]] name = "pluggy" version = "1.2.0" description = "plugin and hook calling mechanisms for python" +category = "main" optional = false python-versions = ">=3.7" -files = [ - {file = "pluggy-1.2.0-py3-none-any.whl", hash = "sha256:c2fd55a7d7a3863cba1a013e4e2414658b1d07b6bc57b3919e0c63c9abb99849"}, - {file = "pluggy-1.2.0.tar.gz", hash = "sha256:d12f0c4b579b15f5e054301bb226ee85eeeba08ffec228092f8defbaa3a4c4b3"}, -] [package.extras] dev = ["pre-commit", "tox"] @@ -172,46 +73,9 @@ testing = ["pytest", "pytest-benchmark"] name = "pydantic" version = "1.10.9" description = "Data validation and settings management using python type hints" +category = "main" optional = false python-versions = ">=3.7" -files = [ - {file = "pydantic-1.10.9-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e692dec4a40bfb40ca530e07805b1208c1de071a18d26af4a2a0d79015b352ca"}, - {file = "pydantic-1.10.9-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:3c52eb595db83e189419bf337b59154bdcca642ee4b2a09e5d7797e41ace783f"}, - {file = "pydantic-1.10.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:939328fd539b8d0edf244327398a667b6b140afd3bf7e347cf9813c736211896"}, - {file = "pydantic-1.10.9-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b48d3d634bca23b172f47f2335c617d3fcb4b3ba18481c96b7943a4c634f5c8d"}, - {file = "pydantic-1.10.9-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:f0b7628fb8efe60fe66fd4adadd7ad2304014770cdc1f4934db41fe46cc8825f"}, - {file = "pydantic-1.10.9-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:e1aa5c2410769ca28aa9a7841b80d9d9a1c5f223928ca8bec7e7c9a34d26b1d4"}, - {file = "pydantic-1.10.9-cp310-cp310-win_amd64.whl", hash = "sha256:eec39224b2b2e861259d6f3c8b6290d4e0fbdce147adb797484a42278a1a486f"}, - {file = "pydantic-1.10.9-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:d111a21bbbfd85c17248130deac02bbd9b5e20b303338e0dbe0faa78330e37e0"}, - {file = "pydantic-1.10.9-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:2e9aec8627a1a6823fc62fb96480abe3eb10168fd0d859ee3d3b395105ae19a7"}, - {file = "pydantic-1.10.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:07293ab08e7b4d3c9d7de4949a0ea571f11e4557d19ea24dd3ae0c524c0c334d"}, - {file = "pydantic-1.10.9-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7ee829b86ce984261d99ff2fd6e88f2230068d96c2a582f29583ed602ef3fc2c"}, - {file = "pydantic-1.10.9-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:4b466a23009ff5cdd7076eb56aca537c745ca491293cc38e72bf1e0e00de5b91"}, - {file = "pydantic-1.10.9-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:7847ca62e581e6088d9000f3c497267868ca2fa89432714e21a4fb33a04d52e8"}, - {file = "pydantic-1.10.9-cp311-cp311-win_amd64.whl", hash = "sha256:7845b31959468bc5b78d7b95ec52fe5be32b55d0d09983a877cca6aedc51068f"}, - {file = "pydantic-1.10.9-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:517a681919bf880ce1dac7e5bc0c3af1e58ba118fd774da2ffcd93c5f96eaece"}, - {file = "pydantic-1.10.9-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:67195274fd27780f15c4c372f4ba9a5c02dad6d50647b917b6a92bf00b3d301a"}, - {file = "pydantic-1.10.9-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2196c06484da2b3fded1ab6dbe182bdabeb09f6318b7fdc412609ee2b564c49a"}, - {file = "pydantic-1.10.9-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:6257bb45ad78abacda13f15bde5886efd6bf549dd71085e64b8dcf9919c38b60"}, - {file = "pydantic-1.10.9-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:3283b574b01e8dbc982080d8287c968489d25329a463b29a90d4157de4f2baaf"}, - {file = "pydantic-1.10.9-cp37-cp37m-win_amd64.whl", hash = "sha256:5f8bbaf4013b9a50e8100333cc4e3fa2f81214033e05ac5aa44fa24a98670a29"}, - {file = "pydantic-1.10.9-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:b9cd67fb763248cbe38f0593cd8611bfe4b8ad82acb3bdf2b0898c23415a1f82"}, - {file = "pydantic-1.10.9-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:f50e1764ce9353be67267e7fd0da08349397c7db17a562ad036aa7c8f4adfdb6"}, - {file = "pydantic-1.10.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:73ef93e5e1d3c8e83f1ff2e7fdd026d9e063c7e089394869a6e2985696693766"}, - {file = "pydantic-1.10.9-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:128d9453d92e6e81e881dd7e2484e08d8b164da5507f62d06ceecf84bf2e21d3"}, - {file = "pydantic-1.10.9-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:ad428e92ab68798d9326bb3e5515bc927444a3d71a93b4a2ca02a8a5d795c572"}, - {file = "pydantic-1.10.9-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:fab81a92f42d6d525dd47ced310b0c3e10c416bbfae5d59523e63ea22f82b31e"}, - {file = "pydantic-1.10.9-cp38-cp38-win_amd64.whl", hash = "sha256:963671eda0b6ba6926d8fc759e3e10335e1dc1b71ff2a43ed2efd6996634dafb"}, - {file = "pydantic-1.10.9-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:970b1bdc6243ef663ba5c7e36ac9ab1f2bfecb8ad297c9824b542d41a750b298"}, - {file = "pydantic-1.10.9-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:7e1d5290044f620f80cf1c969c542a5468f3656de47b41aa78100c5baa2b8276"}, - {file = "pydantic-1.10.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:83fcff3c7df7adff880622a98022626f4f6dbce6639a88a15a3ce0f96466cb60"}, - {file = "pydantic-1.10.9-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0da48717dc9495d3a8f215e0d012599db6b8092db02acac5e0d58a65248ec5bc"}, - {file = "pydantic-1.10.9-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:0a2aabdc73c2a5960e87c3ffebca6ccde88665616d1fd6d3db3178ef427b267a"}, - {file = "pydantic-1.10.9-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:9863b9420d99dfa9c064042304868e8ba08e89081428a1c471858aa2af6f57c4"}, - {file = "pydantic-1.10.9-cp39-cp39-win_amd64.whl", hash = "sha256:e7c9900b43ac14110efa977be3da28931ffc74c27e96ee89fbcaaf0b0fe338e1"}, - {file = "pydantic-1.10.9-py3-none-any.whl", hash = "sha256:6cafde02f6699ce4ff643417d1a9223716ec25e228ddc3b436fe7e2d25a1f305"}, - {file = "pydantic-1.10.9.tar.gz", hash = "sha256:95c70da2cd3b6ddf3b9645ecaa8d98f3d80c606624b6d245558d202cd23ea3be"}, -] [package.dependencies] typing-extensions = ">=4.2.0" @@ -224,12 +88,9 @@ email = ["email-validator (>=1.0.3)"] name = "pytest" version = "7.4.0" description = "pytest: simple powerful testing with Python" +category = "main" optional = false python-versions = ">=3.7" -files = [ - {file = "pytest-7.4.0-py3-none-any.whl", hash = "sha256:78bf16451a2eb8c7a2ea98e32dc119fd2aa758f1d5d66dbf0a59d69a3969df32"}, - {file = "pytest-7.4.0.tar.gz", hash = "sha256:b4bf8c45bd59934ed84001ad51e11b4ee40d40a1229d2c79f9c592b0a3f6bd8a"}, -] [package.dependencies] colorama = {version = "*", markers = "sys_platform == \"win32\""} @@ -246,12 +107,9 @@ testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "no name = "requests" version = "2.31.0" description = "Python HTTP for Humans." +category = "main" optional = false python-versions = ">=3.7" -files = [ - {file = "requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f"}, - {file = "requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1"}, -] [package.dependencies] certifi = ">=2017.4.17" @@ -261,40 +119,31 @@ urllib3 = ">=1.21.1,<3" [package.extras] socks = ["PySocks (>=1.5.6,!=1.5.7)"] -use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] +use_chardet_on_py3 = ["chardet (>=3.0.2,<6)"] [[package]] name = "tomli" version = "2.0.1" description = "A lil' TOML parser" +category = "main" optional = false python-versions = ">=3.7" -files = [ - {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, - {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, -] [[package]] name = "typing-extensions" version = "4.6.3" description = "Backported and Experimental Type Hints for Python 3.7+" +category = "main" optional = false python-versions = ">=3.7" -files = [ - {file = "typing_extensions-4.6.3-py3-none-any.whl", hash = "sha256:88a4153d8505aabbb4e13aacb7c486c2b4a33ca3b3f807914a9b4c844c471c26"}, - {file = "typing_extensions-4.6.3.tar.gz", hash = "sha256:d91d5919357fe7f681a9f2b5b4cb2a5f1ef0a1e9f59c4d8ff0d3491e05c0ffd5"}, -] [[package]] name = "urllib3" version = "2.0.3" description = "HTTP library with thread-safe connection pooling, file post, and more." +category = "main" optional = false python-versions = ">=3.7" -files = [ - {file = "urllib3-2.0.3-py3-none-any.whl", hash = "sha256:48e7fafa40319d358848e1bc6809b208340fafe2096f1725d05d67443d0483d1"}, - {file = "urllib3-2.0.3.tar.gz", hash = "sha256:bee28b5e56addb8226c96f7f13ac28cb4c301dd5ea8a6ca179c0b9835e032825"}, -] [package.extras] brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)"] @@ -303,6 +152,25 @@ socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"] zstd = ["zstandard (>=0.18.0)"] [metadata] -lock-version = "2.0" +lock-version = "1.1" python-versions = "^3.10" -content-hash = "2598ace6c448b698bbe6a8204a307a0ef7402ccf74f8cd6a1fe93d80f0325d05" +content-hash = "706d4b76443826b8c4278fc18041ce7a33edb016854dabd28f50fb3ff0d5cff4" + +[metadata.files] +certifi = [] +charset-normalizer = [] +colorama = [] +exceptiongroup = [] +idna = [] +iniconfig = [] +packaging = [] +pluggy = [] +pydantic = [] +pytest = [] +requests = [] +tomli = [ + {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, + {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, +] +typing-extensions = [] +urllib3 = [] diff --git a/pyproject.toml b/pyproject.toml index 108aced..e381e0c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,7 @@ license = "MIT" python = "^3.10" requests = "^2.27.1" pydantic = "^1.9.1" +pytest = "^7.4.0" [tool.poetry.dev-dependencies] pytest = "^7.1.2" diff --git a/tests/test_multi_client_integration.py b/tests/test_multi_client_integration.py index bf4bcaa..27770dd 100644 --- a/tests/test_multi_client_integration.py +++ b/tests/test_multi_client_integration.py @@ -165,10 +165,10 @@ def test_can_quote_intraday(): "interval": "5min" } client = AlphavantageClient().should_retry_once() - intra_day_quote = client.get_intraday_quote(event) - assert not intra_day_quote.limit_reached, f"limit_reached should not be true {intra_day_quote.error_message}" - assert intra_day_quote.success, f"success is false {intra_day_quote.error_message}" - assert len(intra_day_quote.data), f"Did not return data for this symbol {intra_day_quote.symbol}" + quote = client.get_intraday_quote(event) + assert not quote.limit_reached, f"limit_reached should not be true {quote.error_message}" + assert quote.success, f"success is false {quote.error_message}" + assert len(quote.data), f"Did not return data for this symbol {quote.symbol}" logging.warning(f" Successfully quoted cryptocurrency symbol {event['symbol']} in JSON") @@ -178,13 +178,77 @@ def test_can_quote_daily(): "symbol": "VZ" } client = AlphavantageClient().should_retry_once() - daily_quote = client.get_daily_quote(event) - print(daily_quote.json()) - assert not daily_quote.limit_reached, f"limit_reached should not be true {daily_quote.error_message}" - assert daily_quote.success, f"success is false {daily_quote.error_message}" - assert len(daily_quote.data), f"Did not return data for this symbol {daily_quote.symbol}" + quote = client.get_daily_quote(event) + print(quote.json()) + assert not quote.limit_reached, f"limit_reached should not be true {quote.error_message}" + assert quote.success, f"success is false {quote.error_message}" + assert len(quote.data), f"Did not return data for this symbol {quote.symbol}" logging.warning(f" Successfully quoted symbol {event['symbol']} in JSON") +@pytest.mark.integration +def test_can_quote_daily_adjusted(): + event = { + "symbol": "VZ" + } + client = AlphavantageClient().should_retry_once() + quote = client.get_daily_adjusted_quote(event) + print(quote.json()) + assert not quote.limit_reached, f"limit_reached should not be true {quote.error_message}" + assert quote.success, f"success is false {quote.error_message}" + assert len(quote.data), f"Did not return data for this symbol {quote.symbol}" + logging.warning(f" Successfully quoted symbol {event['symbol']} in JSON") + +@pytest.mark.integration +def test_can_quote_weekly(): + event = { + "symbol": "VZ" + } + client = AlphavantageClient().should_retry_once() + quote = client.get_weekly_quote(event) + print(quote.json()) + assert not quote.limit_reached, f"limit_reached should not be true {quote.error_message}" + assert quote.success, f"success is false {quote.error_message}" + assert len(quote.data), f"Did not return data for this symbol {quote.symbol}" + logging.warning(f" Successfully quoted symbol {event['symbol']} in JSON") + +@pytest.mark.integration +def test_can_quote_weekly_adjusted(): + event = { + "symbol": "VZ" + } + client = AlphavantageClient().should_retry_once() + quote = client.get_weekly_adjusted_quote(event) + print(quote.json()) + assert not quote.limit_reached, f"limit_reached should not be true {quote.error_message}" + assert quote.success, f"success is false {quote.error_message}" + assert len(quote.data), f"Did not return data for this symbol {quote.symbol}" + logging.warning(f" Successfully quoted symbol {event['symbol']} in JSON") + +@pytest.mark.integration +def test_can_quote_monthly(): + event = { + "symbol": "VZ" + } + client = AlphavantageClient().should_retry_once() + quote = client.get_monthly_quote(event) + print(quote.json()) + assert not quote.limit_reached, f"limit_reached should not be true {quote.error_message}" + assert quote.success, f"success is false {quote.error_message}" + assert len(quote.data), f"Did not return data for this symbol {quote.symbol}" + logging.warning(f" Successfully quoted symbol {event['symbol']} in JSON") + +@pytest.mark.integration +def test_can_quote_monthly_adjusted(): + event = { + "symbol": "VZ" + } + client = AlphavantageClient().should_retry_once() + quote = client.get_monthly_adjusted_quote(event) + print(quote.json()) + assert not quote.limit_reached, f"limit_reached should not be true {quote.error_message}" + assert quote.success, f"success is false {quote.error_message}" + assert len(quote.data), f"Did not return data for this symbol {quote.symbol}" + logging.warning(f" Successfully quoted symbol {event['symbol']} in JSON") @pytest.mark.integrationn_paid def test_can_quote_crypto(): @@ -195,10 +259,10 @@ def test_can_quote_crypto(): "interval": "5min" } client = AlphavantageClient().should_retry_once() - results = client.get_crypto_intraday(event) - assert not results.limit_reached, f"limit_reached should not be true {results.error_message}" - assert results.success, f"success is false {results.error_message}" - assert len(results.data), "Data{} property is empty but should have information" + quote = client.get_crypto_intraday(event) + assert not quote.limit_reached, f"limit_reached should not be true {quote.error_message}" + assert quote.success, f"success is false {quote.error_message}" + assert len(quote.data), "Data{} property is empty but should have information" logging.warning(f" Successfully quoted cryptocurrency symbol {event['symbol']} in JSON") From cc9ed15ba9a5110e7e879e7fd25a300293ff2e79 Mon Sep 17 00:00:00 2001 From: Ray Garcia Date: Tue, 27 Jun 2023 12:19:46 -0500 Subject: [PATCH 2/3] added method to search ticker --- alphavantage_api_client/__init__.py | 2 +- alphavantage_api_client/client.py | 22 ++++++++++++++++++- alphavantage_api_client/models.py | 4 ++++ tests/test_single_client_cache_integration.py | 18 ++++++++++++++- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/alphavantage_api_client/__init__.py b/alphavantage_api_client/__init__.py index ec68b1a..048a922 100644 --- a/alphavantage_api_client/__init__.py +++ b/alphavantage_api_client/__init__.py @@ -1,4 +1,4 @@ from alphavantage_api_client.client import AlphavantageClient from alphavantage_api_client.models import GlobalQuote, Quote, AccountingReport, CompanyOverview, RealGDP, \ - CsvNotSupported + CsvNotSupported, TickerSearch from alphavantage_api_client.ticker import Ticker diff --git a/alphavantage_api_client/client.py b/alphavantage_api_client/client.py index 4934fd3..1ed6bfc 100644 --- a/alphavantage_api_client/client.py +++ b/alphavantage_api_client/client.py @@ -6,7 +6,7 @@ from .response_validation_rules import ValidationRuleChecks import json from alphavantage_api_client.models import GlobalQuote, Quote, AccountingReport, CompanyOverview, RealGDP, \ - CsvNotSupported + CsvNotSupported, TickerSearch import copy import logging import hashlib @@ -633,3 +633,23 @@ def clear_cache(self): self.__cache__.clear() return self + + def search_ticker(self, event) -> TickerSearch: + """ + We've got you covered! The Search Endpoint returns the best-matching symbols and market information based + on keywords of your choice. The search results also contain match scores that provide you with the full + flexibility to develop your own search and filtering logic. + Args: + event: dict + + Returns: TickerSearch + + """ + defaults = { + "function": "SYMBOL_SEARCH", + "datatype": "json" + } + json_request = self.__create_api_request_from__(defaults, event) + json_response = self.get_data_from_alpha_vantage(json_request, self.__retry__) + + return TickerSearch.parse_obj(json_response) \ No newline at end of file diff --git a/alphavantage_api_client/models.py b/alphavantage_api_client/models.py index b6572ce..58c78c6 100644 --- a/alphavantage_api_client/models.py +++ b/alphavantage_api_client/models.py @@ -23,6 +23,10 @@ class BaseQuote(BaseResponse): symbol: str +class TickerSearch(BaseResponse): + bestMatches: list[dict] + + class Quote(BaseQuote): """ data is this clients abstraction of the response from alpha vantage. Time Series, Technical Indicator diff --git a/tests/test_single_client_cache_integration.py b/tests/test_single_client_cache_integration.py index 9e456de..6fbb6ae 100644 --- a/tests/test_single_client_cache_integration.py +++ b/tests/test_single_client_cache_integration.py @@ -1,6 +1,6 @@ import pytest import time -from alphavantage_api_client import AlphavantageClient, CsvNotSupported +from alphavantage_api_client import AlphavantageClient, CsvNotSupported, TickerSearch import logging import json @@ -161,6 +161,22 @@ def test_can_quote_intraday(): assert len(intra_day_quote.data), f"Did not return data for this symbol {intra_day_quote.symbol}" logging.warning(f" Successfully quoted symbol {event['symbol']} in JSON") +@pytest.mark.integration +def test_can_search_ticker(): + event = { + "keywords" : "Tesla" + } + client = AlphavantageClient() + ticker_search_result = client.search_ticker(event) + assert not ticker_search_result.limit_reached, f"limit_reached should not be true {ticker_search_result.error_message}" + assert ticker_search_result.success, f"success is false {ticker_search_result.error_message}" + assert len(ticker_search_result.bestMatches), f"Did not return bestMatches for this search {event['keywords']}" + for result in ticker_search_result.bestMatches: + assert "9. matchScore" in result, f"9. matchScore property is not in search result for {event['keywords']}" + assert "1. symbol" in result, f"1. symbol property is not in search result for {event['keywords']}" + assert "2. name" in result, f"2. name property is not in search result for {event['keywords']}" + assert "3. type" in result, f"3. type property is not in search result for {event['keywords']}" + @pytest.mark.integration_paid def test_can_quote_daily(): From b95422a0885d322b39a7ab560dbc82ff4d4a244f Mon Sep 17 00:00:00 2001 From: Ray Garcia Date: Tue, 27 Jun 2023 12:31:04 -0500 Subject: [PATCH 3/3] adding method to get market status. now have all time series end points supported and tested --- alphavantage_api_client/__init__.py | 2 +- alphavantage_api_client/client.py | 18 ++++++++++++++++-- alphavantage_api_client/models.py | 3 +++ tests/test_single_client_cache_integration.py | 19 +++++++++++++++++-- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/alphavantage_api_client/__init__.py b/alphavantage_api_client/__init__.py index 048a922..9b83e37 100644 --- a/alphavantage_api_client/__init__.py +++ b/alphavantage_api_client/__init__.py @@ -1,4 +1,4 @@ from alphavantage_api_client.client import AlphavantageClient from alphavantage_api_client.models import GlobalQuote, Quote, AccountingReport, CompanyOverview, RealGDP, \ - CsvNotSupported, TickerSearch + CsvNotSupported, TickerSearch, MarketStatus from alphavantage_api_client.ticker import Ticker diff --git a/alphavantage_api_client/client.py b/alphavantage_api_client/client.py index 1ed6bfc..adb9df5 100644 --- a/alphavantage_api_client/client.py +++ b/alphavantage_api_client/client.py @@ -6,7 +6,7 @@ from .response_validation_rules import ValidationRuleChecks import json from alphavantage_api_client.models import GlobalQuote, Quote, AccountingReport, CompanyOverview, RealGDP, \ - CsvNotSupported, TickerSearch + CsvNotSupported, TickerSearch, MarketStatus import copy import logging import hashlib @@ -652,4 +652,18 @@ def search_ticker(self, event) -> TickerSearch: json_request = self.__create_api_request_from__(defaults, event) json_response = self.get_data_from_alpha_vantage(json_request, self.__retry__) - return TickerSearch.parse_obj(json_response) \ No newline at end of file + return TickerSearch.parse_obj(json_response) + + def get_market_status(self) -> MarketStatus: + """ + This endpoint returns the current market status (open vs. closed) of major trading venues for equities, + forex, and cryptocurrencies around the world. + Returns: + + """ + json_request = { + "function": "MARKET_STATUS" + } + json_response = self.get_data_from_alpha_vantage(json_request, self.__retry__) + + return MarketStatus.parse_obj(json_response) \ No newline at end of file diff --git a/alphavantage_api_client/models.py b/alphavantage_api_client/models.py index 58c78c6..f6b32e8 100644 --- a/alphavantage_api_client/models.py +++ b/alphavantage_api_client/models.py @@ -26,6 +26,9 @@ class BaseQuote(BaseResponse): class TickerSearch(BaseResponse): bestMatches: list[dict] +class MarketStatus(BaseResponse): + endpoint: str + markets: list[dict] class Quote(BaseQuote): """ diff --git a/tests/test_single_client_cache_integration.py b/tests/test_single_client_cache_integration.py index 6fbb6ae..6e770d6 100644 --- a/tests/test_single_client_cache_integration.py +++ b/tests/test_single_client_cache_integration.py @@ -1,6 +1,6 @@ import pytest import time -from alphavantage_api_client import AlphavantageClient, CsvNotSupported, TickerSearch +from alphavantage_api_client import AlphavantageClient, CsvNotSupported, TickerSearch, MarketStatus import logging import json @@ -478,4 +478,19 @@ def test_get_fx_currency_data(): } results = client.get_data_from_alpha_vantage(event) print(results) - assert results["success"], f"FX Exchange call failed{results}" \ No newline at end of file + assert results["success"], f"FX Exchange call failed{results}" + +@pytest.mark.integration +def test_get_market_status(): + market_status = client.get_market_status() + print(market_status) + assert market_status.success, f"success was found to be True which is unexpected: {market_status.error_message}" + assert not market_status.limit_reached, f"limit_reached is true {market_status.error_message}" + assert len(market_status.endpoint), "endPoint is not defined within response" + assert len(market_status.markets), "markets list is missing results" + + for market in market_status.markets: + assert "market_type" in market, "market_type not found within result" + assert "region" in market, "region not found within result" + assert "primary_exchanges" in market, "primary_exchanges not found within result" + assert "local_open" in market, "local_open not found within result"