stock-lab 자동 매매 요청 삭제, 수동 매매 요청 추가
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import json
|
||||
from typing import Optional
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
@@ -7,6 +8,17 @@ import requests
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from pydantic import BaseModel
|
||||
|
||||
# ... (중략) ...
|
||||
|
||||
class OrderRequest(BaseModel):
|
||||
code: str
|
||||
name: Optional[str] = None # 종목명 (옵션)
|
||||
qty: int
|
||||
price: int = 0 # 0이면 시장가
|
||||
type: str # 'buy' or 'sell'
|
||||
|
||||
@app.post("/api/trade/order")
|
||||
|
||||
|
||||
|
||||
from .db import init_db, save_articles, get_latest_articles
|
||||
@@ -98,10 +110,11 @@ def get_balance():
|
||||
)
|
||||
|
||||
class OrderRequest(BaseModel):
|
||||
code: str
|
||||
qty: int
|
||||
ticker: str # 종목 코드 (예: "005930")
|
||||
action: str # "BUY" or "SELL"
|
||||
quantity: int # 주문 수량
|
||||
price: int = 0 # 0이면 시장가
|
||||
type: str # 'buy' or 'sell'
|
||||
reason: Optional[str] = "Manual Order" # 주문 사유 (AI 기록용)
|
||||
|
||||
@app.post("/api/trade/order")
|
||||
def order_stock(req: OrderRequest):
|
||||
@@ -122,27 +135,6 @@ def order_stock(req: OrderRequest):
|
||||
content={"error": "Connection Failed", "detail": str(e), "target": WINDOWS_AI_SERVER_URL}
|
||||
)
|
||||
|
||||
@app.post("/api/trade/auto")
|
||||
def auto_trade():
|
||||
"""AI 자동 매매 트리거 (Windows AI Server Proxy)"""
|
||||
print(f"[Proxy] Triggering Auto Trade at {WINDOWS_AI_SERVER_URL}...")
|
||||
try:
|
||||
# 빈 JSON Body를 명시적으로 전송하여 422 에러 방지
|
||||
resp = requests.post(f"{WINDOWS_AI_SERVER_URL}/trade/auto", json={}, timeout=120)
|
||||
|
||||
if resp.status_code != 200:
|
||||
print(f"[ProxyError] Auto Trade Error: {resp.status_code} {resp.text}")
|
||||
return JSONResponse(status_code=resp.status_code, content=resp.json())
|
||||
|
||||
result = resp.json()
|
||||
print(f"[Proxy] Auto Trade Success. Response:\n{json.dumps(result, indent=2, ensure_ascii=False)}")
|
||||
return result
|
||||
except Exception as e:
|
||||
print(f"[ProxyError] Auto Trade Connection Failed: {e}")
|
||||
return JSONResponse(
|
||||
status_code=500,
|
||||
content={"error": "Connection Failed", "detail": str(e), "target": WINDOWS_AI_SERVER_URL}
|
||||
)
|
||||
|
||||
@app.get("/api/stock/analyze")
|
||||
def analyze_market():
|
||||
|
||||
Reference in New Issue
Block a user