π° μ΄ νλ‘μ νΈλ μΌν νμ΄λΈμ€ λ°μ΄ν°λ₯Ό νμ©ν λ κ°μ§ μμ€ν μ μ 곡ν©λλ€:
- FastAPI μλ²: μ€μκ° μΌν νμ΄λΈμ€ λ°μ΄ν° API
- λ°μ΄ν°λ² μ΄μ€ μμ€ν : νκ΅ μ£Όμ λ°μ΄ν° μμ§ λ° μ μ₯ μμ€ν
- β‘ κ³ μ±λ₯: FastAPI κΈ°λ° λΉλκΈ° μ²λ¦¬
- π ν¬κ΄μ κΈμ΅ λ°μ΄ν°:
- κ³Όκ±° μ£Όκ° λ°μ΄ν° (OHLCV)
- κΈ°μ μ 보 λ° μ§ν
- μ¬λ¬΄μ ν (μμ΅κ³μ°μ, λμ°¨λμ‘°ν, νκΈνλ¦ν)
- μ£Όμ£Ό μ 보 λ° μ λ리μ€νΈ μΆμ²
- π μμ : λ°μ΄ν° κ²μ¦ λ° μ€λ₯ μ²λ¦¬
- π μλ λ¬Έμν:
/docsμμ μΈν°λν°λΈ API λ¬Έμ
- π°π· νκ΅ μ£Όμ νΉν: KOSPI/KOSDAQ μ μ’ λͺ© μ§μ
- π κΈ°μ μ μ§ν: RSI, MACD, λ³Όλ¦°μ λ°΄λ λ± μλ κ³μ°
- π μμ₯ ν΅κ³: μμΉ/νλ½ μ’ λͺ© μ, κ±°λλ/κ±°λλκΈ
- π μλ μ λ°μ΄νΈ: μΌμΌ λ°μ΄ν° μλ μμ§
yahoo-finance-mcp/
βββ server.py # FastAPI μλ² (μ€μκ° λ°μ΄ν°)
βββ models.py # λ°μ΄ν°λ² μ΄μ€ λͺ¨λΈ μ μ
βββ data_importer.py # λ°μ΄ν° μμ§ λ° μ μ₯ λ‘μ§
βββ run_update.py # DB μ
λ°μ΄νΈ λ©μΈ μ€ν¬λ¦½νΈ
βββ test_db.py # λΉ λ₯Έ ν
μ€νΈ μ€ν¬λ¦½νΈ
βββ README_DATABASE.md # λ°μ΄ν°λ² μ΄μ€ μμΈ λ¬Έμ
βββ README.md # μ΄ λ¬Έμ
pip install ta sqlalchemy psycopg2-binary pykrx tqdm yfinance fastapi uvicorn# PostgreSQL μ€μΉ λ° μμ
brew install postgresql@14
brew services start postgresql@14
# λ°μ΄ν°λ² μ΄μ€ μμ±
createdb finance_dbuvicorn server:app --reload --host 0.0.0.0 --port 8000μ μ μ£Όμ:
- API μλ²:
http://localhost:8000 - Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
python run_update.py init 3python run_update.py update 2python test_db.py| μλν¬μΈνΈ | μ€λͺ | μμ |
|---|---|---|
GET /stock/history |
κ³Όκ±° OHLCV λ°μ΄ν° | ?ticker=005930.KS&period=1y |
GET /stock/info |
κΈ°μ μ 보 λ° μ§ν | ?ticker=005930.KS |
GET /stock/actions |
λ°°λΉ λ° μ£Όμ λΆν | ?ticker=005930.KS |
| μλν¬μΈνΈ | μ€λͺ | λ§€κ°λ³μ |
|---|---|---|
GET /stock/financials |
μμ΅κ³μ°μ, λμ°¨λμ‘°ν, νκΈνλ¦ν | ticker, financial_type |
μ¬λ¬΄μ ν νμ :
income_stmt- μ°κ° μμ΅κ³μ°μquarterly_income_stmt- λΆκΈ° μμ΅κ³μ°μbalance_sheet- μ°κ° λμ°¨λμ‘°νquarterly_balance_sheet- λΆκΈ° λμ°¨λμ‘°νcashflow- μ°κ° νκΈνλ¦νquarterly_cashflow- λΆκΈ° νκΈνλ¦ν
# μΌμ±μ μ 1λ
μ£Όκ° λ°μ΄ν°
curl "http://localhost:8000/stock/history?ticker=005930.KS&period=1y&interval=1d"
# λ€μ΄λ² κΈ°μ
μ 보
curl "http://localhost:8000/stock/info?ticker=035420.KS"
# SKνμ΄λμ€ μ°κ° μμ΅κ³μ°μ
curl "http://localhost:8000/stock/financials?ticker=000660.KS&financial_type=income_stmt"- Stock: μ’ λͺ© κΈ°λ³Έ μ 보
- DailyPrice: μΌμΌ μ£Όκ° λ°μ΄ν°
- TechnicalIndicator: κΈ°μ μ μ§ν
- MarketIndex: μμ₯ μ§μ (KOSPI, KOSDAQ)
- MarketStat: μμ₯ ν΅κ³
- μ’ λͺ© μμ§: pykrx β Yahoo Finance νμ λ³ν
- μ£Όκ° λ°μ΄ν°: λ³λ ¬ μ²λ¦¬λ‘ λΉ λ₯Έ μμ§
- κΈ°μ μ μ§ν: ta λΌμ΄λΈλ¬λ¦¬λ‘ μλ κ³μ°
- μμ₯ ν΅κ³: μΌμΌ μμ₯ λν₯ λΆμ
# crontab -e
30 15 * * 1-5 cd /path/to/project && python run_update.py update 2docker build -t yahoo-finance-api .
docker run -d -p 8000:8000 --name yahoo-finance-api yahoo-finance-apidocker run -d \
--name yahoo-finance-api \
--restart unless-stopped \
-p 8000:8000 \
--health-cmd="curl -f http://localhost:8000/docs || exit 1" \
--health-interval=30s \
yahoo-finance-api:latest- λ°μ΄ν°λ² μ΄μ€ μμ€ν : README_DATABASE.md
- API λ¬Έμ: μλ² μ€ν ν
/docsκ²½λ‘
- νκ΅ μ£Όμ μ΅μ ν: KOSPI/KOSDAQ μ μ’ λͺ© μ§μ
- μ€μκ° + νμ€ν 리: μ€μκ° API + μΆμ λ λ°μ΄ν°λ² μ΄μ€
- λ³λ ¬ μ²λ¦¬: λΉ λ₯Έ λμ©λ λ°μ΄ν° μμ§
- μμ μ±: μ€λ₯ 볡ꡬ λ° μ¬μλ λ‘μ§
- νμ₯μ±: μλ‘μ΄ μ§ν λ° κΈ°λ₯ μ½κ² μΆκ°
- μλν: λ¬΄μΈ μ΄μ κ°λ₯ν μ λ°μ΄νΈ μμ€ν
- 404: μ’ λͺ©μ μ°Ύμ μ μμ
- 500: λ΄λΆ μλ² μ€λ₯ (μμΈ μ 보 ν¬ν¨)
- 422: κ²μ¦ μ€λ₯ (μλͺ»λ λ§€κ°λ³μ)
MIT License - LICENSE νμΌ μ°Έμ‘°