Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tradingagents/dataflows/alpha_vantage_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
from datetime import datetime
from io import StringIO
from typing import Union

API_BASE_URL = "https://www.alphavantage.co/query"

Expand Down Expand Up @@ -39,7 +40,7 @@ class AlphaVantageRateLimitError(Exception):
"""Exception raised when Alpha Vantage API rate limit is exceeded."""
pass

def _make_api_request(function_name: str, params: dict) -> dict | str:
def _make_api_request(function_name: str, params: dict) -> Union[dict, str]:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The function implementation shows that it always returns response_text, which is a string. It never returns a dictionary, as the JSON is only parsed to check for API errors before being discarded. Therefore, the return type hint should be str instead of Union[dict, str] to accurately reflect the function's behavior and prevent confusion for developers and static analysis tools.

Suggested change
def _make_api_request(function_name: str, params: dict) -> Union[dict, str]:
def _make_api_request(function_name: str, params: dict) -> str:

"""Helper function to make API requests and handle responses.

Raises:
Expand Down
5 changes: 3 additions & 2 deletions tradingagents/dataflows/alpha_vantage_news.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .alpha_vantage_common import _make_api_request, format_datetime_for_api
from typing import Union

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the PEP 8 style guide, imports should be grouped in the following order: standard library, third-party, and then local application imports. typing is a standard library module and should be imported before local imports like .alpha_vantage_common.

To fix this, you would move this line above the import on line 1. Due to tooling limitations, I cannot provide an automated suggestion that spans both lines, but the correct order would be:

from typing import Union
from .alpha_vantage_common import _make_api_request, format_datetime_for_api


def get_news(ticker, start_date, end_date) -> dict[str, str] | str:
def get_news(ticker, start_date, end_date) -> Union[dict[str, str], str]:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This function returns the raw string response from _make_api_request. It does not parse the JSON, so it never returns a dict. The return type hint should be str to reflect this.

Additionally, to improve code clarity and maintainability, it's good practice to add type hints for the function's parameters.

Suggested change
def get_news(ticker, start_date, end_date) -> Union[dict[str, str], str]:
def get_news(ticker: str, start_date: str, end_date: str) -> str:

"""Returns live and historical market news & sentiment data from premier news outlets worldwide.

Covers stocks, cryptocurrencies, forex, and topics like fiscal policy, mergers & acquisitions, IPOs.
Expand All @@ -24,7 +25,7 @@ def get_news(ticker, start_date, end_date) -> dict[str, str] | str:

return _make_api_request("NEWS_SENTIMENT", params)

def get_insider_transactions(symbol: str) -> dict[str, str] | str:
def get_insider_transactions(symbol: str) -> Union[dict[str, str], str]:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to get_news, this function returns a string from _make_api_request, not a dictionary. The return type hint should be str to accurately represent the function's output.

Suggested change
def get_insider_transactions(symbol: str) -> Union[dict[str, str], str]:
def get_insider_transactions(symbol: str) -> str:

"""Returns latest and historical insider transactions by key stakeholders.

Covers transactions by founders, executives, board members, etc.
Expand Down