From 7a8a3a8fd1bedf2af4435e5315030b45fcf76563 Mon Sep 17 00:00:00 2001 From: hailin Date: Thu, 29 Jan 2026 07:31:16 -0800 Subject: [PATCH] =?UTF-8?q?feat(trading-service):=20=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E5=81=9A=E5=B8=82=E5=95=86=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=92=B1=E5=8C=85=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 从 FUSDT_MARKET_MAKER_ADDRESS 环境变量读取做市商钱包地址 - 初始化时自动设置 kavaWalletAddress - 如果做市商已存在但钱包地址为空,也会从环境变量更新 Co-Authored-By: Claude Opus 4.5 --- .../services/market-maker.service.ts | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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; }