주식 증권 api 연동 및 window pc AI 연동 기능 구현 시작
This commit is contained in:
@@ -2,11 +2,17 @@ import os
|
||||
from fastapi import FastAPI
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
|
||||
from .db import init_db, save_articles, get_latest_articles
|
||||
from .db import init_db, save_articles, get_latest_articles
|
||||
from .scraper import fetch_market_news, fetch_major_indices, fetch_overseas_news
|
||||
from .kis_api import KisApi
|
||||
from .analysis import AIAnalyst
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
scheduler = BackgroundScheduler(timezone=os.getenv("TZ", "Asia/Seoul"))
|
||||
kis = KisApi()
|
||||
analyst = AIAnalyst()
|
||||
|
||||
@app.on_event("startup")
|
||||
def on_startup():
|
||||
@@ -53,8 +59,37 @@ def get_indices():
|
||||
def trigger_scrap():
|
||||
"""수동 스크랩 트리거"""
|
||||
run_scraping_job()
|
||||
run_scraping_job()
|
||||
return {"ok": True}
|
||||
|
||||
# --- Trading API ---
|
||||
|
||||
@app.get("/api/trade/balance")
|
||||
def get_balance():
|
||||
"""계좌 잔고 조회 (보유주식 + 예수금)"""
|
||||
return kis.get_balance()
|
||||
|
||||
class OrderRequest(BaseModel):
|
||||
code: str
|
||||
qty: int
|
||||
price: int = 0 # 0이면 시장가
|
||||
type: str # 'buy' or 'sell'
|
||||
|
||||
@app.post("/api/trade/order")
|
||||
def order_stock(req: OrderRequest):
|
||||
"""주식 매수/매도 주문"""
|
||||
if req.type not in ["buy", "sell"]:
|
||||
return {"success": False, "message": "Invalid type (buy/sell)"}
|
||||
|
||||
return kis.order(req.code, req.qty, req.price, req.type)
|
||||
|
||||
@app.get("/api/stock/analyze")
|
||||
def analyze_market():
|
||||
"""최신 뉴스를 기반으로 AI 시장 요약"""
|
||||
articles = get_latest_articles(20)
|
||||
result = analyst.analyze_market_summary(articles)
|
||||
return {"analysis": result, "model": analyst.model}
|
||||
|
||||
@app.get("/api/version")
|
||||
def version():
|
||||
return {"version": os.getenv("APP_VERSION", "dev")}
|
||||
|
||||
Reference in New Issue
Block a user