Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.hackathon.tomolow.domain.candle.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hackathon.tomolow.domain.candle.service.CandleIngestService;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/dev")
@Tag(name = "Candles", description = "[개발자] 캔들 데이터 저장용 API")
public class CandleDevController {

private final CandleIngestService candleIngestService;

@PostMapping("/candle/ingest")
public String ingestByMarketId(
@RequestParam Long marketId, @RequestParam(defaultValue = "200") int count) {

try {
int saved = candleIngestService.ingestSingleById(marketId, count);
return "OK - marketId=" + marketId + " 저장 개수: " + saved;
} catch (Exception e) {
log.error("❌ ingestByMarketId 실패: id={}, msg={}", marketId, e.getMessage());
return "ERROR: " + e.getMessage();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.hackathon.tomolow.domain.candle.entity.Candle;
import com.hackathon.tomolow.domain.candle.repository.CandleRepository;
import com.hackathon.tomolow.domain.market.entity.Market;
import com.hackathon.tomolow.domain.market.repository.MarketRepository;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -26,6 +27,7 @@ public class CandleIngestService {

private final UpbitRestClient upbit;
private final CandleRepository candleRepo;
private final MarketRepository marketRepo;

@Transactional
public int upsertDayCandles(Market market, int count) throws Exception {
Expand Down Expand Up @@ -67,4 +69,14 @@ public int upsertDayCandles(Market market, int count) throws Exception {
"Upsert 1D candles: {} saved={} (symbol={})", market.getName(), saved, market.getSymbol());
return saved;
}

@Transactional
public int ingestSingleById(Long marketId, int count) throws Exception {
Market m =
marketRepo
.findById(marketId)
.orElseThrow(() -> new IllegalArgumentException("해당 시장 없음: id=" + marketId));

return upsertDayCandles(m, count);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class CandleScheduler {
private final CandleIngestService ingest;

// 매일 00:05 KST에 최근 5개만 동기화(업서트)
@Scheduled(cron = "0 55 3 * * *", zone = "Asia/Seoul")
@Scheduled(cron = "0 5 0 * * *", zone = "Asia/Seoul")
public void syncDaily() throws Exception {
for (Market m : marketRepo.findAll()) {
if (m.getExchangeType() == ExchangeType.UPBIT) {
ingest.upsertDayCandles(m, 365 * 3);
ingest.upsertDayCandles(m, 5);
}
}
}
Expand Down