본문으로 건너뛰기

미국 주식 AI 분석 (TSLA)

LLM 기반 멀티 에이전트가 TSLA 한 종목을 분석하고, 결정에 따라 Alpaca 페이퍼로 주문을 내고 체결을 실시간 구독하는 시나리오입니다.

학습 목표

  • POST /api/equity/analyzeGET /api/equity/reports/{id} 라이프사이클
  • 분석 보고서의 decision/agents 필드 해석
  • 페이퍼 주문 제출 시 bracket(TP/SL) 사용법
  • WebSocket /ws/equity/orders로 체결 이벤트 추적

사전 준비

  • Alpaca 페이퍼 API 키 등록 (SettingsExchange Keysus_equity)
  • FEATURE_EQUITY_ANALYSIS=true, FEATURE_EQUITY_PAPER=true
  • LLM 예산 여유 확인 (SettingsNotifications → 예산 카드)

1단계: 분석 요청

EquityReports 탭에서 New Analysis → 종목 TSLA, 모드 standard 선택. 또는 cURL:

curl -X POST http://localhost:8000/api/equity/analyze \
-H "Authorization: Bearer $JWT" \
-H "Content-Type: application/json" \
-d '{
"symbol": "TSLA",
"mode": "standard",
"inline": false,
"priority": 0
}'

응답:

{
"report_id": "0c3a5b...",
"queue_id": 142,
"status": "queued"
}

2단계: 보고서 폴링

curl -H "Authorization: Bearer $JWT" \
"http://localhost:8000/api/equity/reports/0c3a5b..."

statusdone이 되면 다음과 같은 페이로드를 받습니다.

{
"report_id": "0c3a5b...",
"asset_class": "us_equity",
"symbol": "TSLA",
"mode": "standard",
"status": "done",
"score": 0.72,
"decision": "buy",
"confidence": 0.72,
"cost_usd": 0.0123,
"decision_output": {
"signal": "buy",
"ideal_buy": 188.20,
"secondary_buy": 184.50,
"stop_loss": 179.00,
"take_profit": 205.00,
"currency": "USD"
}
}

3단계: 에이전트 trace 확인

각 에이전트(technical/intel/risk/decision)의 단계별 추론을 확인합니다.

curl -H "Authorization: Bearer $JWT" \
"http://localhost:8000/api/equity/reports/0c3a5b.../traces"

Reports 상세 페이지의 Trace 탭에서도 동일 정보를 시각적으로 볼 수 있습니다.

4단계: 페이퍼 주문 제출

decision_output.ideal_buy/stop_loss/take_profit을 그대로 활용합니다.

curl -X POST http://localhost:8000/api/equity/orders \
-H "Authorization: Bearer $JWT" \
-H "Content-Type: application/json" \
-d '{
"asset_class": "us_equity",
"symbol": "TSLA",
"side": "buy",
"qty": 5,
"order_type": "limit",
"limit_price": 188.20,
"time_in_force": "day",
"bracket": {"take_profit": 205.00, "stop_loss": 179.00},
"report_uuid": "0c3a5b..."
}'

report_uuid를 함께 전달하면 감사 로그에 분석 보고서와 주문이 연결되어 추후 추적이 쉬워집니다.

5단계: 실시간 체결 구독

const ws = new WebSocket(`ws://localhost:8000/ws/equity/orders?token=${JWT}`);
ws.onmessage = (e) => {
const event = JSON.parse(e.data);
console.log(event.event_type, event.broker_order_id, event.filled_qty);
};

수신 시퀀스 예시: placedacceptedpartial_fillfilled.

검증

  • 분석 비용이 cost_usd 필드에 기록됨
  • 결정 신호가 buy/hold/sell 중 하나로 채워짐
  • 페이퍼 주문이 status=accepted로 응답
  • WebSocket으로 filled 이벤트 수신
  • Trades 탭에서 해당 체결 row 확인 (currency=USD)

다음 단계