Skip to content

Commit 1fea492

Browse files
authored
Merge pull request #69 from InserToken/feat/3-chart/yeakyung
[feat] 전날주가업데이트시간변경 -> 0시
2 parents 6eb0739 + 0516886 commit 1fea492

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

services/test.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
// //practicechartdata db에서 중복된 날짜 제거
2-
const mongoose = require("mongoose");
3-
const PracticeChartData = require("../models/PracticeChartData"); // 경로 수정
4-
require("dotenv").config();
5-
6-
async function removeDuplicatePrices() {
7-
await mongoose.connect(process.env.DB_URI);
8-
9-
const docs = await PracticeChartData.find({});
10-
11-
for (const doc of docs) {
12-
const seen = new Map(); // 날짜 -> 첫 price
13-
const uniquePrices = [];
14-
15-
for (const price of doc.prices) {
16-
if (!seen.has(price.date)) {
17-
seen.set(price.date, true);
18-
uniquePrices.push(price);
19-
}
20-
}
21-
22-
if (uniquePrices.length !== doc.prices.length) {
23-
console.log(
24-
`[중복 제거] ${doc.stock_code}: ${doc.prices.length}${uniquePrices.length}`
25-
);
26-
doc.prices = uniquePrices;
27-
await doc.save();
28-
}
29-
}
30-
31-
await mongoose.disconnect();
32-
console.log("✅ 중복 제거 완료");
33-
}
34-
35-
removeDuplicatePrices().catch((err) => {
36-
console.error("❌ 오류 발생:", err);
37-
});
38-
39-
// // 테스트용, 전 종목 직전일 주가정보 업데이트
402
// const mongoose = require("mongoose");
41-
// // const { fetchDailyPrice } = require("./fetchStockPrice");
3+
// const PracticeChartData = require("../models/PracticeChartData"); // 경로 수정
4+
// require("dotenv").config();
5+
6+
// async function removeDuplicatePrices() {
7+
// await mongoose.connect(process.env.DB_URI);
8+
9+
// const docs = await PracticeChartData.find({});
10+
11+
// for (const doc of docs) {
12+
// const seen = new Map(); // 날짜 -> 첫 price
13+
// const uniquePrices = [];
14+
15+
// for (const price of doc.prices) {
16+
// if (!seen.has(price.date)) {
17+
// seen.set(price.date, true);
18+
// uniquePrices.push(price);
19+
// }
20+
// }
21+
22+
// if (uniquePrices.length !== doc.prices.length) {
23+
// console.log(
24+
// `[중복 제거] ${doc.stock_code}: ${doc.prices.length} → ${uniquePrices.length}`
25+
// );
26+
// doc.prices = uniquePrices;
27+
// await doc.save();
28+
// }
29+
// }
30+
31+
// await mongoose.disconnect();
32+
// console.log("✅ 중복 제거 완료");
33+
// }
34+
35+
// removeDuplicatePrices().catch((err) => {
36+
// console.error("❌ 오류 발생:", err);
37+
// });
38+
39+
// 테스트용, 전 종목 직전일 주가정보 업데이트
40+
// const mongoose = require("mongoose");
41+
// require("dotenv").config();
4242

4343
// const { fetchAllStockPrice } = require("../tasks/dailyStockUpdater");
4444
// async function testInsert() {

tasks/dailyStockUpdater.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// 매일 6시 전날 주가 데이터 업데이트
1+
// 매일 자정 전날 주가 데이터 업데이트
22
const cron = require("node-cron");
33
const { fetchDailyPrice } = require("../services/fetchStockPrice");
44
const Stock = require("../models/Stocks");
@@ -23,7 +23,7 @@ async function fetchAllStockPrice() {
2323
}
2424

2525
cron.schedule(
26-
"0 6 * * *",
26+
"0 0 * * *",
2727
async () => {
2828
console.log("[스케줄 시작] 매일 6시 직전 영업일 주가 데이터 수집");
2929
await fetchAllStockPrice();

0 commit comments

Comments
 (0)