diff --git a/alphavantage_api_client/client.py b/alphavantage_api_client/client.py index cc5aca9..ca8ebe4 100644 --- a/alphavantage_api_client/client.py +++ b/alphavantage_api_client/client.py @@ -163,6 +163,26 @@ def get_global_quote(self, event: dict) -> GlobalQuote: return GlobalQuote.parse_obj(json_response) + def get_daily_quote(self, event: dict) -> Quote: + """ + This API returns raw (as-traded) daily time series (date, daily open, daily high, daily low, daily close, daily + volume) of the global equity specified, covering 20+ years of historical data. If you are also interested in + split/dividend-adjusted historical data, please use the Daily Adjusted API, which covers adjusted close values + and historical split and dividend events. + Args: + event: dict, required + + Returns: Quote + + """ + # default params + defaults = {"datatype": "json", "function": "TIME_SERIES_DAILY", + "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_intraday_quote(self, event: dict) -> Quote: """ Intraday time series data covering extened trading hours. @@ -476,6 +496,8 @@ def __sleep__(self): now = time.perf_counter() diff = 60 - (now - then) logging.info(f"sleeping for {diff} seconds") + if diff < 0: + diff = 60 time.sleep(diff) def clear_cache(self): diff --git a/alphavantage_api_client/models.py b/alphavantage_api_client/models.py index c667391..4b2168d 100644 --- a/alphavantage_api_client/models.py +++ b/alphavantage_api_client/models.py @@ -147,7 +147,7 @@ class CompanyOverview(BaseQuote): Industry: str = Field(default=None, alias='Industry') address: str = Field(default=None, alias='Address') fiscal_year_end: str = Field(default=None, alias='FiscalYearEnd') - latest_Quarter: str = Field(default=None, alias='LatestQuarter') + latest_quarter: str = Field(default=None, alias='LatestQuarter') market_capitalization: str = Field(default=None, alias='MarketCapitalization') ebitda: str = Field(default=None, alias='EBITDA') pe_ratio: str = Field(default=None, alias='PERatio') diff --git a/alphavantage_api_client/ticker.py b/alphavantage_api_client/ticker.py index 614d9ef..28ba029 100644 --- a/alphavantage_api_client/ticker.py +++ b/alphavantage_api_client/ticker.py @@ -11,6 +11,7 @@ def __init__(self): self.__symbol__: str = None self.__global_quote__: GlobalQuote = None self.__intraday_quote__: Quote = None + self.__daily_quote__: Quote = None self.__earnings__: AccountingReport = None self.__cash_flow__: AccountingReport = None self.__balance_sheet__: AccountingReport = None @@ -53,12 +54,15 @@ def should_retry_once(self, retry_status: bool = True): return self - def fetch_global_quote(self): + def fetch_global_quote(self, params=None): if self.__symbol__ is None or len(self.__symbol__) == 0: raise ValueError("You must define the symbol by calling from_symbol(...)") event = { "symbol": self.__symbol__ } + if params is not None: + self.__client__.__inject_values__(params, event) + self.__global_quote__ = self.__client__.get_global_quote(event) return self @@ -104,12 +108,28 @@ def fetch_company_overview(self): return self - def fetch_intraday_quote(self): + def fetch_daily_quote(self, params=None): if self.__symbol__ is None or len(self.__symbol__) == 0: raise ValueError("You must define the symbol by calling from_symbol(...)") event = { "symbol": self.__symbol__ } + if params is not None: + self.__client__.__inject_values__(params, event) + + daily_quote = self.__client__.get_intraday_quote(event) + self.__daily_quote__ = daily_quote + return self + + def fetch_intraday_quote(self, params=None): + if self.__symbol__ is None or len(self.__symbol__) == 0: + raise ValueError("You must define the symbol by calling from_symbol(...)") + event = { + "symbol": self.__symbol__ + } + if params is not None: + self.__client__.__inject_values__(params, event) + intraday_quote = self.__client__.get_intraday_quote(event) self.__intraday_quote__ = intraday_quote return self @@ -220,7 +240,12 @@ def get_intraday_quote(self) -> Quote: raise ValueError("intraday_quote is not defined. You call fetch_intraday_quote(...) to populate it") return self.__intraday_quote__ - def get_company_overview(self) -> Quote: + def get_daily_quote(self) -> Quote: + if self.__daily_quote__ is None or not self.__daily_quote__: + raise ValueError("daily_quote is not defined. You call fetch_daily_quote(...) to populate it") + return self.__daily_quote__ + + def get_company_overview(self) -> CompanyOverview: if self.__company_overview__ is None or not self.__company_overview__: raise ValueError("company_overview is not defined. You call fetch_company_overview(...) to populate it") return self.__company_overview__ diff --git a/poetry.lock b/poetry.lock index 9053e9c..24d1350 100644 --- a/poetry.lock +++ b/poetry.lock @@ -83,8 +83,8 @@ optional = false python-versions = ">=3.6" [package.extras] -dev = ["pre-commit", "tox"] -testing = ["pytest", "pytest-benchmark"] +testing = ["pytest-benchmark", "pytest"] +dev = ["tox", "pre-commit"] [[package]] name = "py" @@ -177,7 +177,7 @@ python-versions = ">=3.7" [[package]] name = "urllib3" -version = "1.26.10" +version = "1.26.11" description = "HTTP library with thread-safe connection pooling, file post, and more." category = "main" optional = false @@ -190,102 +190,24 @@ socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] [metadata] lock-version = "1.1" -python-versions = "3.10.4" -content-hash = "4a8035d606e7926447e9de6905e99f5d7ccdd7b5cbf8729e4879d54aafe61cf7" +python-versions = "^3.10" +content-hash = "2598ace6c448b698bbe6a8204a307a0ef7402ccf74f8cd6a1fe93d80f0325d05" [metadata.files] atomicwrites = [] -attrs = [ - {file = "attrs-21.4.0-py2.py3-none-any.whl", hash = "sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4"}, - {file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"}, -] -certifi = [ - {file = "certifi-2022.6.15-py3-none-any.whl", hash = "sha256:fe86415d55e84719d75f8b69414f6438ac3547d2078ab91b67e779ef69378412"}, - {file = "certifi-2022.6.15.tar.gz", hash = "sha256:84c85a9078b11105f04f3036a9482ae10e4621616db313fe045dd24743a0820d"}, -] -charset-normalizer = [ - {file = "charset-normalizer-2.1.0.tar.gz", hash = "sha256:575e708016ff3a5e3681541cb9d79312c416835686d054a23accb873b254f413"}, - {file = "charset_normalizer-2.1.0-py3-none-any.whl", hash = "sha256:5189b6f22b01957427f35b6a08d9a0bc45b46d3788ef5a92e978433c7a35f8a5"}, -] -colorama = [ - {file = "colorama-0.4.5-py2.py3-none-any.whl", hash = "sha256:854bf444933e37f5824ae7bfc1e98d5bce2ebe4160d46b5edf346a89358e99da"}, - {file = "colorama-0.4.5.tar.gz", hash = "sha256:e6c6b4334fc50988a639d9b98aa429a0b57da6e17b9a44f0451f930b6967b7a4"}, -] -idna = [ - {file = "idna-3.3-py3-none-any.whl", hash = "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff"}, - {file = "idna-3.3.tar.gz", hash = "sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"}, -] -iniconfig = [ - {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, - {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, -] -packaging = [ - {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, - {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, -] -pluggy = [ - {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, - {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, -] -py = [ - {file = "py-1.11.0-py2.py3-none-any.whl", hash = "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378"}, - {file = "py-1.11.0.tar.gz", hash = "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719"}, -] -pydantic = [ - {file = "pydantic-1.9.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:c8098a724c2784bf03e8070993f6d46aa2eeca031f8d8a048dff277703e6e193"}, - {file = "pydantic-1.9.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c320c64dd876e45254bdd350f0179da737463eea41c43bacbee9d8c9d1021f11"}, - {file = "pydantic-1.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:18f3e912f9ad1bdec27fb06b8198a2ccc32f201e24174cec1b3424dda605a310"}, - {file = "pydantic-1.9.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c11951b404e08b01b151222a1cb1a9f0a860a8153ce8334149ab9199cd198131"}, - {file = "pydantic-1.9.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:8bc541a405423ce0e51c19f637050acdbdf8feca34150e0d17f675e72d119580"}, - {file = "pydantic-1.9.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:e565a785233c2d03724c4dc55464559639b1ba9ecf091288dd47ad9c629433bd"}, - {file = "pydantic-1.9.1-cp310-cp310-win_amd64.whl", hash = "sha256:a4a88dcd6ff8fd47c18b3a3709a89adb39a6373f4482e04c1b765045c7e282fd"}, - {file = "pydantic-1.9.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:447d5521575f18e18240906beadc58551e97ec98142266e521c34968c76c8761"}, - {file = "pydantic-1.9.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:985ceb5d0a86fcaa61e45781e567a59baa0da292d5ed2e490d612d0de5796918"}, - {file = "pydantic-1.9.1-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:059b6c1795170809103a1538255883e1983e5b831faea6558ef873d4955b4a74"}, - {file = "pydantic-1.9.1-cp36-cp36m-musllinux_1_1_i686.whl", hash = "sha256:d12f96b5b64bec3f43c8e82b4aab7599d0157f11c798c9f9c528a72b9e0b339a"}, - {file = "pydantic-1.9.1-cp36-cp36m-musllinux_1_1_x86_64.whl", hash = "sha256:ae72f8098acb368d877b210ebe02ba12585e77bd0db78ac04a1ee9b9f5dd2166"}, - {file = "pydantic-1.9.1-cp36-cp36m-win_amd64.whl", hash = "sha256:79b485767c13788ee314669008d01f9ef3bc05db9ea3298f6a50d3ef596a154b"}, - {file = "pydantic-1.9.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:494f7c8537f0c02b740c229af4cb47c0d39840b829ecdcfc93d91dcbb0779892"}, - {file = "pydantic-1.9.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f0f047e11febe5c3198ed346b507e1d010330d56ad615a7e0a89fae604065a0e"}, - {file = "pydantic-1.9.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:969dd06110cb780da01336b281f53e2e7eb3a482831df441fb65dd30403f4608"}, - {file = "pydantic-1.9.1-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:177071dfc0df6248fd22b43036f936cfe2508077a72af0933d0c1fa269b18537"}, - {file = "pydantic-1.9.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:9bcf8b6e011be08fb729d110f3e22e654a50f8a826b0575c7196616780683380"}, - {file = "pydantic-1.9.1-cp37-cp37m-win_amd64.whl", hash = "sha256:a955260d47f03df08acf45689bd163ed9df82c0e0124beb4251b1290fa7ae728"}, - {file = "pydantic-1.9.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:9ce157d979f742a915b75f792dbd6aa63b8eccaf46a1005ba03aa8a986bde34a"}, - {file = "pydantic-1.9.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:0bf07cab5b279859c253d26a9194a8906e6f4a210063b84b433cf90a569de0c1"}, - {file = "pydantic-1.9.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5d93d4e95eacd313d2c765ebe40d49ca9dd2ed90e5b37d0d421c597af830c195"}, - {file = "pydantic-1.9.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1542636a39c4892c4f4fa6270696902acb186a9aaeac6f6cf92ce6ae2e88564b"}, - {file = "pydantic-1.9.1-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:a9af62e9b5b9bc67b2a195ebc2c2662fdf498a822d62f902bf27cccb52dbbf49"}, - {file = "pydantic-1.9.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:fe4670cb32ea98ffbf5a1262f14c3e102cccd92b1869df3bb09538158ba90fe6"}, - {file = "pydantic-1.9.1-cp38-cp38-win_amd64.whl", hash = "sha256:9f659a5ee95c8baa2436d392267988fd0f43eb774e5eb8739252e5a7e9cf07e0"}, - {file = "pydantic-1.9.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:b83ba3825bc91dfa989d4eed76865e71aea3a6ca1388b59fc801ee04c4d8d0d6"}, - {file = "pydantic-1.9.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:1dd8fecbad028cd89d04a46688d2fcc14423e8a196d5b0a5c65105664901f810"}, - {file = "pydantic-1.9.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:02eefd7087268b711a3ff4db528e9916ac9aa18616da7bca69c1871d0b7a091f"}, - {file = "pydantic-1.9.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7eb57ba90929bac0b6cc2af2373893d80ac559adda6933e562dcfb375029acee"}, - {file = "pydantic-1.9.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:4ce9ae9e91f46c344bec3b03d6ee9612802682c1551aaf627ad24045ce090761"}, - {file = "pydantic-1.9.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:72ccb318bf0c9ab97fc04c10c37683d9eea952ed526707fabf9ac5ae59b701fd"}, - {file = "pydantic-1.9.1-cp39-cp39-win_amd64.whl", hash = "sha256:61b6760b08b7c395975d893e0b814a11cf011ebb24f7d869e7118f5a339a82e1"}, - {file = "pydantic-1.9.1-py3-none-any.whl", hash = "sha256:4988c0f13c42bfa9ddd2fe2f569c9d54646ce84adc5de84228cfe83396f3bd58"}, - {file = "pydantic-1.9.1.tar.gz", hash = "sha256:1ed987c3ff29fff7fd8c3ea3a3ea877ad310aae2ef9889a119e22d3f2db0691a"}, -] -pyparsing = [ - {file = "pyparsing-3.0.9-py3-none-any.whl", hash = "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"}, - {file = "pyparsing-3.0.9.tar.gz", hash = "sha256:2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb"}, -] -pytest = [ - {file = "pytest-7.1.2-py3-none-any.whl", hash = "sha256:13d0e3ccfc2b6e26be000cb6568c832ba67ba32e719443bfe725814d3c42433c"}, - {file = "pytest-7.1.2.tar.gz", hash = "sha256:a06a0425453864a270bc45e71f783330a7428defb4230fb5e6a731fde06ecd45"}, -] -requests = [ - {file = "requests-2.28.1-py3-none-any.whl", hash = "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"}, - {file = "requests-2.28.1.tar.gz", hash = "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983"}, -] -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 = [ - {file = "typing_extensions-4.3.0-py3-none-any.whl", hash = "sha256:25642c956049920a5aa49edcdd6ab1e06d7e5d467fc00e0506c44ac86fbfca02"}, - {file = "typing_extensions-4.3.0.tar.gz", hash = "sha256:e6d2677a32f47fc7eb2795db1dd15c1f34eff616bcaf2cfb5e997f854fa1c4a6"}, -] +attrs = [] +certifi = [] +charset-normalizer = [] +colorama = [] +idna = [] +iniconfig = [] +packaging = [] +pluggy = [] +py = [] +pydantic = [] +pyparsing = [] +pytest = [] +requests = [] +tomli = [] +typing-extensions = [] urllib3 = [] diff --git a/pyproject.toml b/pyproject.toml index 9c3546b..108aced 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ authors = ["Ray Garcia "] license = "MIT" [tool.poetry.dependencies] -python = "3.10.4" +python = "^3.10" requests = "^2.27.1" pydantic = "^1.9.1" diff --git a/tests/test_multi_client_integration.py b/tests/test_multi_client_integration.py index a15933d..3fc1297 100644 --- a/tests/test_multi_client_integration.py +++ b/tests/test_multi_client_integration.py @@ -94,7 +94,7 @@ def test_can_not_global_quote_wrong_symbol_json(): global_quote = client.get_global_quote(event) assert not global_quote.success, f"success was found to be {global_quote.success}: {global_quote.error_message}" assert global_quote.symbol == event.get("symbol"), "Response symbol doesn't matched requested symbol" - #assert not global_quote.limit_reached, f"{global_quote.error_message}" + # assert not global_quote.limit_reached, f"{global_quote.error_message}" assert not len(global_quote.data), "Response should have data but contains zero" logging.warning(f" Can NOT quote stock symbol in JSON {event.get('symbol', None)}") @@ -109,7 +109,7 @@ def test_can_not_global_quote_wrong_symbol_csv(): global_quote = client.get_global_quote(event) assert not global_quote.success, f"success: {global_quote.success}, msg: {global_quote.error_message}" assert global_quote.symbol == event.get("symbol"), "Response symbol doesn't matched requested symbol" - #assert not global_quote.limit_reached, f"{global_quote.error_message}" + # assert not global_quote.limit_reached, f"{global_quote.error_message}" assert global_quote.csv is None, "Response should have data but contains zero" logging.warning(f" Can NOT quote stock symbol in csv {event.get('symbol', None)} : {global_quote.error_message}") @@ -172,6 +172,20 @@ def test_can_quote_intraday(): logging.warning(f" Successfully quoted cryptocurrency symbol {event['symbol']} in JSON") +@pytest.mark.integration +def test_can_quote_daily(): + event = { + "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}" + logging.warning(f" Successfully quoted cryptocurrency symbol {event['symbol']} in JSON") + + @pytest.mark.integration def test_can_quote_crypto(): event = { @@ -308,14 +322,13 @@ def test_can_not_query_csv_company_overview(): @pytest.mark.integration def test_can_not_query_income_statement(): - client = AlphavantageClient() + event = { - "symbol": "tsla2" + "symbol": "tsla22354q2354" } - + client = AlphavantageClient() accounting_report = client.get_income_statement(event) assert not accounting_report.success, f"success was found to be True: {accounting_report.error_message}" - assert not accounting_report.limit_reached, f'{accounting_report.error_message}' assert accounting_report.symbol == event.get("symbol", None), f"Symbols don't match " \ f"{accounting_report.symbol} : {event.get('symbol')}" logging.warning(f" Can not query income statement {accounting_report.error_message}") diff --git a/tests/test_single_client_cache_integration.py b/tests/test_single_client_cache_integration.py index bf505c3..9aa8999 100644 --- a/tests/test_single_client_cache_integration.py +++ b/tests/test_single_client_cache_integration.py @@ -99,7 +99,7 @@ def test_canReachLimitJson(): results = None # force limit reached # my api key is free, so 5 calls per min and total of 500 per day - client.clear_cache().should_retry_once(False) # turn retry off so we can hit limit + client.clear_cache().should_retry_once(False) # turn retry off so we can hit limit for index, symbol in enumerate(symbols): event = { "symbol": symbol @@ -108,7 +108,7 @@ def test_canReachLimitJson(): if results.limit_reached: limit_reached = True break - client.should_retry_once() # turn retry back on + client.should_retry_once() # turn retry back on assert limit_reached, "Failed to reach limit" assert results.symbol == event['symbol'], f" Expected symbol doesn't match given: {event.get('symbol', None)}" logging.warning(f" Can Reach Limit while quoting for symbols {symbols}") @@ -132,7 +132,7 @@ def test_canReachLimitCsv(): limit_reached = True break - client.should_retry_once() # turn retry back on + client.should_retry_once() # turn retry back on assert limit_reached, "Failed to reach limit" assert results.symbol == event['symbol'], f" Expected symbol doesn't match given: {event.get('symbol', None)}" @@ -152,6 +152,18 @@ def test_can_quote_intraday(): logging.warning(f" Successfully quoted cryptocurrency symbol {event['symbol']} in JSON") +@pytest.mark.integration +def test_can_quote_daily(): + event = { + "symbol": "VZ" + } + daily_quote = client.get_daily_quote(event) + 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}" + logging.warning(f" Successfully quoted cryptocurrency symbol {event['symbol']} in JSON") + + @pytest.mark.integration def test_can_quote_crypto(): event = { diff --git a/tests/test_ticker.py b/tests/test_ticker.py index 85b1297..6dff480 100644 --- a/tests/test_ticker.py +++ b/tests/test_ticker.py @@ -46,3 +46,33 @@ def test_get_most_recent_annual_reports(): metrics = ticker.get_client().get_internal_metrics() print("") print(metrics) + + +@pytest.mark.integration +def test_get_intraday_with_params(): + print("") + params = { + "adjusted": False, + "interval": "60min" + } + symbols = ["TSLA", "MSFT", "AMZN", "TDOC", "PATH", "ZM", "C", "VZ"] + ticker = Ticker().create_client().should_retry_once() + for symbol in symbols: + intraday_quote = ticker.from_symbol(symbol).fetch_intraday_quote(params).get_intraday_quote() + assert params["interval"] == intraday_quote.meta_data["4. Interval"], \ + f"The interval doesn't match, {params['interval']} != {intraday_quote.meta_data['4. Interval']}" + +@pytest.mark.integration +def test_get_daily_quote_with_params(): + print("") + params = { + "adjusted": False, + "interval": "60min" + } + symbols = ["TSLA", "MSFT", "AMZN", "TDOC", "PATH", "ZM", "C", "VZ"] + ticker = Ticker().create_client().should_retry_once() + for symbol in symbols: + daily_quote = ticker.from_symbol(symbol).fetch_daily_quote(params).get_daily_quote() + assert params["interval"] == daily_quote.meta_data["4. Interval"], \ + f"The interval doesn't match, {params['interval']} != {daily_quote.meta_data['4. Interval']}" +