Polygon IO Toolkit and Tools
This notebook shows how to use agents to interact with the Polygon IO toolkit. The toolkit provides access to Polygon's Stock Market Data API.
Setupโ
Installationโ
To use Polygon IO tools, you need to install the langchain-community
package.
%pip install -qU langchain-community > /dev/null
Credentialsโ
Get your Polygon IO API key here, and then set it below.
import getpass
import os
if "POLYGON_API_KEY" not in os.environ:
os.environ["POLYGON_API_KEY"] = getpass.getpass()
It's also helpful (but not needed) to set up LangSmith for best-in-class observability
# os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass()
Toolkitโ
Polygon IO provides both a toolkit and individual tools for each of the tools included in the toolkit. Let's first explore using the toolkit and then we will walk through using the individual tools.
Initializationโ
We can initialize the toolkit by importing it alongside the API wrapper needed to use the tools.
from langchain_community.agent_toolkits.polygon.toolkit import PolygonToolkit
from langchain_community.utilities.polygon import PolygonAPIWrapper
polygon = PolygonAPIWrapper()
toolkit = PolygonToolkit.from_polygon_api_wrapper(polygon)
API Reference:PolygonToolkit | PolygonAPIWrapper
Toolsโ
We can examine the tools included in this toolkit:
toolkit.get_tools()
[PolygonAggregates(api_wrapper=PolygonAPIWrapper(polygon_api_key='K231Rg76pOsN_IdT2eWhCC9npBguCYEj')),
PolygonLastQuote(api_wrapper=PolygonAPIWrapper(polygon_api_key='K231Rg76pOsN_IdT2eWhCC9npBguCYEj')),
PolygonTickerNews(api_wrapper=PolygonAPIWrapper(polygon_api_key='K231Rg76pOsN_IdT2eWhCC9npBguCYEj')),
PolygonFinancials(api_wrapper=PolygonAPIWrapper(polygon_api_key='K231Rg76pOsN_IdT2eWhCC9npBguCYEj'))]