From 89406d1ffbb0037ac1b42060b344be4331283cc9 Mon Sep 17 00:00:00 2001 From: Alvaro Bartolome Date: Sun, 16 Oct 2022 18:56:20 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Add=20`has=5Fvolume`=20check=20?= =?UTF-8?q?from=20`investing=5Finfo`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/investiny/historical.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/investiny/historical.py b/src/investiny/historical.py index 23681a0..3d72c56 100644 --- a/src/investiny/historical.py +++ b/src/investiny/historical.py @@ -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 @@ -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, @@ -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") From 454acacdb8b85d990a3d961f397707d18c71176d Mon Sep 17 00:00:00 2001 From: Alvaro Bartolome Date: Sun, 16 Oct 2022 18:56:44 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A7=AA=20Add=20unit=20test=20for=20`h?= =?UTF-8?q?istorical=5Fdata`=20w/o=20volume?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/conftest.py | 5 +++++ tests/test_historical.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 3084d1e..71797f3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/test_historical.py b/tests/test_historical.py index 076bd16..deeb219 100644 --- a/tests/test_historical.py +++ b/tests/test_historical.py @@ -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()