本指南为金融建模项目提供全面的安装、配置、使用、测试、开发等方面的详细说明,帮助用户快速上手并高效使用该项目。
本项目提供了两种安装方式,分别是使用 Docker 和虚拟环境,你可以根据自己的需求进行选择。
docker pull ghcr.io/cdtait/fmp-mcp-server:latest
docker run -it --rm \
-p 8000:8000 \
-v "$PWD:/app" \
ghcr.io/cdtait/fmp-mcp-server:latest
-it:保持交互模式并分配终端。--rm:容器退出后自动删除。-p 8000:8000:映射端口,使容器内的服务可在主机上访问。-v "$PWD:/app":将当前目录挂载到容器的 /app 路径。git clone https://github.com/cdtait/fmp-mcp-server.git
cd fmp-mcp-server
python -m venv .venv && source ./.venv/bin/activate
poetry,可以运行:poetry install
pip install -r requirements.txt
python main.py
建议在项目根目录下创建一个 .env 文件,用于存储敏感信息和自定义设置。例如:
# Example .env file contents
FMP_API_KEY=your_api_key_here
OPENAI_API_KEY=your_openai_api_key_here
PORT=9000
TEST_MODE=true # For testing with mock data
可以通过命令行参数覆盖 .env 文件中的默认值:
python main.py --port 8001 --test_mode false
from fmpsdk import get_stock_data
# 示例:获取苹果股票的历史数据
data = get_stock_data(symbol="AAPL", api_key=api_key)
print(data.head())
from fmpsdk import get_fx_rate
# 示例:获取欧元对美元的汇率
rate = get_fx_rate(cross="EURUSD", api_key=api_key)
print(rate)
from utils.data_cleaning import clean_stock_data
# 示例:清洗股票数据
cleaned_data = clean_stock_data(data, fillna=True)
from fmpsdk import get_stock_data
from utils.data_cleaning import clean_stock_data
# 获取股票数据
data = get_stock_data(symbol="AAPL", api_key=api_key)
# 清洗数据
cleaned_data = clean_stock_data(data, fillna=True)
print(cleaned_data.head())
from utils.technical_indicators import calculate_moving_average
# 示例:计算简单移动平均线(SMA)
sma_50 = calculate_moving_average(close_prices, window=50)
print(sma_50.tail())
运行单元测试:
pytest tests/unit_tests/ --cov --report=
运行集成测试:
pytest tests/integration_tests/ --cov --report=
使用 benchmark 库进行性能测试:
import pytest_benchmark
from fmpsdk import get_stock_data
@pytest.mark.benchmark
def test_get_stock_data(benchmark):
benchmark(get_stock_data, symbol="AAPL", api_key=api_key)
fmp-mcp-server/
├── main.py # 主程序入口
├── config/ # 配置文件和环境变量管理
│ └── settings.py
├── data/ # 数据存储和处理逻辑
│ ├── raw_data/
│ └── processed_data/
├── fmpsdk/ # 第三方库接口封装
│ ├── __init__.py
│ └── api.py # API 请求处理
└── tests/ # 测试用例
├── unit_tests/
│ └── test_api.py
└── integration_tests/
└── test_data_cleaning.py
pytest tests/unit_tests/ --cov --report=
pytest tests/integration_tests/ --cov --report=
coverage run -m pytest tests/ && coverage report
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["python", "main.py"]
docker build -t cdtait/fmp-mcp-server:latest .
docker push cdtait/fmp-mcp-server:latest
git checkout -b feature/new-feature
git add .
git commit -m "Add new feature"
git push origin feature/new-feature
docker pull ghcr.io/cdtait/fmp-mcp-server:latest
docker build -t local/fmp-mcp-server .
docker run -it --rm -p 8000:8000 local/fmp-mcp-server
遵循 PEP 8 编码规范。
使用 semver 进行版本管理:
在 github 仓库页面提交 Issues:
https://github.com/cdtait/fmp-mcp-server/issues