langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
95.3k stars 15.46k forks source link

Add Polygon Finance Tool #27383

Open efriis opened 1 month ago

efriis commented 1 month ago

Discussed in https://github.com/langchain-ai/langchain/discussions/27321

Originally posted by **kritgrover** October 13, 2024 ### Checked - [X] I searched existing ideas and did not find a similar one - [X] I added a very descriptive title - [X] I've clearly described the feature request and motivation for it ### Feature request As mentioned in, https://github.com/langchain-ai/langchain/discussions/27176, we would like to add a tool that integrates with the Bloomberg and Polygon Finance API. We initially had Yahoo Finance in our plan but after doing some research we found that the official API was discontinued in 2017. Users will benefit from expanded access to comprehensive financial data, enabling better decision-making and deeper market analysis. The tool would take a query from an agent, gather the relevant information from our Finance Tools, format the information into a readable output, and return the result to the agent. **Sample Usage:** ```python from langchain_community.tools import PolygonFinanceQueryRun from langchain_community.utilities import PolygonFinanceAPIWrapper # Initialize the Polygon API wrapper and query tool api_wrapper = PolygonFinanceAPIWrapper() tool = PolygonFinanceQueryRun(api_wrapper=api_wrapper) # Example query for real-time cryptocurrency data, not supported by Google Finance query = "BTC-USD real-time price" # Run the query and print the result result = tool.run({'query': query}) print(result) ``` **Sample Output:** ``` { "symbol": "BTC-USD", "name": "Bitcoin", "price": "35,640.12", "timestamp": "2024-10-14T14:35:20Z", "open": "34,920.15", "high": "35,800.50", "low": "34,500.00", "volume": "22,650 BTC", "market_status": "Open", "currency": "USD" } ``` **Sample Usage 2:** ```python from langchain_community.tools import BloombergFinanceQueryRun from langchain_community.utilities import BloombergFinanceAPIWrapper # Initialize the Bloomberg API wrapper and query tool api_wrapper = BloombergFinanceAPIWrapper() tool = BloombergFinanceQueryRun(api_wrapper=api_wrapper) # Example query for bond market data, something Google Finance can't access query = "US 10-year treasury bond yield" # Run the query and print the result result = tool.run({'query': query}) print(result) ``` **Sample Output 2:** ``` { "symbol": "US10YT", "name": "US 10-Year Treasury Bond Yield", "yield": "4.16%", "date": "2024-10-14", "open": "4.12%", "high": "4.18%", "low": "4.10%", "previous_close": "4.13%", "market_status": "Open", "currency": "USD" } ``` ### Motivation The objective is to extend LangChain’s financial capabilities by adding Bloomberg and Polygon Finance tools and addressing the limitations in Google Finance, which primarily focuses on basic stock quotes and limited historical data. Polygon provides real-time, low-latency data across various asset classes, including stocks, forex, and cryptocurrencies, while Bloomberg offers institutional-grade data, global market coverage, and detailed financial analytics. These additions will enable more advanced financial applications, from algorithmic trading to in-depth market research, by offering more comprehensive data and insights, filling the gaps left by Google Finance’s limited coverage of certain asset classes and professional-grade metrics. ### Proposal (If applicable) We are planning to make an addition to the tools contained in libs/community/langchain_community/tools and follow a similar structure to the existing tools, such as GoogleFinanceQueryRun. If this idea is approved, we hope to submit a PR by November. Here is an outline of the changes we are anticipating to make: We plan to modify the following files: ``` libs/community/langchain_community/agent_toolkits/load_tools.py to register our tool libs/community/langchain_community/tools/__init__.py to register the tool libs/langchain/langchain/tools/__init__.py to register the tool ``` We plan to create the following files: ``` libs/community/langchain_community/tools/bloomberg_finance where we will define the class BloombergFinanceQueryRun which inherits from BaseTool libs/community/langchain_community/utilities/bloomberg_finance which we will define the class BloombergFinanceAPIWrapper that inherits from BaseModel libs/community/tests/integration_tests/utilities/test_bloomberg_finance.py where we will define test cases to test our tool ``` We are planning to use Bloomberg's [B-PIPE](https://www.bloomberg.com/professional/products/data/enterprise-catalog/market/#global-connectivity) to access market data. A similar approach will be used for Polygon Finance API.
efriis commented 1 month ago

assigning to @kritgrover

efriis commented 1 month ago

(can't officially assign issue til they interact but just in case someone comments)

kritgrover commented 1 month ago

On it!