diff --git a/backend/services/trading-service/src/application/services/market-maker.service.ts b/backend/services/trading-service/src/application/services/market-maker.service.ts index 359ce859..84521957 100644 --- a/backend/services/trading-service/src/application/services/market-maker.service.ts +++ b/backend/services/trading-service/src/application/services/market-maker.service.ts @@ -1,4 +1,5 @@ import { Injectable, Logger } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { PrismaService } from '../../infrastructure/persistence/prisma/prisma.service'; import { RedisService } from '../../infrastructure/redis/redis.service'; import { OrderRepository } from '../../infrastructure/persistence/repositories/order.repository'; @@ -70,6 +71,7 @@ export class MarketMakerService { private readonly accountRepository: TradingAccountRepository, private readonly orderService: OrderService, private readonly priceService: PriceService, + private readonly configService: ConfigService, ) {} /** @@ -150,6 +152,18 @@ export class MarketMakerService { // 检查是否已存在 const existing = await this.getConfig(name); if (existing) { + // 如果存在但钱包地址为空,尝试从环境变量更新 + if (!existing.kavaWalletAddress) { + const kavaWalletAddress = this.configService.get('FUSDT_MARKET_MAKER_ADDRESS'); + if (kavaWalletAddress) { + await this.prisma.marketMakerConfig.update({ + where: { name }, + data: { kavaWalletAddress }, + }); + this.logger.log(`Market maker ${name} wallet address updated from env: ${kavaWalletAddress}`); + return this.getConfig(name) as Promise; + } + } return existing; } @@ -160,6 +174,9 @@ export class MarketMakerService { await this.accountRepository.save(tradingAccount); } + // 从环境变量读取做市商钱包地址 + const kavaWalletAddress = this.configService.get('FUSDT_MARKET_MAKER_ADDRESS') || null; + // 创建做市商配置 const config = await this.prisma.marketMakerConfig.create({ data: { @@ -169,10 +186,11 @@ export class MarketMakerService { maxBuyRatio: params.maxBuyRatio || 0.05, minIntervalMs: params.minIntervalMs || 1000, maxIntervalMs: params.maxIntervalMs || 1000, + kavaWalletAddress, }, }); - this.logger.log(`Market maker initialized: ${name}, account: ${params.accountSequence}`); + this.logger.log(`Market maker initialized: ${name}, account: ${params.accountSequence}, wallet: ${kavaWalletAddress || 'not configured'}`); return this.getConfig(name) as Promise; }