Skip to content

Commit

Permalink
Fixed: current prices - float values.
Browse files Browse the repository at this point in the history
  • Loading branch information
im-n1 committed Aug 31, 2023
1 parent 30ce04c commit e7f3aca
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 0.9.1

- fixed `Yahoo.get_current_price_change()` return values - returns floats or `None` now

### 0.9

- new `EtfDb.get_holdings()` method
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
author = "Pavel Hrdina"

# The full version, including alpha/beta/rc tags
release = "0.9"
release = "0.9.1"


# -- General configuration ---------------------------------------------------
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 = "rug"
version = "0.9"
version = "0.9.1-post2"
description = "Library for fetching various stock data from the internet (official and unofficial APIs)."
authors = ["Pavel Hrdina"]
classifiers = [
Expand Down
31 changes: 22 additions & 9 deletions rug/yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def get_current_price_change(self):
- value
- value
Values are floats (if present) or None.
Returned dict looks like:
.. code-block:: python
Expand Down Expand Up @@ -122,24 +123,36 @@ def get_state(data):
output = {
"pre_market": {
"change": {
"percents": output.get("pre_market_change_percents"),
"value": output.get("pre_market_change"),
"percents": float(val) * 100
if (val := output.get("pre_market_change_percents"))
else None,
"value": float(val)
if (val := output.get("pre_market_change"))
else None,
},
"value": output.get("pre_market_price"),
"value": float(val)
if (val := output.get("pre_market_price"))
else None,
},
"current_market": {
"change": {
"percents": output["change_percents"],
"value": output["change"],
"percents": float(output["change_percents"]) * 100,
"value": float(output["change"]),
},
"value": output["price"],
"value": float(output["price"]),
},
"post_market": {
"change": {
"percents": output.get("post_market_change_percents"),
"value": output.get("post_market_change"),
"percents": float(val) * 100
if (val := output.get("post_market_change_percents"))
else None,
"value": float(val)
if (val := output.get("post_market_change"))
else None,
},
"value": output.get("post_market_price"),
"value": float(val)
if (val := output.get("post_market_price"))
else None,
},
}
output["state"] = get_state(output)
Expand Down
1 change: 0 additions & 1 deletion tests/test_etfdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ def do_test(symbol):

def test_get_holdings():
holdings = EtfDb("SPLG").get_holdings()
print(holdings)
assert 15 == len(holdings)
assert "AAPL" in [h[0] for h in holdings]

0 comments on commit e7f3aca

Please sign in to comment.