fix(trading): 销毁和快照只在交易系统激活时执行

- BurnScheduler 检查 trading_configs.isActive 状态
- 交易系统未激活时跳过每分钟销毁和价格快照
- 交易系统未激活时跳过每小时状态日志

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-18 08:28:48 -08:00
parent 096d87e2a8
commit b7c8cdd249
1 changed files with 18 additions and 1 deletions

View File

@ -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}, ` +