Skip to content

Commit

Permalink
πŸ”€ Merge pull request #46 from alvarobartt/volume-check
Browse files Browse the repository at this point in the history
✨ Add `has_volume` check to avoid `n/a` volume values
  • Loading branch information
alvarobartt authored Oct 16, 2022
2 parents e644cf2 + 454acac commit 78aa35d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/investiny/historical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any, Dict, Literal, Union

from investiny.config import Config
from investiny.info import investing_info
from investiny.utils import calculate_date_intervals, request_to_investing


Expand Down Expand Up @@ -44,6 +45,8 @@ def historical_data(
Config.time_format if interval not in ["D", "W", "M"] else Config.date_format
)

has_volume = not investing_info(investing_id=investing_id)["has_no_volume"]

for to_datetime, from_datetime in zip(to_datetimes, from_datetimes):
params = {
"symbol": investing_id,
Expand All @@ -64,7 +67,7 @@ def historical_data(
result["high"] += data["h"] # type: ignore
result["low"] += data["l"] # type: ignore
result["close"] += data["c"] # type: ignore
if "v" in data:
if has_volume:
result["volume"] += data["v"] # type: ignore
if len(result["volume"]) < 1:
result.pop("volume")
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ def assets() -> str:
def asset_list() -> List[str]:
"""List of assets to retrieve their information from Investing.com."""
return ["NASDAQ:AAPL", "NASDAQ:GOOGL"]


@pytest.fixture
def investing_id_no_volume() -> int:
return 1
7 changes: 7 additions & 0 deletions tests/test_historical.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ def test_historical_wide_range(
)
assert res["date"][0] == from_date_wide_range
assert res["date"][-1] == to_date_wide_range


@pytest.mark.usefixtures("investing_id_no_volume")
def test_historical_no_volume(investing_id_no_volume: int) -> None:
res = historical_data(investing_id=investing_id_no_volume)
assert isinstance(res, dict)
assert "volume" not in res.keys()

0 comments on commit 78aa35d

Please sign in to comment.