mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-13 13:36:15 +00:00
community: Add stock market tools from financialdatasets.ai (#25025)
**Description:** In this PR, I am adding three stock market tools from financialdatasets.ai (my API!): - get balance sheets - get cash flow statements - get income statements Twitter handle: [@virattt](https://twitter.com/virattt) --------- Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
"""financial datasets tools."""
|
||||
|
||||
from langchain_community.tools.financial_datasets.balance_sheets import (
|
||||
BalanceSheets,
|
||||
)
|
||||
from langchain_community.tools.financial_datasets.cash_flow_statements import (
|
||||
CashFlowStatements,
|
||||
)
|
||||
from langchain_community.tools.financial_datasets.income_statements import (
|
||||
IncomeStatements,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"BalanceSheets",
|
||||
"CashFlowStatements",
|
||||
"IncomeStatements",
|
||||
]
|
@@ -0,0 +1,62 @@
|
||||
from typing import Optional, Type
|
||||
|
||||
from langchain_core.callbacks import CallbackManagerForToolRun
|
||||
from langchain_core.pydantic_v1 import BaseModel, Field
|
||||
from langchain_core.tools import BaseTool
|
||||
|
||||
from langchain_community.utilities.financial_datasets import FinancialDatasetsAPIWrapper
|
||||
|
||||
|
||||
class BalanceSheetsSchema(BaseModel):
|
||||
"""Input for BalanceSheets."""
|
||||
|
||||
ticker: str = Field(
|
||||
description="The ticker symbol to fetch balance sheets for.",
|
||||
)
|
||||
period: str = Field(
|
||||
description="The period of the balance sheets. "
|
||||
"Possible values are: "
|
||||
"annual, quarterly, ttm. "
|
||||
"Default is 'annual'.",
|
||||
)
|
||||
limit: int = Field(
|
||||
description="The number of balance sheets to return. " "Default is 10.",
|
||||
)
|
||||
|
||||
|
||||
class BalanceSheets(BaseTool):
|
||||
"""
|
||||
Tool that gets balance sheets for a given ticker over a given period.
|
||||
"""
|
||||
|
||||
mode: str = "get_balance_sheets"
|
||||
name: str = "balance_sheets"
|
||||
description: str = (
|
||||
"A wrapper around financial datasets's Balance Sheets API. "
|
||||
"This tool is useful for fetching balance sheets for a given ticker."
|
||||
"The tool fetches balance sheets for a given ticker over a given period."
|
||||
"The period can be annual, quarterly, or trailing twelve months (ttm)."
|
||||
"The number of balance sheets to return can also be "
|
||||
"specified using the limit parameter."
|
||||
)
|
||||
args_schema: Type[BalanceSheetsSchema] = BalanceSheetsSchema
|
||||
|
||||
api_wrapper: FinancialDatasetsAPIWrapper = Field(..., exclude=True)
|
||||
|
||||
def __init__(self, api_wrapper: FinancialDatasetsAPIWrapper):
|
||||
super().__init__(api_wrapper=api_wrapper)
|
||||
|
||||
def _run(
|
||||
self,
|
||||
ticker: str,
|
||||
period: str,
|
||||
limit: Optional[int],
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> str:
|
||||
"""Use the Balance Sheets API tool."""
|
||||
return self.api_wrapper.run(
|
||||
mode=self.mode,
|
||||
ticker=ticker,
|
||||
period=period,
|
||||
limit=limit,
|
||||
)
|
@@ -0,0 +1,62 @@
|
||||
from typing import Optional, Type
|
||||
|
||||
from langchain_core.callbacks import CallbackManagerForToolRun
|
||||
from langchain_core.pydantic_v1 import BaseModel, Field
|
||||
from langchain_core.tools import BaseTool
|
||||
|
||||
from langchain_community.utilities.financial_datasets import FinancialDatasetsAPIWrapper
|
||||
|
||||
|
||||
class CashFlowStatementsSchema(BaseModel):
|
||||
"""Input for CashFlowStatements."""
|
||||
|
||||
ticker: str = Field(
|
||||
description="The ticker symbol to fetch cash flow statements for.",
|
||||
)
|
||||
period: str = Field(
|
||||
description="The period of the cash flow statement. "
|
||||
"Possible values are: "
|
||||
"annual, quarterly, ttm. "
|
||||
"Default is 'annual'.",
|
||||
)
|
||||
limit: int = Field(
|
||||
description="The number of cash flow statements to return. " "Default is 10.",
|
||||
)
|
||||
|
||||
|
||||
class CashFlowStatements(BaseTool):
|
||||
"""
|
||||
Tool that gets cash flow statements for a given ticker over a given period.
|
||||
"""
|
||||
|
||||
mode: str = "get_cash_flow_statements"
|
||||
name: str = "cash_flow_statements"
|
||||
description: str = (
|
||||
"A wrapper around financial datasets's Cash Flow Statements API. "
|
||||
"This tool is useful for fetching cash flow statements for a given ticker."
|
||||
"The tool fetches cash flow statements for a given ticker over a given period."
|
||||
"The period can be annual, quarterly, or trailing twelve months (ttm)."
|
||||
"The number of cash flow statements to return can also be "
|
||||
"specified using the limit parameter."
|
||||
)
|
||||
args_schema: Type[CashFlowStatementsSchema] = CashFlowStatementsSchema
|
||||
|
||||
api_wrapper: FinancialDatasetsAPIWrapper = Field(..., exclude=True)
|
||||
|
||||
def __init__(self, api_wrapper: FinancialDatasetsAPIWrapper):
|
||||
super().__init__(api_wrapper=api_wrapper)
|
||||
|
||||
def _run(
|
||||
self,
|
||||
ticker: str,
|
||||
period: str,
|
||||
limit: Optional[int],
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> str:
|
||||
"""Use the Cash Flow Statements API tool."""
|
||||
return self.api_wrapper.run(
|
||||
mode=self.mode,
|
||||
ticker=ticker,
|
||||
period=period,
|
||||
limit=limit,
|
||||
)
|
@@ -0,0 +1,62 @@
|
||||
from typing import Optional, Type
|
||||
|
||||
from langchain_core.callbacks import CallbackManagerForToolRun
|
||||
from langchain_core.pydantic_v1 import BaseModel, Field
|
||||
from langchain_core.tools import BaseTool
|
||||
|
||||
from langchain_community.utilities.financial_datasets import FinancialDatasetsAPIWrapper
|
||||
|
||||
|
||||
class IncomeStatementsSchema(BaseModel):
|
||||
"""Input for IncomeStatements."""
|
||||
|
||||
ticker: str = Field(
|
||||
description="The ticker symbol to fetch income statements for.",
|
||||
)
|
||||
period: str = Field(
|
||||
description="The period of the income statement. "
|
||||
"Possible values are: "
|
||||
"annual, quarterly, ttm. "
|
||||
"Default is 'annual'.",
|
||||
)
|
||||
limit: int = Field(
|
||||
description="The number of income statements to return. " "Default is 10.",
|
||||
)
|
||||
|
||||
|
||||
class IncomeStatements(BaseTool):
|
||||
"""
|
||||
Tool that gets income statements for a given ticker over a given period.
|
||||
"""
|
||||
|
||||
mode: str = "get_income_statements"
|
||||
name: str = "income_statements"
|
||||
description: str = (
|
||||
"A wrapper around financial datasets's Income Statements API. "
|
||||
"This tool is useful for fetching income statements for a given ticker."
|
||||
"The tool fetches income statements for a given ticker over a given period."
|
||||
"The period can be annual, quarterly, or trailing twelve months (ttm)."
|
||||
"The number of income statements to return can also be "
|
||||
"specified using the limit parameter."
|
||||
)
|
||||
args_schema: Type[IncomeStatementsSchema] = IncomeStatementsSchema
|
||||
|
||||
api_wrapper: FinancialDatasetsAPIWrapper = Field(..., exclude=True)
|
||||
|
||||
def __init__(self, api_wrapper: FinancialDatasetsAPIWrapper):
|
||||
super().__init__(api_wrapper=api_wrapper)
|
||||
|
||||
def _run(
|
||||
self,
|
||||
ticker: str,
|
||||
period: str,
|
||||
limit: Optional[int],
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> str:
|
||||
"""Use the Income Statements API tool."""
|
||||
return self.api_wrapper.run(
|
||||
mode=self.mode,
|
||||
ticker=ticker,
|
||||
period=period,
|
||||
limit=limit,
|
||||
)
|
Reference in New Issue
Block a user