Skip to content

Commit

Permalink
Merge branch 'v0.8.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ymyke committed Oct 16, 2023
2 parents 5383ebc + e5a2438 commit a0b72ff
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -51,14 +52,14 @@ 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
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
```

Expand All @@ -81,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.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 2 additions & 6 deletions tessa/price/yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/price/test_price_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
4 changes: 1 addition & 3 deletions tests/price/test_yahoo_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest
from tessa.price import yahoo
from tessa.price.types import SymbolNotFoundError


@pytest.mark.parametrize(
Expand All @@ -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)

0 comments on commit a0b72ff

Please sign in to comment.