Skip to content

Commit

Permalink
Merge pull request #4 from caps6/dev
Browse files Browse the repository at this point in the history
bump version 0.1.5
  • Loading branch information
caps6 authored Aug 13, 2024
2 parents cf02c91 + 9abf0ee commit b567fed
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.2
current_version = 0.1.5
commit = True
tag = True

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# yf-data

![application-build](https://github.com/caps6/yf-data/actions/workflows/python-build.yml/badge.svg)
![GitHub Downloads](https://img.shields.io/github/downloads/caps6/yf-data/total)
![PyPI - Downloads](https://img.shields.io/pypi/dm/yfdata)

A simple-but-working python module that returns data from Yahoo Finance.

Current Version: 0.1.2
Current Version: 0.1.5


### Features
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 = "yfdata"
version = "0.1.2"
version = "0.1.5"
description = "Client for Yahoo Finance data"
authors = ["andrea <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setup(
name="yf-data",
version="0.1.2",
version="0.1.5",
keywords="yahoo finance data",
description=DESCRIPTION,
packages=packages,
Expand Down
103 changes: 65 additions & 38 deletions yfdata/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,58 @@ def parse_prices_or_rates(body: dict, ticker_or_pair: str) -> DataFrame:
"""

data = body["chart"]["result"][0]
df = None

metadata = data["meta"]
if metadata["instrumentType"] == "EQUITY" or metadata["instrumentType"] == "ETF":
code_name = "ticker"
elif metadata["instrumentType"] == "CURRENCY":
code_name = "pair"
else:
raise ValueError("Instrument type not supported.")
result = body["chart"]["result"]

ts = data["timestamp"]
if isinstance(result, list) and len(result) > 0:

quotes = data["indicators"]["quote"][0]
data = body["chart"]["result"][0]

df = DataFrame(
data={
"ts": ts,
"o": quotes["open"],
"h": quotes["high"],
"l": quotes["low"],
"c": quotes["close"],
"v": quotes["volume"],
}
)
metadata = data["meta"]
if (
metadata["instrumentType"] == "EQUITY"
or metadata["instrumentType"] == "ETF"
):
code_name = "ticker"
elif metadata["instrumentType"] == "CURRENCY":
code_name = "pair"
else:
raise ValueError("Instrument type not supported.")

if isinstance(data, dict) and "timestamp" in data and "indicators" in data:

ts = data["timestamp"]
quotes = data["indicators"]["quote"][0]

df = DataFrame(
data={
"ts": ts,
"o": quotes["open"],
"h": quotes["high"],
"l": quotes["low"],
"c": quotes["close"],
"v": quotes["volume"],
}
)

if df is None:
code_name = "instrument"
df = DataFrame(
data={
"ts": [],
"o": [],
"h": [],
"l": [],
"c": [],
"v": [],
}
)

df[code_name] = ticker_or_pair.lower()
df["ts"] = pd.to_datetime(df["ts"], unit="s")
# .dt.tz_convert('Europe/Paris').dt.tz_convert('UTC')

# Reorder the columns.
df = df[[code_name, "ts", "o", "h", "l", "c", "v"]]

return df
Expand Down Expand Up @@ -87,15 +110,15 @@ def parse_financials(body: dict, ticker: str, freq: str, mapping: dict) -> DataF
dates.append(item["asOfDate"])
values.append(float(item["reportedValue"]["raw"]))

df = DataFrame(
data={
"date": dates,
"value": values,
}
)
df = DataFrame(
data={
"date": dates,
"value": values,
}
)

df["metric"] = mapping[yahoo_metric_name]
dfs.append(df)
df["metric"] = mapping[yahoo_metric_name]
dfs.append(df)

df = pd.concat(dfs, ignore_index=True)
df["ticker"] = ticker.lower()
Expand All @@ -118,22 +141,26 @@ def parse_dividends(body: dict, ticker: str) -> DataFrame:
"""

data = body["chart"]["result"][0]

dates = []
dividends = []

if "events" in data:
result = body["chart"]["result"]

if isinstance(result, list) and len(result) > 0:

data = result[0]

if isinstance(data, dict) and "events" in data:

dict_dividends = data["events"]["dividends"]
dict_dividends = data["events"]["dividends"]

for uts in dict_dividends:
for uts in dict_dividends:

if "amount" in dict_dividends[uts]:
if "amount" in dict_dividends[uts]:

ts = utils.timestamp2datetime(int(uts))
dates.append(ts)
dividends.append(dict_dividends[uts]["amount"])
ts = utils.timestamp2datetime(int(uts))
dates.append(ts)
dividends.append(dict_dividends[uts]["amount"])

df = DataFrame(
data={
Expand Down

0 comments on commit b567fed

Please sign in to comment.