From 9dcd8c8ac895d42ef6a683fb078f54a423b25fd8 Mon Sep 17 00:00:00 2001 From: ymyke Date: Mon, 16 Oct 2023 13:26:33 +0200 Subject: [PATCH 1/6] Fix test (Apparently, Yahoo Finance changed some historical values slightly.) --- tests/price/test_price_points.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/price/test_price_points.py b/tests/price/test_price_points.py index 73a2455..6ae1c06 100644 --- a/tests/price/test_price_points.py +++ b/tests/price/test_price_points.py @@ -62,7 +62,7 @@ def test_concrete_yahoo_price_point(): res = price_point("AAPL", "2018-01-11", "yahoo") assert isinstance(res, PricePoint) assert res.when == pd.Timestamp("2018-01-11 05:00:00+0000", tz="UTC") - assert round(res.price) == 42 + assert round(res.price) == 41 assert res.currency == "USD" From 2462be65d0d52869949b15bac7e81aadf3375758 Mon Sep 17 00:00:00 2001 From: ymyke Date: Mon, 16 Oct 2023 15:45:17 +0200 Subject: [PATCH 2/6] Expose/raise all yfinance exceptions Otherwise, we potentially run into problems later on. See #19 for an example. Unfortunately, yfinance currently doesn't give very useful information in its exceptions and therefore doesn't help to understand the underlying issue (i.e., symbol not found vs no network connectivity at all vs ...). Therefore we no longer raise a `SymbolNotFoundException` any longer here but simply pass through what yfinance raises. Resolves #19 --- tessa/price/yahoo.py | 8 ++------ tests/price/test_yahoo_api.py | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/tessa/price/yahoo.py b/tessa/price/yahoo.py index 8707c7e..f4f9353 100644 --- a/tessa/price/yahoo.py +++ b/tessa/price/yahoo.py @@ -2,7 +2,7 @@ import pandas as pd import yfinance as yf -from .types import PriceHistory, SymbolNotFoundError +from .types import PriceHistory START_FROM = "2000-01-01" """Adjust this date if you need to get historical data further in the past. Note that @@ -18,11 +18,7 @@ def get_price_history( that ticker. """ ticker = yf.Ticker(query) - try: - df = ticker.history(start=START_FROM, raise_errors=True) - except Exception as exc: # pylint: disable=broad-except - if "No timezone found" in str(exc): - raise SymbolNotFoundError(source="yahoo", query=query) from exc + df = ticker.history(start=START_FROM, raise_errors=True) # Simplify dataframe: df = df.copy() diff --git a/tests/price/test_yahoo_api.py b/tests/price/test_yahoo_api.py index 5c58106..0ea7f94 100644 --- a/tests/price/test_yahoo_api.py +++ b/tests/price/test_yahoo_api.py @@ -4,7 +4,6 @@ import pytest from tessa.price import yahoo -from tessa.price.types import SymbolNotFoundError @pytest.mark.parametrize( @@ -28,6 +27,5 @@ def test_api_returns_reasonable_data(query: str, expected_currency: str): @pytest.mark.net def test_non_existing_query_raises(): - with pytest.raises(SymbolNotFoundError) as excinfo: + with pytest.raises(Exception): yahoo.get_price_history("thisshouldntexistreally") - assert "No symbol found" in str(excinfo.value) From e9c240ac39959788071fb59379c06c5a09f7947c Mon Sep 17 00:00:00 2001 From: ymyke Date: Mon, 16 Oct 2023 16:01:02 +0200 Subject: [PATCH 3/6] Add comment re 5xx retries --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 985180e..bd5e32b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ and load them, and extend their functionality. Finally, tessa makes sure to be nice to the sites being accessed and tries to **prevent users from being blocked by 429 rate limiting errors** by 1) caching results upon retrieval and 2) keeping track of request timestamps and waiting appropriate amounts of -time if necessary. +time if necessary. tessa also automatically waits and retries requests that fail with a +5xx error. [→ Check out the full documentation. 📖](https://ymyke.github.io/tessa/tessa.html) From ab35ef694f4d9222109d718a39a9cd4ec54673e8 Mon Sep 17 00:00:00 2001 From: ymyke Date: Mon, 16 Oct 2023 16:01:28 +0200 Subject: [PATCH 4/6] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bd5e32b..3f3df01 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ s3 = Symbol("bitcoin", source="coingecko") s3.price_graph() # show price graph ``` -- Search for a more crypto ticker on coingecko: +- Search for a crypto ticker on coingecko: ```python res = search("GAME") # search and print search result summary From 40730ce55f4ecaef9f61eaf09a037341e5eabff3 Mon Sep 17 00:00:00 2001 From: ymyke Date: Mon, 16 Oct 2023 16:01:35 +0200 Subject: [PATCH 5/6] Switch from GAME to ENS --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3f3df01..9dd99aa 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,11 @@ s3.price_graph() # show price graph - Search for a crypto ticker on coingecko: ```python -res = search("GAME") # search and print search result summary +res = search("name") # search and print search result summary filtered = res.filter(source="coingecko") # filter results filtered.p() # print summary of filtered results -filtered.buckets[0].symbols # review the best bucket in the filtered results -s4 = filtered.buckets[0].symbols[2] # our symbol is the 3rd in that list +filtered.buckets[1].symbols # review the 2nd bucket in the filtered results +s4 = filtered.buckets[1].symbols[2] # our symbol is the 3rd in that list s4.price_history() # get entire history ``` @@ -82,9 +82,9 @@ sc_new.load_yaml("my_symbols.yaml") - Use a different currency preference: ```python -sc.find_one("game").price_latest() # will return price in USD +sc.find_one("ens").price_latest() # will return price in USD Symbol.currency_preference = "CHF" -sc.find_one("game").price_latest() # will return price in CHF +sc.find_one("ens").price_latest() # will return price in CHF ``` Note that `currency_preference` will only have an effect with sources that support it. From e5a24380b18ccb0c6ccd3cb13c4c3054e8cdf6c1 Mon Sep 17 00:00:00 2001 From: ymyke Date: Mon, 16 Oct 2023 16:06:02 +0200 Subject: [PATCH 6/6] Bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 06520e2..9a53c3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "tessa" -version = "0.8.0" +version = "0.8.1" description = "Find financial assets and get their price history without worrying about different APIs or rate limiting." authors = ["ymyke"] license = "MIT"