315105cebb
- 투자 의견 조회
ㄴ 전반적인 주식 판단 기준(ex. 채무, 리스크 등등)을 기준으로 판단하여 도출
- 투자 추천
ex)
{
"tickers": [
"NVDA", "GOOGL", "AAPL"
],
"risk_type": "aggressive"
}
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
import yfinance as yf
|
|
from ta.trend import MACD, SMAIndicator
|
|
from ta.momentum import RSIIndicator
|
|
|
|
async def get_technical_info(ticker: str):
|
|
"""
|
|
yfinance, ta api 이용
|
|
"""
|
|
|
|
# 주가 데이터 다운로드
|
|
df = yf.download(ticker, period="1y", interval="1d")
|
|
# 종가 가져오기
|
|
close = df["Close"].squeeze()
|
|
|
|
macd = MACD(close)
|
|
macd_value = float(macd.macd().iloc[-1])
|
|
signal_value = float(macd.macd_signal().iloc[-1])
|
|
trend = "bullish" if macd_value > signal_value else "bearish"
|
|
|
|
return {
|
|
# 현재주가
|
|
"current_price": close.iloc[-1],
|
|
# 20일선
|
|
"sma20": float(SMAIndicator(close, window=20).sma_indicator().iloc[-1]),
|
|
# 60일선
|
|
"sma60": float(SMAIndicator(close, window=60).sma_indicator().iloc[-1]),
|
|
# rsi
|
|
"rsi": float(RSIIndicator(close, window=14).rsi().iloc[-1]),
|
|
# macd
|
|
"macd": macd_value,
|
|
# macd_signal
|
|
"macd_signal": signal_value,
|
|
# trend
|
|
"trend": trend,
|
|
} |