Skip to main content

Thin python wrapper to retrieve and work with Yahoo! finance data

Project description

yfbasic

A thin python wrapper to retrieve price action data from the Yahoo! finance API.

There are similar packages available that does this, most notably yfinance. The purpose of this package is to present the raw data as typed objects to be consumed as desired.

Getting started

The interface is straight forward, just import and query.

import yfbasic

data = yfbasic.query("GME")

The supporting parameters are typed as well.

import yfbasic
from yfbasic import Range, Interval

data = yfbasic.query("GME", range=Range.r1mo, interval=Interval.i1h)

You can use query_threaded to parallelise the data retrieval.

import yfbasic

symbols = ("GME", "AMC", "TSLA")

data = yfbasic.query_threaded(symbols)

Working with the data

The data is modelled directly of the structure returned by the yahoo api. This makes it a bit more low level to work with, but the package makes no presumptions about how you intend to work with the data.

The best way to understand the data is to look at the data structure directly.

Error handling

If we look at the Chart data model it contains two optional parameters, result and error which means we need to do application side checking of the data. To satisfy type safety we need to at least verify the existence of results by checking data.chart.results . If we want insight into any API side errors we could verify and action upon data.chart.error

import yfbasic

data = yfbasic.query("GME")

# verifying the API produced results.
if data.chart.result:
    result = data.chart.result[0]
    quotes = result.indicators.quote[0]

    # getting price action data
    timestamps = result.timestamp
    open = quotes.open
    close = quotes.close
    high = quotes.high
    low = quotes.low
    volume = quotes.volume

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

yfbasic-0.2.0.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

yfbasic-0.2.0-py3-none-any.whl (5.5 kB view hashes)

Uploaded Python 3

Supported by

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