Skip to main content

Find financial assets and get their price history without worrying about different APIs or rate limiting.

Project description

tessa – simple, hassle-free access to price information of financial assets

tessa is a Python library to help you easily retrieve price information for assets from different sources such as Yahoo or Coingecko. It takes care of the different APIs, caching, rate limiting, and other hassles.

tessa provides a Symbol class that encapsulates the methods relevant for a symbol. tessa also provides functionality to manage collections of symbols, store 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. tessa also automatically waits and retries requests that fail with a 5xx error.

→ Check out the full documentation. 📖

How to use

Here's a longer example that shows all aspects of the library. Refer to submodules symbol, search, and price for more information.

Imports:
from tessa import Symbol, SymbolCollection, search
import pendulum
Create a symbol for MSFT and access some functions:
s1 = Symbol("MSFT")             # will use "yahoo" as the default source
s1.price_latest()               # get latest price
Create another symbol from a bloomberg ticker as it is used by Yahoo Finance:
s2 = Symbol("SREN.SW")
s2.price_point("2022-06-30")    # get price at specific point in time
Create a symbol from the coingecko source with an id as it is used by coingecko:
s3 = Symbol("bitcoin", source="coingecko")
s3.price_graph()                # show price graph
Search for a crypto ticker on coingecko:
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[1].symbols  # review the 2nd bucket in the filtered results
s4 = filtered.buckets[1].symbols[4]  # our symbol is the 5th in that list
s4.price_history()  # get entire history
s4.price_graph()  # visualize the price history
Build a collection of several symbols and use the collection to retrieve symbols:
sc = SymbolCollection([s1, s2, s3, s4])   # create a collection w/ symbols from above
sc.add(Symbol("AAPL"))                    # add another one
sc.find_one("SREN").price_graph()
Store and load a symbol collection:
sc.save_yaml("my_symbols.yaml")
sc_new = SymbolCollection()
sc_new.load_yaml("my_symbols.yaml")
Use a different currency preference:
sc.find_one("ens").price_latest()   # will return price in USD
Symbol.currency_preference = "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. It is supported for Coingecko but not for Yahoo. So you should always verify the effective currency you receive in the result.

On Yahoo, some tickers are listed in several currency-specific variants that you can try:

Symbol("ETH-USD").price_latest()  # will return the price in USD
Symbol("ETH-EUR").price_latest()  # will return the price in EUR
Accessing older crypto price information:

Coingecko only provides a limited amount of historical data:

from_date = (pendulum.now() - pendulum.duration(months=6)).to_date_string()
Symbol("bitcoin", source="coingecko").price_point(from_date)
# Will work because coingecko has data for the last year
Symbol("bitcoin", source="coingecko").price_point("2020-08-01")
# Will result in a value error as the data is not available

Yahoo also lists a number of crypto assets with longer history, so you can try that source as well:

Symbol("BTC-USD").price_point(from_date)  # Should work, "yahoo" is the default source
price_point tries to be lenient and you can adjust the leniency:

By default, price_point will try to find the closest price to the requested date as long as it's not more than max_date_deviation_days days away (default: 10 days).

ea = Symbol("EA")
ea.price_point("2022-01-01")  # Will return the price for 2021-12-31
Symbol.max_date_deviation_days = 0
ea.price_point("2022-01-01")  # Will raise a ValueError

Data sources

tessa builds on yfinance and pycoingecko and offers a simplified and unified interface.

Why these two sources? Yahoo Finance (via yfinance) is fast and offers an extensive database that also contains many non-US markets and many crypto tokens. Coingecko (via pycoingecko) offers great access to crypto prices, but is limited to 1 year of historical data.

More sources can be added in the future. Let me know in the issues of you have a particular request.

Main submodules

  • symbol: working with symbols and symbol collections.
  • search: searching the different sources.
  • price: accessing price functions directly instead of via the Symbol class.
  • sources: if you'd like to add additional sources to the library.

How to install

pip install tessa

Requires Python 3.10 or higher.

Prerequisites

See pyproject.toml. Major prerequisites are the yfinance and pycoingecko packages to access finance information.

Repository

https://github.com/ymyke/tessa

On terminology

I'm using symbol instead of ticker because a ticker is mainly used for stock on stock markets, whereas tessa is inteded to be used for any kind of financial assets, e.g. also crypto.

Other noteworthy libraries

  • strela: A python package for financial alerts.
  • pypme: A Python package for PME (Public Market Equivalent) calculation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tessa-0.10.1.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tessa-0.10.1-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file tessa-0.10.1.tar.gz.

File metadata

  • Download URL: tessa-0.10.1.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.9.13 Windows/10

File hashes

Hashes for tessa-0.10.1.tar.gz
Algorithm Hash digest
SHA256 d99c51efdbfd85fecddbef9f74c68bbc651b9c4ad6795e6af735898d492e8873
MD5 d803f61a3bf608b8a1debb4ccacab5a0
BLAKE2b-256 810f98490cb47682ca711644df302c81d9022e01665019bc17bc57b3b05d1e79

See more details on using hashes here.

File details

Details for the file tessa-0.10.1-py3-none-any.whl.

File metadata

  • Download URL: tessa-0.10.1-py3-none-any.whl
  • Upload date:
  • Size: 28.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.9.13 Windows/10

File hashes

Hashes for tessa-0.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6cde999b2218c9c9ac050bbb1a150643446f27609aeca323492da5f62cb83405
MD5 5feb5cd99f3708cd30be4c961d05c133
BLAKE2b-256 e26808a957b6fe3226cbc5259cda7c552e4cf7e99e304966fffb17a6d945d36f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page