initial commit
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
"""Polygon IO tools."""
|
||||
|
||||
from langchain_community.tools.polygon.aggregates import PolygonAggregates
|
||||
from langchain_community.tools.polygon.financials import PolygonFinancials
|
||||
from langchain_community.tools.polygon.last_quote import PolygonLastQuote
|
||||
from langchain_community.tools.polygon.ticker_news import PolygonTickerNews
|
||||
|
||||
__all__ = [
|
||||
"PolygonAggregates",
|
||||
"PolygonFinancials",
|
||||
"PolygonLastQuote",
|
||||
"PolygonTickerNews",
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,77 @@
|
||||
from typing import Optional, Type
|
||||
|
||||
from langchain_core.callbacks import CallbackManagerForToolRun
|
||||
from langchain_core.tools import BaseTool
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from langchain_community.utilities.polygon import PolygonAPIWrapper
|
||||
|
||||
|
||||
class PolygonAggregatesSchema(BaseModel):
|
||||
"""Input for PolygonAggregates."""
|
||||
|
||||
ticker: str = Field(
|
||||
description="The ticker symbol to fetch aggregates for.",
|
||||
)
|
||||
timespan: str = Field(
|
||||
description="The size of the time window. "
|
||||
"Possible values are: "
|
||||
"second, minute, hour, day, week, month, quarter, year. "
|
||||
"Default is 'day'",
|
||||
)
|
||||
timespan_multiplier: int = Field(
|
||||
description="The number of timespans to aggregate. "
|
||||
"For example, if timespan is 'day' and "
|
||||
"timespan_multiplier is 1, the result will be daily bars. "
|
||||
"If timespan is 'day' and timespan_multiplier is 5, "
|
||||
"the result will be weekly bars. "
|
||||
"Default is 1.",
|
||||
)
|
||||
from_date: str = Field(
|
||||
description="The start of the aggregate time window. "
|
||||
"Either a date with the format YYYY-MM-DD or "
|
||||
"a millisecond timestamp.",
|
||||
)
|
||||
to_date: str = Field(
|
||||
description="The end of the aggregate time window. "
|
||||
"Either a date with the format YYYY-MM-DD or "
|
||||
"a millisecond timestamp.",
|
||||
)
|
||||
|
||||
|
||||
class PolygonAggregates(BaseTool):
|
||||
"""
|
||||
Tool that gets aggregate bars (stock prices) over a
|
||||
given date range for a given ticker from Polygon.
|
||||
"""
|
||||
|
||||
mode: str = "get_aggregates"
|
||||
name: str = "polygon_aggregates"
|
||||
description: str = (
|
||||
"A wrapper around Polygon's Aggregates API. "
|
||||
"This tool is useful for fetching aggregate bars (stock prices) for a ticker. "
|
||||
"Input should be the ticker, date range, timespan, and timespan multiplier"
|
||||
" that you want to get the aggregate bars for."
|
||||
)
|
||||
args_schema: Type[PolygonAggregatesSchema] = PolygonAggregatesSchema
|
||||
|
||||
api_wrapper: PolygonAPIWrapper
|
||||
|
||||
def _run(
|
||||
self,
|
||||
ticker: str,
|
||||
timespan: str,
|
||||
timespan_multiplier: int,
|
||||
from_date: str,
|
||||
to_date: str,
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> str:
|
||||
"""Use the Polygon API tool."""
|
||||
return self.api_wrapper.run(
|
||||
mode=self.mode,
|
||||
ticker=ticker,
|
||||
timespan=timespan,
|
||||
timespan_multiplier=timespan_multiplier,
|
||||
from_date=from_date,
|
||||
to_date=to_date,
|
||||
)
|
||||
@@ -0,0 +1,38 @@
|
||||
from typing import Optional, Type
|
||||
|
||||
from langchain_core.callbacks import CallbackManagerForToolRun
|
||||
from langchain_core.tools import BaseTool
|
||||
from pydantic import BaseModel
|
||||
|
||||
from langchain_community.utilities.polygon import PolygonAPIWrapper
|
||||
|
||||
|
||||
class Inputs(BaseModel):
|
||||
"""Inputs for Polygon's Financials API"""
|
||||
|
||||
query: str
|
||||
|
||||
|
||||
class PolygonFinancials(BaseTool):
|
||||
"""Tool that gets the financials of a ticker from Polygon"""
|
||||
|
||||
mode: str = "get_financials"
|
||||
name: str = "polygon_financials"
|
||||
description: str = (
|
||||
"A wrapper around Polygon's Stock Financials API. "
|
||||
"This tool is useful for fetching fundamental financials from "
|
||||
"balance sheets, income statements, and cash flow statements "
|
||||
"for a stock ticker. The input should be the ticker that you want "
|
||||
"to get the latest fundamental financial data for."
|
||||
)
|
||||
args_schema: Type[BaseModel] = Inputs
|
||||
|
||||
api_wrapper: PolygonAPIWrapper
|
||||
|
||||
def _run(
|
||||
self,
|
||||
query: str,
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> str:
|
||||
"""Use the Polygon API tool."""
|
||||
return self.api_wrapper.run(self.mode, ticker=query)
|
||||
@@ -0,0 +1,36 @@
|
||||
from typing import Optional, Type
|
||||
|
||||
from langchain_core.callbacks import CallbackManagerForToolRun
|
||||
from langchain_core.tools import BaseTool
|
||||
from pydantic import BaseModel
|
||||
|
||||
from langchain_community.utilities.polygon import PolygonAPIWrapper
|
||||
|
||||
|
||||
class Inputs(BaseModel):
|
||||
"""Inputs for Polygon's Last Quote API"""
|
||||
|
||||
query: str
|
||||
|
||||
|
||||
class PolygonLastQuote(BaseTool):
|
||||
"""Tool that gets the last quote of a ticker from Polygon"""
|
||||
|
||||
mode: str = "get_last_quote"
|
||||
name: str = "polygon_last_quote"
|
||||
description: str = (
|
||||
"A wrapper around Polygon's Last Quote API. "
|
||||
"This tool is useful for fetching the latest price of a stock. "
|
||||
"Input should be the ticker that you want to query the last price quote for."
|
||||
)
|
||||
args_schema: Type[BaseModel] = Inputs
|
||||
|
||||
api_wrapper: PolygonAPIWrapper
|
||||
|
||||
def _run(
|
||||
self,
|
||||
query: str,
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> str:
|
||||
"""Use the Polygon API tool."""
|
||||
return self.api_wrapper.run(self.mode, ticker=query)
|
||||
@@ -0,0 +1,36 @@
|
||||
from typing import Optional, Type
|
||||
|
||||
from langchain_core.callbacks import CallbackManagerForToolRun
|
||||
from langchain_core.tools import BaseTool
|
||||
from pydantic import BaseModel
|
||||
|
||||
from langchain_community.utilities.polygon import PolygonAPIWrapper
|
||||
|
||||
|
||||
class Inputs(BaseModel):
|
||||
"""Inputs for Polygon's Ticker News API"""
|
||||
|
||||
query: str
|
||||
|
||||
|
||||
class PolygonTickerNews(BaseTool):
|
||||
"""Tool that gets the latest news for a given ticker from Polygon"""
|
||||
|
||||
mode: str = "get_ticker_news"
|
||||
name: str = "polygon_ticker_news"
|
||||
description: str = (
|
||||
"A wrapper around Polygon's Ticker News API. "
|
||||
"This tool is useful for fetching the latest news for a stock. "
|
||||
"Input should be the ticker that you want to get the latest news for."
|
||||
)
|
||||
args_schema: Type[BaseModel] = Inputs
|
||||
|
||||
api_wrapper: PolygonAPIWrapper
|
||||
|
||||
def _run(
|
||||
self,
|
||||
query: str,
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> str:
|
||||
"""Use the Polygon API tool."""
|
||||
return self.api_wrapper.run(self.mode, ticker=query)
|
||||
Reference in New Issue
Block a user