fix(trading): 销毁和快照只在交易系统激活时执行
- BurnScheduler 检查 trading_configs.isActive 状态 - 交易系统未激活时跳过每分钟销毁和价格快照 - 交易系统未激活时跳过每小时状态日志 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
096d87e2a8
commit
b7c8cdd249
|
|
@ -3,6 +3,7 @@ import { Cron, CronExpression } from '@nestjs/schedule';
|
|||
import { BurnService } from '../services/burn.service';
|
||||
import { PriceService } from '../services/price.service';
|
||||
import { RedisService } from '../../infrastructure/redis/redis.service';
|
||||
import { TradingConfigRepository } from '../../infrastructure/persistence/repositories/trading-config.repository';
|
||||
|
||||
@Injectable()
|
||||
export class BurnScheduler implements OnModuleInit {
|
||||
|
|
@ -12,6 +13,7 @@ export class BurnScheduler implements OnModuleInit {
|
|||
private readonly burnService: BurnService,
|
||||
private readonly priceService: PriceService,
|
||||
private readonly redis: RedisService,
|
||||
private readonly tradingConfigRepository: TradingConfigRepository,
|
||||
) {}
|
||||
|
||||
async onModuleInit() {
|
||||
|
|
@ -32,10 +34,19 @@ export class BurnScheduler implements OnModuleInit {
|
|||
*
|
||||
* 注意:销毁和快照必须在同一个任务中顺序执行,
|
||||
* 确保快照总是捕获销毁后的最新价格,避免K线出现价格不变的情况
|
||||
*
|
||||
* 只有当交易系统激活时才执行销毁和快照
|
||||
*/
|
||||
@Cron(CronExpression.EVERY_MINUTE)
|
||||
async executeMinuteBurnAndSnapshot(): Promise<void> {
|
||||
try {
|
||||
// 检查交易系统是否激活
|
||||
const config = await this.tradingConfigRepository.getConfig();
|
||||
if (!config || !config.isActive) {
|
||||
// 交易系统未激活,跳过销毁和快照
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. 先执行销毁
|
||||
const burnAmount = await this.burnService.executeMinuteBurn();
|
||||
if (!burnAmount.isZero()) {
|
||||
|
|
@ -71,11 +82,17 @@ export class BurnScheduler implements OnModuleInit {
|
|||
}
|
||||
|
||||
/**
|
||||
* 每小时记录销毁状态日志
|
||||
* 每小时记录销毁状态日志(只在交易系统激活时记录)
|
||||
*/
|
||||
@Cron('0 * * * *') // 每小时整点
|
||||
async logBurnStatus(): Promise<void> {
|
||||
try {
|
||||
// 检查交易系统是否激活
|
||||
const config = await this.tradingConfigRepository.getConfig();
|
||||
if (!config || !config.isActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
const status = await this.burnService.getBurnStatus();
|
||||
this.logger.log(
|
||||
`Burn status: burned=${status.totalBurned}, ` +
|
||||
|
|
|
|||
Loading…
Reference in New Issue