Skip to content

Commit

Permalink
Added support for historical data
Browse files Browse the repository at this point in the history
  • Loading branch information
yushdotkapoor authored Nov 25, 2024
1 parent 2a3e443 commit 6f9be2f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/fear_and_greed/cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,24 @@ def get(fetcher: Fetcher = None) -> FearGreedIndex:
description=response["rating"],
last_update=datetime.datetime.fromisoformat(response["timestamp"]),
)

def historical(fetcher: Fetcher = None) -> dict:
"""Returns CNN's Fear & Greed Index historical data."""

if fetcher is None:
fetcher = Fetcher()

response = fetcher()["fear_and_greed_historical"]
fear_greed_historical = []

if "data" in response:
historical_data = response["data"]
for data in historical_data:
fear_greed_historical.append(FearGreedIndex(
value=data["y"],
description=data["rating"],
last_update=datetime.datetime.fromtimestamp(data["x"] / 1000),
))

return fear_greed_historical

0 comments on commit 6f9be2f

Please sign in to comment.