Skip to content

Commit

Permalink
πŸ› Fix day-shift in some Investing.com assets
Browse files Browse the repository at this point in the history
Some assets such as the bond yields have incorrect timestamps shifted by one day, and doesn't seem to be related with timezone issues, as previously thought.
  • Loading branch information
alvarobartt committed Oct 16, 2022
1 parent b0ffe30 commit 3cd31e9
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/investiny/historical.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Copyright 2022 Alvaro Bartolome, alvarobartt @ GitHub
# See LICENSE for details.

from datetime import datetime
from datetime import datetime, timedelta
from typing import Any, Dict, Literal, Union

import pytz

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 @@ -50,9 +47,6 @@ def historical_data(
Config.time_format if interval not in ["D", "W", "M"] else Config.date_format
)

info = investing_info(investing_id=investing_id)
tz = pytz.timezone(info["timezone"])

for to_datetime, from_datetime in zip(to_datetimes, from_datetimes):
params = {
"symbol": investing_id,
Expand All @@ -61,8 +55,12 @@ def historical_data(
"resolution": interval,
}
data = request_to_investing(endpoint="history", params=params)
# Dates are shifted due to an Investing.com issue with returned timestamps
days_shift = (datetime.fromtimestamp(data["t"][0]) - from_datetime).days # type: ignore
result["date"] += [
datetime.fromtimestamp(t, tz=tz).strftime(datetime_format)
(datetime.fromtimestamp(t) - timedelta(days=days_shift)).strftime(
datetime_format
)
for t in data["t"] # type: ignore
]
result["open"] += data["o"] # type: ignore
Expand Down

0 comments on commit 3cd31e9

Please sign in to comment.