fix(trading): getConfig 自动从环境变量填充空的钱包地址

之前只有 initializeConfig 会读取 env 填充钱包地址,
getConfig 只读数据库。导致新增 eusdtWalletAddress 字段后
即使 .env 配置了地址,前端仍显示"未配置"。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-03 04:09:00 -08:00
parent 2192f5e917
commit 4a69fdd070
1 changed files with 19 additions and 0 deletions

View File

@ -85,6 +85,25 @@ export class MarketMakerService {
});
if (!config) return null;
// 自动从环境变量填充空的钱包地址
const updateData: Record<string, string> = {};
if (!config.kavaWalletAddress) {
const addr = this.configService.get<string>('FUSDT_MARKET_MAKER_ADDRESS');
if (addr) updateData.kavaWalletAddress = addr;
}
if (!config.eusdtWalletAddress) {
const addr = this.configService.get<string>('EUSDT_MARKET_MAKER_ADDRESS');
if (addr) updateData.eusdtWalletAddress = addr;
}
if (Object.keys(updateData).length > 0) {
await this.prisma.marketMakerConfig.update({
where: { name },
data: updateData,
});
Object.assign(config, updateData);
this.logger.log(`Auto-filled wallet addresses from env for ${name}: ${JSON.stringify(updateData)}`);
}
// 从交易账户获取实际余额(保证一致性)
const tradingAccount = await this.accountRepository.findByAccountSequence(config.accountSequence);
const cashBalance = tradingAccount ? new Decimal(tradingAccount.cashBalance.value.toString()) : new Decimal(0);