---
title: FMP Data
---

자연어 쿼리를 통해 금융 시장 데이터에 액세스하세요.

## Overview

FMP(Financial Modeling Prep) LangChain 통합은 자연어 쿼리를 통해 금융 시장 데이터에 액세스할 수 있는 원활한 방법을 제공합니다. 이 통합은 두 가지 주요 컴포넌트를 제공합니다:

- `FMPDataToolkit`: 자연어 쿼리를 기반으로 도구 모음을 생성합니다
- `FMPDataTool`: 적절한 endpoint를 자동으로 선택하고 사용하는 단일 통합 도구입니다

이 통합은 LangChain의 semantic search 기능을 활용하여 사용자 쿼리를 가장 관련성 높은 FMP API endpoint와 매칭함으로써 금융 데이터 액세스를 더욱 직관적이고 효율적으로 만듭니다.

## Setup

```python
!pip install -U langchain-fmp-data
import os

# Replace with your actual API keys
os.environ["FMP_API_KEY"] = "your-fmp-api-key"  # pragma: allowlist secret
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"  # pragma: allowlist secret
최고 수준의 observability를 위해 LangSmith를 설정하는 것도 도움이 됩니다(필수는 아님):
os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass()

Instantiation

FMP LangChain 통합을 인스턴스화하는 두 가지 주요 방법이 있습니다:
  1. FMPDataToolkit 사용
from langchain_fmp_data import FMPDataToolkit

query = "Get stock market prices and technical indicators"
# Basic instantiation
toolkit = FMPDataToolkit(query=query)

# Instantiation with specific query focus
market_toolkit = FMPDataToolkit(
    query=query,
    num_results=5,
)

# Instantiation with custom configuration
custom_toolkit = FMPDataToolkit(
    query="Financial analysis",
    num_results=3,
    similarity_threshold=0.4,
    cache_dir="/custom/cache/path",
)
  1. FMPDataTool 사용
from langchain_fmp_data import FMPDataTool
from langchain_fmp_data.tools import ResponseFormat

# Basic instantiation
tool = FMPDataTool()

# Advanced instantiation with custom settings
advanced_tool = FMPDataTool(
    max_iterations=50,
    temperature=0.2,
)

Invocation

도구는 여러 가지 방법으로 호출할 수 있습니다:

Direct Invocation

# Using FMPDataTool
tool_direct = FMPDataTool()

# Basic query
# fmt: off
result = tool.invoke({"query": "What's Apple's current stock price?"})
# fmt: on

# Advanced query with specific format
# fmt: off
detailed_result = tool_direct.invoke(
    {
        "query": "Compare Tesla and Ford's profit margins",
        "response_format": ResponseFormat.BOTH,
    }
)
# fmt: on

LangChain Agent와 함께 사용하기

from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain_openai import ChatOpenAI

# Setup
llm = ChatOpenAI(temperature=0)
toolkit = FMPDataToolkit(
    query="Stock analysis",
    num_results=3,
)
tools = toolkit.get_tools()

# Create agent
prompt = "You are a helpful assistant. Answer the user's questions based on the provided context."
agent = create_openai_functions_agent(llm, tools, prompt)
agent_executor = AgentExecutor(
    agent=agent,
    tools=tools,
)

# Run query
# fmt: off
response = agent_executor.invoke({"input": "What's the PE ratio of Microsoft?"})
# fmt: on

Advanced Usage

도구의 동작을 커스터마이징할 수 있습니다:
# Initialize with custom settings
advanced_tool = FMPDataTool(
    max_iterations=50,  # Increase max iterations for complex queries
    temperature=0.2,  # Adjust temperature for more/less focused responses
)

# Example of a complex multi-part analysis
query = """
Analyze Apple's financial health by:
1. Examining current ratios and debt levels
2. Comparing profit margins to industry average
3. Looking at cash flow trends
4. Assessing growth metrics
"""
# fmt: off
response = advanced_tool.invoke(
    {
        "query": query,
        "response_format": ResponseFormat.BOTH}
)
# fmt: on
print("Detailed Financial Analysis:")
print(response)

Chaining

원하는 model로 chain을 생성하여 다른 도구와 유사하게 도구를 체이닝할 수 있습니다.
from langchain_core.output_parsers import StrOutputParser
from langchain_openai import ChatOpenAI

# Setup
llm = ChatOpenAI(temperature=0)
toolkit = FMPDataToolkit(query="Stock analysis", num_results=3)
tools = toolkit.get_tools()

llm_with_tools = llm.bind(functions=tools)
output_parser = StrOutputParser()
# Create chain
runner = llm_with_tools | output_parser

# Run chain
# fmt: off
response = runner.invoke(
    {
        "input": "What's the PE ratio of Microsoft?"
    }
)
# fmt: on

API reference

FMPDataToolkit

FMP API 도구 모음을 생성하기 위한 메인 class:
from typing import Any

from langchain.tools import Tool


class FMPDataToolkit:
    """Creates a collection of FMP data tools based on queries."""

    def __init__(
        self,
        query: str | None = None,
        num_results: int = 3,
        similarity_threshold: float = 0.3,
        cache_dir: str | None = None,
    ): ...

    def get_tools(self) -> list[Tool]:
        """Returns a list of relevant FMP API tools based on the query."""
        ...

FMPDataTool

적절한 FMP endpoint를 자동으로 선택하는 통합 도구:
# fmt: off
class FMPDataTool:
    """Single unified tool for accessing FMP data through natural language."""

    def __init__(
            self,
            max_iterations: int = 3,
            temperature: float = 0.0,
    ): ...

    def invoke(
            self,
            input: dict[str, Any],
    ) -> str | dict[str, Any]:
        """Execute a natural language query against FMP API."""
        ...

# fmt: on

ResponseFormat

응답 형식을 제어하기 위한 Enum:
from enum import Enum


class ResponseFormat(str, Enum):
    RAW = "raw"  # Raw API response
    ANALYSIS = "text"  # Natural language analysis
    BOTH = "both"  # Both raw data and analysis

---

<Callout icon="pen-to-square" iconType="regular">
    [Edit the source of this page on GitHub.](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/tools/fmp-data.mdx)
</Callout>
<Tip icon="terminal" iconType="regular">
    [Connect these docs programmatically](/use-these-docs) to Claude, VSCode, and more via MCP for    real-time answers.
</Tip>
I