mirror of https://github.com/hwchase17/langchain
community[minor]: Add Alpha Vantage API Tool (#14332)
### Description This implementation adds functionality from the AlphaVantage API, renowned for its comprehensive financial data. The class encapsulates various methods, each dedicated to fetching specific types of financial information from the API. ### Implemented Functions - **`search_symbols`**: - Searches the AlphaVantage API for financial symbols using the provided keywords. - **`_get_market_news_sentiment`**: - Retrieves market news sentiment for a specified stock symbol from the AlphaVantage API. - **`_get_time_series_daily`**: - Fetches daily time series data for a specific symbol from the AlphaVantage API. - **`_get_quote_endpoint`**: - Obtains the latest price and volume information for a given symbol from the AlphaVantage API. - **`_get_time_series_weekly`**: - Gathers weekly time series data for a particular symbol from the AlphaVantage API. - **`_get_top_gainers_losers`**: - Provides details on top gainers, losers, and most actively traded tickers in the US market from the AlphaVantage API. ### Issue: - #11994 ### Dependencies: - 'requests' library for HTTP requests. (import requests) - 'pytest' library for testing. (import pytest) --------- Co-authored-by: Adam Badar <94140103+adam-badar@users.noreply.github.com> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com> Co-authored-by: Bagatur <baskaryan@gmail.com>pull/14283/head
parent
a9bc212bf2
commit
0884e5de7f
@ -0,0 +1,66 @@
|
||||
"""Integration test for Alpha Vantage API Wrapper."""
|
||||
import pytest
|
||||
|
||||
from langchain_community.utilities.alpha_vantage import AlphaVantageAPIWrapper
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def api_wrapper() -> AlphaVantageAPIWrapper:
|
||||
# Ensure that the ALPHAVANTAGE_API_KEY environment variable is set
|
||||
return AlphaVantageAPIWrapper()
|
||||
|
||||
|
||||
def test_search_symbols(api_wrapper: AlphaVantageAPIWrapper) -> None:
|
||||
"""Test the search symbols API call for successful response."""
|
||||
response = api_wrapper.search_symbols("AAPL")
|
||||
assert response is not None
|
||||
assert isinstance(response, dict)
|
||||
|
||||
|
||||
def test_market_news_sentiment(api_wrapper: AlphaVantageAPIWrapper) -> None:
|
||||
"""Test the market news sentiment API call for successful response."""
|
||||
response = api_wrapper._get_market_news_sentiment("AAPL")
|
||||
assert response is not None
|
||||
assert isinstance(response, dict)
|
||||
|
||||
|
||||
def test_time_series_daily(api_wrapper: AlphaVantageAPIWrapper) -> None:
|
||||
"""Test the time series daily API call for successful response."""
|
||||
response = api_wrapper._get_time_series_daily("AAPL")
|
||||
assert response is not None
|
||||
assert isinstance(response, dict)
|
||||
|
||||
|
||||
def test_quote_endpoint(api_wrapper: AlphaVantageAPIWrapper) -> None:
|
||||
"""Test the quote endpoint API call for successful response."""
|
||||
response = api_wrapper._get_quote_endpoint("AAPL")
|
||||
assert response is not None
|
||||
assert isinstance(response, dict)
|
||||
|
||||
|
||||
def test_time_series_weekly(api_wrapper: AlphaVantageAPIWrapper) -> None:
|
||||
"""Test the time series weekly API call for successful response."""
|
||||
response = api_wrapper._get_time_series_weekly("AAPL")
|
||||
assert response is not None
|
||||
assert isinstance(response, dict)
|
||||
|
||||
|
||||
def test_top_gainers_losers(api_wrapper: AlphaVantageAPIWrapper) -> None:
|
||||
"""Test the top gainers and losers API call for successful response."""
|
||||
response = api_wrapper._get_top_gainers_losers()
|
||||
assert response is not None
|
||||
assert isinstance(response, dict)
|
||||
|
||||
|
||||
def test_exchange_rate(api_wrapper: AlphaVantageAPIWrapper) -> None:
|
||||
"""Test the exchange rate API call for successful response."""
|
||||
response = api_wrapper._get_exchange_rate("USD", "EUR")
|
||||
assert response is not None
|
||||
assert isinstance(response, dict)
|
||||
|
||||
|
||||
def test_run_method(api_wrapper: AlphaVantageAPIWrapper) -> None:
|
||||
"""Test the run method for successful response."""
|
||||
response = api_wrapper.run("USD", "EUR")
|
||||
assert response is not None
|
||||
assert isinstance(response, dict)
|
Loading…
Reference in New Issue