update refactor

This commit is contained in:
KienVT9 2025-07-08 18:03:36 +07:00
parent 01abc7e446
commit 55ad0607f3
39 changed files with 4304 additions and 584 deletions

View file

@ -0,0 +1,26 @@
import schedule from 'node-schedule';
import * as indicatorService from '../services/indicatorService';
import { BybitService } from '../services/bybitService';
import { KlineIntervalV3 } from 'bybit-api';
import { sendLarkMessage } from '../services/messageService';
// Hàm thực hiện phân tích nến
async function analyzeCandlesJob(symbol: string, interval: KlineIntervalV3) {
const bybitService = new BybitService(process.env.BYBIT_API_KEY!, process.env.BYBIT_API_SECRET!, false);
// TODO: Lấy client thật nếu cần
const candles = await bybitService.getCandles({ symbol, interval, category: 'linear', limit: 200 });
const analysis = indicatorService.analyze(candles);
console.log(`[${new Date().toISOString()}] Phân tích nến ${symbol} ${interval}:`, analysis);
await sendLarkMessage('oc_f9b2e8f0309ecab0c94e3e134b0ddd29', JSON.stringify(analysis));
// Có thể gửi kết quả qua Lark, lưu DB, ...
}
// Lập lịch chạy vào 00:00 mỗi ngày
const rule = new schedule.RecurrenceRule();
rule.minute = [4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59];
rule.second = 59;
schedule.scheduleJob(rule, () => {
// Có thể lặp qua nhiều symbol/interval nếu muốn
analyzeCandlesJob('BTCUSDT', '5');
});