feat(trading-service): 初始化做市商时自动读取环境变量配置钱包地址
- 从 FUSDT_MARKET_MAKER_ADDRESS 环境变量读取做市商钱包地址 - 初始化时自动设置 kavaWalletAddress - 如果做市商已存在但钱包地址为空,也会从环境变量更新 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
812b127ace
commit
7a8a3a8fd1
|
|
@ -1,4 +1,5 @@
|
||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { PrismaService } from '../../infrastructure/persistence/prisma/prisma.service';
|
import { PrismaService } from '../../infrastructure/persistence/prisma/prisma.service';
|
||||||
import { RedisService } from '../../infrastructure/redis/redis.service';
|
import { RedisService } from '../../infrastructure/redis/redis.service';
|
||||||
import { OrderRepository } from '../../infrastructure/persistence/repositories/order.repository';
|
import { OrderRepository } from '../../infrastructure/persistence/repositories/order.repository';
|
||||||
|
|
@ -70,6 +71,7 @@ export class MarketMakerService {
|
||||||
private readonly accountRepository: TradingAccountRepository,
|
private readonly accountRepository: TradingAccountRepository,
|
||||||
private readonly orderService: OrderService,
|
private readonly orderService: OrderService,
|
||||||
private readonly priceService: PriceService,
|
private readonly priceService: PriceService,
|
||||||
|
private readonly configService: ConfigService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -150,6 +152,18 @@ export class MarketMakerService {
|
||||||
// 检查是否已存在
|
// 检查是否已存在
|
||||||
const existing = await this.getConfig(name);
|
const existing = await this.getConfig(name);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
|
// 如果存在但钱包地址为空,尝试从环境变量更新
|
||||||
|
if (!existing.kavaWalletAddress) {
|
||||||
|
const kavaWalletAddress = this.configService.get<string>('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<MarketMakerConfig>;
|
||||||
|
}
|
||||||
|
}
|
||||||
return existing;
|
return existing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -160,6 +174,9 @@ export class MarketMakerService {
|
||||||
await this.accountRepository.save(tradingAccount);
|
await this.accountRepository.save(tradingAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 从环境变量读取做市商钱包地址
|
||||||
|
const kavaWalletAddress = this.configService.get<string>('FUSDT_MARKET_MAKER_ADDRESS') || null;
|
||||||
|
|
||||||
// 创建做市商配置
|
// 创建做市商配置
|
||||||
const config = await this.prisma.marketMakerConfig.create({
|
const config = await this.prisma.marketMakerConfig.create({
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -169,10 +186,11 @@ export class MarketMakerService {
|
||||||
maxBuyRatio: params.maxBuyRatio || 0.05,
|
maxBuyRatio: params.maxBuyRatio || 0.05,
|
||||||
minIntervalMs: params.minIntervalMs || 1000,
|
minIntervalMs: params.minIntervalMs || 1000,
|
||||||
maxIntervalMs: params.maxIntervalMs || 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<MarketMakerConfig>;
|
return this.getConfig(name) as Promise<MarketMakerConfig>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue