전일대비 부호 및 API 데이터 파싱 로직 개선:
Some checks failed
Build Push and Restart Compose / deploy (push) Failing after 1m13s

- `utils.ts`: 전일대비 부호 매핑 로직(1=상한가, 4=하한가) 수정 및 관련 함수(`sigToArrow`, `sigClass`) 업데이트.
- `types.ts`: `IndexQuote` 인터페이스의 `value` 필드명을 `price`로 수정.
- `kiwoom_ws_service.go`, `theme_service.go`, `kiwoom_service.go`: 전일대비 데이터 파싱 시 부호 결정 로직 추가(`signedChange`, `signedChangeBySig`) 및 관련 함수 호출로 대체.
- 기존 `predPre` 처리 부분을 양수/음수를 정확히 계산하도록 변경.
- `kospi200_service.go`: `PredPre` 필드 부호 처리 로직(`signedChangeBySig`) 추가.
- Svelte 페이지 업데이트:
  - `+page.svelte` 파일에서 `value` 필드를 `price`로 대체.
  - `theme` 및 `kospi200` 페이지에서 전일대비 표시값 절댓값으로 렌더링되도록 수정 (`Math.abs` 적용).
This commit is contained in:
hayato5246
2026-04-08 19:53:51 +09:00
parent ba18887ed8
commit 2f8a6ea349
9 changed files with 53 additions and 21 deletions

View File

@@ -219,12 +219,11 @@ func (k *KiwoomClient) fetchPrice(stkCd string) (*models.StockPrice, error) {
if result.ReturnCode != 0 {
return nil, fmt.Errorf("현재가 조회 실패: %s", result.ReturnMsg)
}
price := &models.StockPrice{
Code: displayCode,
Name: result.StkNm,
CurrentPrice: absParseIntSafe(result.CurPrc),
ChangePrice: parseIntSafe(result.PredPre),
ChangePrice: signedChange(result.PredPre, result.FluRt),
ChangeRate: parseFloatSafe(result.FluRt),
Volume: absParseIntSafe(result.TrdeQty),
High: absParseIntSafe(result.HighPric),
@@ -451,7 +450,7 @@ func (k *KiwoomClient) GetTopVolumeStocks(market string, count int) ([]models.St
Code: row.StkCd,
Name: row.StkNm,
CurrentPrice: absParseIntSafe(row.CurPrc),
ChangePrice: parseIntSafe(row.PredPre),
ChangePrice: signedChange(row.PredPre, row.FluRt),
ChangeRate: parseFloatSafe(row.FluRt),
Volume: absParseIntSafe(row.TrdeQty),
Market: mktName,
@@ -559,7 +558,7 @@ func (k *KiwoomClient) GetTopFluctuation(market string, ascending bool, count in
Code: row.StkCd,
Name: row.StkNm,
CurrentPrice: absParseIntSafe(row.CurPrc),
ChangePrice: parseIntSafe(row.PredPre),
ChangePrice: signedChange(row.PredPre, row.FluRt),
ChangeRate: parseFloatSafe(row.FluRt),
Volume: absParseIntSafe(row.NowTrdeQty),
CntrStr: parseFloatSafe(row.CntrStr),
@@ -588,6 +587,27 @@ func absParseIntSafe(s string) int64 {
return n
}
// signedChange 전일대비를 절댓값으로 파싱 후 등락률 부호에 맞춰 부호 결정
// 키움 API의 pred_pre 필드는 가격 필드처럼 부호가 방향 표시용이므로 flu_rt 기준으로 부호 결정
func signedChange(predPre string, fluRt string) int64 {
n := absParseIntSafe(predPre)
rate := parseFloatSafe(fluRt)
if rate < 0 {
return -n
}
return n
}
// signedChangeBySig 전일대비를 절댓값으로 파싱 후 flu_sig(등락기호) 기준으로 부호 결정
// flu_sig: 1=상한가, 2=상승, 3=보합, 4=하한가, 5=하락
func signedChangeBySig(predPre string, fluSig string) int64 {
n := absParseIntSafe(predPre)
if fluSig == "4" || fluSig == "5" {
return -n
}
return n
}
func parseFloatSafe(s string) float64 {
s = strings.ReplaceAll(s, ",", "")
s = strings.TrimPrefix(s, "+")