Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7bc059ec34 | |||
| c20e0138df | |||
| 20acc72ed6 | |||
| a31ed31c98 | |||
| 0625c62e36 |
@@ -122,7 +122,7 @@ docker pull wrbug/polyhermes:v1.0.1
|
|||||||
请通过以下**唯一官方渠道**获取 PolyHermes:
|
请通过以下**唯一官方渠道**获取 PolyHermes:
|
||||||
|
|
||||||
* **GitHub 仓库**:https://github.com/WrBug/PolyHermes
|
* **GitHub 仓库**:https://github.com/WrBug/PolyHermes
|
||||||
* **Twitter**:@quant_tr
|
* **Twitter**:@polyhermes
|
||||||
* **Telegram 群组**:加入群组
|
* **Telegram 群组**:加入群组
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# PolyHermes
|
# PolyHermes
|
||||||
|
|
||||||
[](https://github.com/WrBug/PolyHermes)
|
[](https://github.com/WrBug/PolyHermes)
|
||||||
[](https://x.com/quant_tr)
|
[](https://x.com/polyhermes)
|
||||||
|
|
||||||
> 🌐 **Language**: [English](README_EN.md) | 中文
|
> 🌐 **Language**: [English](README_EN.md) | 中文
|
||||||
|
|
||||||
@@ -414,7 +414,7 @@ cd frontend
|
|||||||
## 🔗 相关链接
|
## 🔗 相关链接
|
||||||
|
|
||||||
- [GitHub 仓库](https://github.com/WrBug/PolyHermes)
|
- [GitHub 仓库](https://github.com/WrBug/PolyHermes)
|
||||||
- [Twitter](https://x.com/quant_tr)
|
- [Twitter](https://x.com/polyhermes)
|
||||||
- [Polymarket 官网](https://polymarket.com)
|
- [Polymarket 官网](https://polymarket.com)
|
||||||
- [Polymarket API 文档](https://docs.polymarket.com)
|
- [Polymarket API 文档](https://docs.polymarket.com)
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
# PolyHermes
|
# PolyHermes
|
||||||
|
|
||||||
[](https://github.com/WrBug/PolyHermes)
|
[](https://github.com/WrBug/PolyHermes)
|
||||||
[](https://x.com/quant_tr)
|
[](https://x.com/polyhermes)
|
||||||
|
|
||||||
> 🌐 **Language**: English | [中文](README.md)
|
> 🌐 **Language**: English | [中文](README.md)
|
||||||
|
|
||||||
@@ -414,7 +414,7 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file
|
|||||||
## 🔗 Related Links
|
## 🔗 Related Links
|
||||||
|
|
||||||
- [GitHub Repository](https://github.com/WrBug/PolyHermes)
|
- [GitHub Repository](https://github.com/WrBug/PolyHermes)
|
||||||
- [Twitter](https://x.com/quant_tr)
|
- [Twitter](https://x.com/polyhermes)
|
||||||
- [Polymarket Official Website](https://polymarket.com)
|
- [Polymarket Official Website](https://polymarket.com)
|
||||||
- [Polymarket API Documentation](https://docs.polymarket.com)
|
- [Polymarket API Documentation](https://docs.polymarket.com)
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ data class SystemConfigDto(
|
|||||||
val builderApiKeyConfigured: Boolean, // Builder API Key 是否已配置
|
val builderApiKeyConfigured: Boolean, // Builder API Key 是否已配置
|
||||||
val builderSecretConfigured: Boolean, // Builder Secret 是否已配置
|
val builderSecretConfigured: Boolean, // Builder Secret 是否已配置
|
||||||
val builderPassphraseConfigured: Boolean, // Builder Passphrase 是否已配置
|
val builderPassphraseConfigured: Boolean, // Builder Passphrase 是否已配置
|
||||||
|
val builderApiKeyDisplay: String? = null, // Builder API Key 显示值(部分显示,用于前端展示)
|
||||||
|
val builderSecretDisplay: String? = null, // Builder Secret 显示值(部分显示,用于前端展示)
|
||||||
|
val builderPassphraseDisplay: String? = null, // Builder Passphrase 显示值(部分显示,用于前端展示)
|
||||||
val autoRedeemEnabled: Boolean = true // 自动赎回(系统级别配置,默认开启)
|
val autoRedeemEnabled: Boolean = true // 自动赎回(系统级别配置,默认开启)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ data class CopyTradingCreateRequest(
|
|||||||
val maxSpread: String? = null, // 最大价差(绝对价格),NULL表示不启用
|
val maxSpread: String? = null, // 最大价差(绝对价格),NULL表示不启用
|
||||||
val minPrice: String? = null, // 最低价格(可选),NULL表示不限制最低价
|
val minPrice: String? = null, // 最低价格(可选),NULL表示不限制最低价
|
||||||
val maxPrice: String? = null, // 最高价格(可选),NULL表示不限制最高价
|
val maxPrice: String? = null, // 最高价格(可选),NULL表示不限制最高价
|
||||||
|
// 最大仓位配置
|
||||||
|
val maxPositionValue: String? = null, // 最大仓位金额(USDC),NULL表示不启用
|
||||||
|
val maxPositionCount: Int? = null, // 最大仓位数量,NULL表示不启用
|
||||||
// 新增配置字段
|
// 新增配置字段
|
||||||
val configName: String? = null, // 配置名(可选)
|
val configName: String? = null, // 配置名(可选)
|
||||||
val pushFailedOrders: Boolean? = null // 推送失败订单(可选)
|
val pushFailedOrders: Boolean? = null // 推送失败订单(可选)
|
||||||
@@ -65,6 +68,9 @@ data class CopyTradingUpdateRequest(
|
|||||||
val maxSpread: String? = null,
|
val maxSpread: String? = null,
|
||||||
val minPrice: String? = null, // 最低价格(可选),NULL表示不限制最低价
|
val minPrice: String? = null, // 最低价格(可选),NULL表示不限制最低价
|
||||||
val maxPrice: String? = null, // 最高价格(可选),NULL表示不限制最高价
|
val maxPrice: String? = null, // 最高价格(可选),NULL表示不限制最高价
|
||||||
|
// 最大仓位配置
|
||||||
|
val maxPositionValue: String? = null, // 最大仓位金额(USDC),NULL表示不启用
|
||||||
|
val maxPositionCount: Int? = null, // 最大仓位数量,NULL表示不启用
|
||||||
// 新增配置字段
|
// 新增配置字段
|
||||||
val configName: String? = null, // 配置名(可选,但提供时必须非空)
|
val configName: String? = null, // 配置名(可选,但提供时必须非空)
|
||||||
val pushFailedOrders: Boolean? = null // 推送失败订单(可选)
|
val pushFailedOrders: Boolean? = null // 推送失败订单(可选)
|
||||||
@@ -133,6 +139,9 @@ data class CopyTradingDto(
|
|||||||
val maxSpread: String?,
|
val maxSpread: String?,
|
||||||
val minPrice: String?, // 最低价格(可选),NULL表示不限制最低价
|
val minPrice: String?, // 最低价格(可选),NULL表示不限制最低价
|
||||||
val maxPrice: String?, // 最高价格(可选),NULL表示不限制最高价
|
val maxPrice: String?, // 最高价格(可选),NULL表示不限制最高价
|
||||||
|
// 最大仓位配置
|
||||||
|
val maxPositionValue: String? = null, // 最大仓位金额(USDC),NULL表示不启用
|
||||||
|
val maxPositionCount: Int? = null, // 最大仓位数量,NULL表示不启用
|
||||||
// 新增配置字段
|
// 新增配置字段
|
||||||
val configName: String? = null, // 配置名(可选)
|
val configName: String? = null, // 配置名(可选)
|
||||||
val pushFailedOrders: Boolean = false, // 推送失败订单(默认关闭)
|
val pushFailedOrders: Boolean = false, // 推送失败订单(默认关闭)
|
||||||
|
|||||||
@@ -84,6 +84,13 @@ data class CopyTrading(
|
|||||||
@Column(name = "max_price", precision = 20, scale = 8)
|
@Column(name = "max_price", precision = 20, scale = 8)
|
||||||
val maxPrice: BigDecimal? = null, // 最高价格(可选),NULL表示不限制最高价
|
val maxPrice: BigDecimal? = null, // 最高价格(可选),NULL表示不限制最高价
|
||||||
|
|
||||||
|
// 最大仓位配置
|
||||||
|
@Column(name = "max_position_value", precision = 20, scale = 8)
|
||||||
|
val maxPositionValue: BigDecimal? = null, // 最大仓位金额(USDC),NULL表示不启用
|
||||||
|
|
||||||
|
@Column(name = "max_position_count")
|
||||||
|
val maxPositionCount: Int? = null, // 最大仓位数量,NULL表示不启用
|
||||||
|
|
||||||
// 新增配置字段
|
// 新增配置字段
|
||||||
@Column(name = "config_name", length = 255)
|
@Column(name = "config_name", length = 255)
|
||||||
val configName: String? = null, // 配置名(可选)
|
val configName: String? = null, // 配置名(可选)
|
||||||
|
|||||||
+89
-2
@@ -8,6 +8,7 @@ import com.wrbug.polymarketbot.util.multi
|
|||||||
import com.wrbug.polymarketbot.util.toSafeBigDecimal
|
import com.wrbug.polymarketbot.util.toSafeBigDecimal
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import com.wrbug.polymarketbot.service.common.PolymarketClobService
|
import com.wrbug.polymarketbot.service.common.PolymarketClobService
|
||||||
|
import com.wrbug.polymarketbot.service.accounts.AccountService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
|
|
||||||
@@ -16,7 +17,8 @@ import java.math.BigDecimal
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
class CopyTradingFilterService(
|
class CopyTradingFilterService(
|
||||||
private val clobService: PolymarketClobService
|
private val clobService: PolymarketClobService,
|
||||||
|
private val accountService: AccountService
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(CopyTradingFilterService::class.java)
|
private val logger = LoggerFactory.getLogger(CopyTradingFilterService::class.java)
|
||||||
@@ -26,12 +28,16 @@ class CopyTradingFilterService(
|
|||||||
* @param copyTrading 跟单配置
|
* @param copyTrading 跟单配置
|
||||||
* @param tokenId token ID(用于获取订单簿)
|
* @param tokenId token ID(用于获取订单簿)
|
||||||
* @param tradePrice Leader 交易价格,用于价格区间检查
|
* @param tradePrice Leader 交易价格,用于价格区间检查
|
||||||
|
* @param copyOrderAmount 跟单金额(USDC),用于仓位检查,如果为null则不进行仓位检查
|
||||||
|
* @param marketId 市场ID,用于仓位检查(按市场过滤仓位)
|
||||||
* @return 过滤结果
|
* @return 过滤结果
|
||||||
*/
|
*/
|
||||||
suspend fun checkFilters(
|
suspend fun checkFilters(
|
||||||
copyTrading: CopyTrading,
|
copyTrading: CopyTrading,
|
||||||
tokenId: String,
|
tokenId: String,
|
||||||
tradePrice: BigDecimal? = null // Leader 交易价格,用于价格区间检查
|
tradePrice: BigDecimal? = null, // Leader 交易价格,用于价格区间检查
|
||||||
|
copyOrderAmount: BigDecimal? = null, // 跟单金额(USDC),用于仓位检查
|
||||||
|
marketId: String? = null // 市场ID,用于仓位检查(按市场过滤仓位)
|
||||||
): FilterResult {
|
): FilterResult {
|
||||||
// 1. 价格区间检查(如果配置了价格区间)
|
// 1. 价格区间检查(如果配置了价格区间)
|
||||||
if (tradePrice != null) {
|
if (tradePrice != null) {
|
||||||
@@ -76,6 +82,14 @@ class CopyTradingFilterService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 6. 仓位检查(如果配置了最大仓位限制且提供了跟单金额和市场ID)
|
||||||
|
if (copyOrderAmount != null && marketId != null) {
|
||||||
|
val positionCheck = checkPositionLimits(copyTrading, copyOrderAmount, marketId)
|
||||||
|
if (!positionCheck.isPassed) {
|
||||||
|
return positionCheck
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return FilterResult.passed(orderbook)
|
return FilterResult.passed(orderbook)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,5 +198,78 @@ class CopyTradingFilterService(
|
|||||||
|
|
||||||
return FilterResult.passed()
|
return FilterResult.passed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查仓位限制(按市场检查)
|
||||||
|
* @param copyTrading 跟单配置
|
||||||
|
* @param copyOrderAmount 跟单金额(USDC)
|
||||||
|
* @param marketId 市场ID,用于过滤该市场的仓位
|
||||||
|
* @return 过滤结果
|
||||||
|
*/
|
||||||
|
private suspend fun checkPositionLimits(
|
||||||
|
copyTrading: CopyTrading,
|
||||||
|
copyOrderAmount: BigDecimal,
|
||||||
|
marketId: String
|
||||||
|
): FilterResult {
|
||||||
|
// 如果未配置仓位限制,直接通过
|
||||||
|
if (copyTrading.maxPositionValue == null && copyTrading.maxPositionCount == null) {
|
||||||
|
return FilterResult.passed()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取账户的所有仓位信息
|
||||||
|
val positionsResult = accountService.getAllPositions()
|
||||||
|
if (positionsResult.isFailure) {
|
||||||
|
logger.warn("获取仓位信息失败,跳过仓位检查: accountId=${copyTrading.accountId}, marketId=$marketId, error=${positionsResult.exceptionOrNull()?.message}")
|
||||||
|
// 如果获取仓位失败,为了安全起见,不通过检查
|
||||||
|
return FilterResult.maxPositionValueFailed("获取仓位信息失败,无法进行仓位检查")
|
||||||
|
}
|
||||||
|
|
||||||
|
val positions = positionsResult.getOrNull() ?: return FilterResult.maxPositionValueFailed("仓位信息为空")
|
||||||
|
|
||||||
|
// 过滤出当前账户且该市场的仓位
|
||||||
|
val marketPositions = positions.currentPositions.filter {
|
||||||
|
it.accountId == copyTrading.accountId && it.marketId == marketId
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查最大仓位金额(如果配置了)
|
||||||
|
if (copyTrading.maxPositionValue != null) {
|
||||||
|
// 计算该市场的当前仓位总价值(累加该市场所有仓位的 currentValue)
|
||||||
|
val currentPositionValue = marketPositions.sumOf { position ->
|
||||||
|
position.currentValue.toSafeBigDecimal()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查:该市场的当前仓位 + 跟单金额 <= 最大仓位金额
|
||||||
|
val totalValueAfterOrder = currentPositionValue.add(copyOrderAmount)
|
||||||
|
|
||||||
|
if (totalValueAfterOrder.gt(copyTrading.maxPositionValue)) {
|
||||||
|
return FilterResult.maxPositionValueFailed(
|
||||||
|
"超过最大仓位金额限制: 当前该市场仓位=${currentPositionValue} USDC, 跟单金额=${copyOrderAmount} USDC, 总计=${totalValueAfterOrder} USDC > 最大限制=${copyTrading.maxPositionValue} USDC"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查最大仓位数量(如果配置了)
|
||||||
|
if (copyTrading.maxPositionCount != null) {
|
||||||
|
// 计算该市场的当前仓位数量(该市场不同方向的仓位算不同仓位)
|
||||||
|
val currentPositionCount = marketPositions.size
|
||||||
|
|
||||||
|
// 检查:该市场的当前仓位数量 <= 最大仓位数量
|
||||||
|
// 注意:如果该市场已有仓位,跟单可能会增加新的仓位(不同方向)或增加现有仓位
|
||||||
|
// 为了简化,我们检查当前该市场的仓位数量是否已经达到或超过限制
|
||||||
|
if (currentPositionCount >= copyTrading.maxPositionCount) {
|
||||||
|
return FilterResult.maxPositionCountFailed(
|
||||||
|
"超过最大仓位数量限制: 当前该市场仓位数量=${currentPositionCount} >= 最大限制=${copyTrading.maxPositionCount}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FilterResult.passed()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logger.error("仓位检查异常: accountId=${copyTrading.accountId}, marketId=$marketId, error=${e.message}", e)
|
||||||
|
// 如果检查异常,为了安全起见,不通过检查
|
||||||
|
return FilterResult.maxPositionValueFailed("仓位检查异常: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-3
@@ -86,7 +86,9 @@ class CopyTradingService(
|
|||||||
minOrderDepth = request.minOrderDepth?.toSafeBigDecimal() ?: template.minOrderDepth,
|
minOrderDepth = request.minOrderDepth?.toSafeBigDecimal() ?: template.minOrderDepth,
|
||||||
maxSpread = request.maxSpread?.toSafeBigDecimal() ?: template.maxSpread,
|
maxSpread = request.maxSpread?.toSafeBigDecimal() ?: template.maxSpread,
|
||||||
minPrice = request.minPrice?.toSafeBigDecimal() ?: template.minPrice,
|
minPrice = request.minPrice?.toSafeBigDecimal() ?: template.minPrice,
|
||||||
maxPrice = request.maxPrice?.toSafeBigDecimal() ?: template.maxPrice
|
maxPrice = request.maxPrice?.toSafeBigDecimal() ?: template.maxPrice,
|
||||||
|
maxPositionValue = request.maxPositionValue?.toSafeBigDecimal(),
|
||||||
|
maxPositionCount = request.maxPositionCount
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// 手动输入(所有字段必须提供)
|
// 手动输入(所有字段必须提供)
|
||||||
@@ -112,7 +114,9 @@ class CopyTradingService(
|
|||||||
minOrderDepth = request.minOrderDepth?.toSafeBigDecimal(),
|
minOrderDepth = request.minOrderDepth?.toSafeBigDecimal(),
|
||||||
maxSpread = request.maxSpread?.toSafeBigDecimal(),
|
maxSpread = request.maxSpread?.toSafeBigDecimal(),
|
||||||
minPrice = request.minPrice?.toSafeBigDecimal(),
|
minPrice = request.minPrice?.toSafeBigDecimal(),
|
||||||
maxPrice = request.maxPrice?.toSafeBigDecimal()
|
maxPrice = request.maxPrice?.toSafeBigDecimal(),
|
||||||
|
maxPositionValue = request.maxPositionValue?.toSafeBigDecimal(),
|
||||||
|
maxPositionCount = request.maxPositionCount
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +143,8 @@ class CopyTradingService(
|
|||||||
maxSpread = config.maxSpread,
|
maxSpread = config.maxSpread,
|
||||||
minPrice = config.minPrice,
|
minPrice = config.minPrice,
|
||||||
maxPrice = config.maxPrice,
|
maxPrice = config.maxPrice,
|
||||||
|
maxPositionValue = config.maxPositionValue,
|
||||||
|
maxPositionCount = config.maxPositionCount,
|
||||||
configName = configName,
|
configName = configName,
|
||||||
pushFailedOrders = request.pushFailedOrders ?: false
|
pushFailedOrders = request.pushFailedOrders ?: false
|
||||||
)
|
)
|
||||||
@@ -204,6 +210,8 @@ class CopyTradingService(
|
|||||||
maxSpread = request.maxSpread?.toSafeBigDecimal() ?: copyTrading.maxSpread,
|
maxSpread = request.maxSpread?.toSafeBigDecimal() ?: copyTrading.maxSpread,
|
||||||
minPrice = request.minPrice?.toSafeBigDecimal() ?: copyTrading.minPrice,
|
minPrice = request.minPrice?.toSafeBigDecimal() ?: copyTrading.minPrice,
|
||||||
maxPrice = request.maxPrice?.toSafeBigDecimal() ?: copyTrading.maxPrice,
|
maxPrice = request.maxPrice?.toSafeBigDecimal() ?: copyTrading.maxPrice,
|
||||||
|
maxPositionValue = request.maxPositionValue?.toSafeBigDecimal() ?: copyTrading.maxPositionValue,
|
||||||
|
maxPositionCount = request.maxPositionCount ?: copyTrading.maxPositionCount,
|
||||||
configName = configName,
|
configName = configName,
|
||||||
pushFailedOrders = request.pushFailedOrders ?: copyTrading.pushFailedOrders,
|
pushFailedOrders = request.pushFailedOrders ?: copyTrading.pushFailedOrders,
|
||||||
updatedAt = System.currentTimeMillis()
|
updatedAt = System.currentTimeMillis()
|
||||||
@@ -409,6 +417,8 @@ class CopyTradingService(
|
|||||||
maxSpread = copyTrading.maxSpread?.toPlainString(),
|
maxSpread = copyTrading.maxSpread?.toPlainString(),
|
||||||
minPrice = copyTrading.minPrice?.toPlainString(),
|
minPrice = copyTrading.minPrice?.toPlainString(),
|
||||||
maxPrice = copyTrading.maxPrice?.toPlainString(),
|
maxPrice = copyTrading.maxPrice?.toPlainString(),
|
||||||
|
maxPositionValue = copyTrading.maxPositionValue?.toPlainString(),
|
||||||
|
maxPositionCount = copyTrading.maxPositionCount,
|
||||||
configName = copyTrading.configName,
|
configName = copyTrading.configName,
|
||||||
pushFailedOrders = copyTrading.pushFailedOrders,
|
pushFailedOrders = copyTrading.pushFailedOrders,
|
||||||
createdAt = copyTrading.createdAt,
|
createdAt = copyTrading.createdAt,
|
||||||
@@ -437,6 +447,8 @@ class CopyTradingService(
|
|||||||
val minOrderDepth: BigDecimal?,
|
val minOrderDepth: BigDecimal?,
|
||||||
val maxSpread: BigDecimal?,
|
val maxSpread: BigDecimal?,
|
||||||
val minPrice: BigDecimal?,
|
val minPrice: BigDecimal?,
|
||||||
val maxPrice: BigDecimal?
|
val maxPrice: BigDecimal?,
|
||||||
|
val maxPositionValue: BigDecimal?,
|
||||||
|
val maxPositionCount: Int?
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-1
@@ -17,7 +17,11 @@ enum class FilterStatus {
|
|||||||
/** 失败:价差过大 */
|
/** 失败:价差过大 */
|
||||||
FAILED_SPREAD,
|
FAILED_SPREAD,
|
||||||
/** 失败:订单深度不足 */
|
/** 失败:订单深度不足 */
|
||||||
FAILED_ORDER_DEPTH
|
FAILED_ORDER_DEPTH,
|
||||||
|
/** 失败:超过最大仓位金额 */
|
||||||
|
FAILED_MAX_POSITION_VALUE,
|
||||||
|
/** 失败:超过最大仓位数量 */
|
||||||
|
FAILED_MAX_POSITION_COUNT
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,6 +77,18 @@ data class FilterResult(
|
|||||||
reason = reason,
|
reason = reason,
|
||||||
orderbook = orderbook
|
orderbook = orderbook
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/** 超过最大仓位金额 */
|
||||||
|
fun maxPositionValueFailed(reason: String) = FilterResult(
|
||||||
|
status = FilterStatus.FAILED_MAX_POSITION_VALUE,
|
||||||
|
reason = reason
|
||||||
|
)
|
||||||
|
|
||||||
|
/** 超过最大仓位数量 */
|
||||||
|
fun maxPositionCountFailed(reason: String) = FilterResult(
|
||||||
|
status = FilterStatus.FAILED_MAX_POSITION_COUNT,
|
||||||
|
reason = reason
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+260
-113
@@ -10,6 +10,8 @@ import com.wrbug.polymarketbot.util.*
|
|||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.dao.DataIntegrityViolationException
|
import org.springframework.dao.DataIntegrityViolationException
|
||||||
|
import org.springframework.dao.DuplicateKeyException
|
||||||
|
import java.sql.SQLException
|
||||||
import com.wrbug.polymarketbot.service.copytrading.configs.CopyTradingFilterService
|
import com.wrbug.polymarketbot.service.copytrading.configs.CopyTradingFilterService
|
||||||
import com.wrbug.polymarketbot.service.copytrading.configs.FilterStatus
|
import com.wrbug.polymarketbot.service.copytrading.configs.FilterStatus
|
||||||
import com.wrbug.polymarketbot.service.copytrading.orders.OrderSigningService
|
import com.wrbug.polymarketbot.service.copytrading.orders.OrderSigningService
|
||||||
@@ -27,7 +29,7 @@ import java.math.BigDecimal
|
|||||||
* 实际创建订单并记录跟踪信息
|
* 实际创建订单并记录跟踪信息
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
class CopyOrderTrackingService(
|
open class CopyOrderTrackingService(
|
||||||
private val copyOrderTrackingRepository: CopyOrderTrackingRepository,
|
private val copyOrderTrackingRepository: CopyOrderTrackingRepository,
|
||||||
private val sellMatchRecordRepository: SellMatchRecordRepository,
|
private val sellMatchRecordRepository: SellMatchRecordRepository,
|
||||||
private val sellMatchDetailRepository: SellMatchDetailRepository,
|
private val sellMatchDetailRepository: SellMatchDetailRepository,
|
||||||
@@ -50,6 +52,12 @@ class CopyOrderTrackingService(
|
|||||||
|
|
||||||
// 协程作用域(用于异步发送通知)
|
// 协程作用域(用于异步发送通知)
|
||||||
private val notificationScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
private val notificationScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||||
|
|
||||||
|
// 订单创建重试配置
|
||||||
|
companion object {
|
||||||
|
private const val MAX_RETRY_ATTEMPTS = 2 // 最多重试次数(首次 + 1次重试)
|
||||||
|
private const val RETRY_DELAY_MS = 3000L // 重试前等待时间(毫秒,3秒)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解密账户私钥
|
* 解密账户私钥
|
||||||
@@ -144,21 +152,38 @@ class CopyOrderTrackingService(
|
|||||||
processedAt = System.currentTimeMillis()
|
processedAt = System.currentTimeMillis()
|
||||||
)
|
)
|
||||||
processedTradeRepository.save(processed)
|
processedTradeRepository.save(processed)
|
||||||
} catch (e: DataIntegrityViolationException) {
|
} catch (e: Exception) {
|
||||||
// 唯一约束冲突,说明已经处理过了(可能是并发请求)
|
// 检查是否是唯一键冲突异常(可能是 DataIntegrityViolationException、DuplicateKeyException 或 SQLException)
|
||||||
// 再次检查确认状态
|
if (isUniqueConstraintViolation(e)) {
|
||||||
val existing = processedTradeRepository.findByLeaderIdAndLeaderTradeId(leaderId, trade.id)
|
// 唯一约束冲突,说明已经处理过了(可能是并发请求)
|
||||||
if (existing != null) {
|
// 再次检查确认状态
|
||||||
if (existing.status == "FAILED") {
|
val existing = processedTradeRepository.findByLeaderIdAndLeaderTradeId(leaderId, trade.id)
|
||||||
|
if (existing != null) {
|
||||||
|
if (existing.status == "FAILED") {
|
||||||
|
logger.debug("交易已标记为失败,跳过处理: leaderId=$leaderId, tradeId=${trade.id}")
|
||||||
|
return Result.success(Unit)
|
||||||
|
}
|
||||||
|
logger.debug("交易已处理(并发检测): leaderId=$leaderId, tradeId=${trade.id}, status=${existing.status}")
|
||||||
|
return Result.success(Unit)
|
||||||
|
} else {
|
||||||
|
// 如果检查不到,可能是事务隔离级别问题,等待一下再查询
|
||||||
|
delay(100)
|
||||||
|
val existingAfterDelay =
|
||||||
|
processedTradeRepository.findByLeaderIdAndLeaderTradeId(leaderId, trade.id)
|
||||||
|
if (existingAfterDelay != null) {
|
||||||
|
logger.debug("延迟查询到记录(并发检测): leaderId=$leaderId, tradeId=${trade.id}, status=${existingAfterDelay.status}")
|
||||||
|
return Result.success(Unit)
|
||||||
|
}
|
||||||
|
// 如果还是查询不到,记录警告但不抛出异常(可能是其他约束冲突)
|
||||||
|
logger.warn(
|
||||||
|
"保存ProcessedTrade时发生唯一约束冲突,但查询不到记录: leaderId=$leaderId, tradeId=${trade.id}",
|
||||||
|
e
|
||||||
|
)
|
||||||
|
// 不抛出异常,避免影响其他交易的处理
|
||||||
return Result.success(Unit)
|
return Result.success(Unit)
|
||||||
}
|
}
|
||||||
return Result.success(Unit)
|
|
||||||
} else {
|
} else {
|
||||||
// 如果检查不到,说明可能是其他约束冲突,重新抛出异常
|
// 其他类型的异常,重新抛出
|
||||||
logger.warn(
|
|
||||||
"保存ProcessedTrade时发生唯一约束冲突,但查询不到记录: leaderId=$leaderId, tradeId=${trade.id}",
|
|
||||||
e
|
|
||||||
)
|
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,11 +241,30 @@ class CopyOrderTrackingService(
|
|||||||
}
|
}
|
||||||
val tokenId = tokenIdResult.getOrNull() ?: continue
|
val tokenId = tokenIdResult.getOrNull() ?: continue
|
||||||
|
|
||||||
|
// 先计算跟单金额(用于仓位检查)
|
||||||
|
// 注意:这里先计算金额,即使后续被过滤也会记录
|
||||||
|
val tradePrice = trade.price.toSafeBigDecimal()
|
||||||
|
val buyQuantity = try {
|
||||||
|
calculateBuyQuantity(trade, copyTrading)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logger.warn("计算买入数量失败: ${e.message}", e)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算跟单金额(USDC)= 买入数量 × 价格
|
||||||
|
val copyOrderAmount = buyQuantity.multi(tradePrice)
|
||||||
|
|
||||||
// 过滤条件检查(在计算订单参数之前)
|
// 过滤条件检查(在计算订单参数之前)
|
||||||
// 传入 Leader 交易价格,用于价格区间检查
|
// 传入 Leader 交易价格,用于价格区间检查
|
||||||
|
// 传入跟单金额和市场ID,用于仓位检查(按市场检查仓位)
|
||||||
// 订单簿只请求一次,返回给后续逻辑使用
|
// 订单簿只请求一次,返回给后续逻辑使用
|
||||||
val tradePrice = trade.price.toSafeBigDecimal()
|
val filterResult = filterService.checkFilters(
|
||||||
val filterResult = filterService.checkFilters(copyTrading, tokenId, tradePrice = tradePrice)
|
copyTrading,
|
||||||
|
tokenId,
|
||||||
|
tradePrice = tradePrice,
|
||||||
|
copyOrderAmount = copyOrderAmount,
|
||||||
|
marketId = trade.market
|
||||||
|
)
|
||||||
val orderbook = filterResult.orderbook // 获取订单簿(如果需要)
|
val orderbook = filterResult.orderbook // 获取订单簿(如果需要)
|
||||||
if (!filterResult.isPassed) {
|
if (!filterResult.isPassed) {
|
||||||
logger.warn("过滤条件检查失败,跳过创建订单: copyTradingId=${copyTrading.id}, reason=${filterResult.reason}")
|
logger.warn("过滤条件检查失败,跳过创建订单: copyTradingId=${copyTrading.id}, reason=${filterResult.reason}")
|
||||||
@@ -313,9 +357,8 @@ class CopyOrderTrackingService(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算买入数量
|
// 买入数量已在过滤检查前计算,这里直接使用
|
||||||
val buyQuantity = calculateBuyQuantity(trade, copyTrading)
|
// 如果数量为0或负数,跳过
|
||||||
|
|
||||||
if (buyQuantity.lte(BigDecimal.ZERO)) {
|
if (buyQuantity.lte(BigDecimal.ZERO)) {
|
||||||
logger.warn("计算出的买入数量为0或负数,跳过: copyTradingId=${copyTrading.id}, tradeId=${trade.id}")
|
logger.warn("计算出的买入数量为0或负数,跳过: copyTradingId=${copyTrading.id}, tradeId=${trade.id}")
|
||||||
continue
|
continue
|
||||||
@@ -358,6 +401,35 @@ class CopyOrderTrackingService(
|
|||||||
// 计算价格(应用价格容忍度)
|
// 计算价格(应用价格容忍度)
|
||||||
val buyPrice = calculateAdjustedPrice(trade.price.toSafeBigDecimal(), copyTrading, isBuy = true)
|
val buyPrice = calculateAdjustedPrice(trade.price.toSafeBigDecimal(), copyTrading, isBuy = true)
|
||||||
|
|
||||||
|
// 在创建订单前,检查订单簿中是否有可匹配的订单(避免 FAK 订单失败)
|
||||||
|
// 如果过滤检查时已经获取了订单簿,直接使用;否则重新获取
|
||||||
|
val orderbookForCheck = orderbook ?: run {
|
||||||
|
val orderbookResult = clobService.getOrderbookByTokenId(tokenId)
|
||||||
|
if (orderbookResult.isSuccess) {
|
||||||
|
orderbookResult.getOrNull()
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否有可匹配的卖单(asks)
|
||||||
|
if (orderbookForCheck != null) {
|
||||||
|
val bestAsk = orderbookForCheck.asks
|
||||||
|
.mapNotNull { it.price.toSafeBigDecimal() }
|
||||||
|
.minOrNull()
|
||||||
|
|
||||||
|
if (bestAsk == null) {
|
||||||
|
logger.warn("订单簿中没有卖单,跳过创建订单: copyTradingId=${copyTrading.id}, tradeId=${trade.id}")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果调整后的买入价格低于最佳卖单价格,无法匹配
|
||||||
|
if (buyPrice.lt(bestAsk)) {
|
||||||
|
logger.warn("调整后的买入价格 ($buyPrice) 低于最佳卖单价格 ($bestAsk),无法匹配,跳过创建订单: copyTradingId=${copyTrading.id}, tradeId=${trade.id}, leaderPrice=${trade.price}, tolerance=${copyTrading.priceTolerance}")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 解密 API 凭证
|
// 解密 API 凭证
|
||||||
val apiSecret = try {
|
val apiSecret = try {
|
||||||
decryptApiSecret(account)
|
decryptApiSecret(account)
|
||||||
@@ -383,7 +455,9 @@ class CopyOrderTrackingService(
|
|||||||
// 解密私钥
|
// 解密私钥
|
||||||
val decryptedPrivateKey = decryptPrivateKey(account)
|
val decryptedPrivateKey = decryptPrivateKey(account)
|
||||||
|
|
||||||
// 调用API创建订单(带重试机制,重试时会重新生成salt并重新签名)
|
// 调用API创建订单(带重试机制)
|
||||||
|
// 重试策略:最多重试 MAX_RETRY_ATTEMPTS 次,每次重试前等待 RETRY_DELAY_MS 毫秒
|
||||||
|
// 每次重试都会重新生成salt并重新签名,确保签名唯一性
|
||||||
val createOrderResult = createOrderWithRetry(
|
val createOrderResult = createOrderWithRetry(
|
||||||
clobApi = clobApi,
|
clobApi = clobApi,
|
||||||
privateKey = decryptedPrivateKey,
|
privateKey = decryptedPrivateKey,
|
||||||
@@ -397,8 +471,9 @@ class CopyOrderTrackingService(
|
|||||||
tradeId = trade.id
|
tradeId = trade.id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 处理订单创建失败
|
||||||
if (createOrderResult.isFailure) {
|
if (createOrderResult.isFailure) {
|
||||||
// 创建订单失败,记录到失败表
|
// 提取错误信息(只保留 code 和 errorBody)
|
||||||
val exception = createOrderResult.exceptionOrNull()
|
val exception = createOrderResult.exceptionOrNull()
|
||||||
val errorMsg = buildFullErrorMessage(
|
val errorMsg = buildFullErrorMessage(
|
||||||
exception,
|
exception,
|
||||||
@@ -407,16 +482,19 @@ class CopyOrderTrackingService(
|
|||||||
finalBuyQuantity.toString(),
|
finalBuyQuantity.toString(),
|
||||||
trade.id
|
trade.id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 记录失败交易到数据库
|
||||||
|
// retryCount = MAX_RETRY_ATTEMPTS - 1,表示已重试的次数
|
||||||
recordFailedTrade(
|
recordFailedTrade(
|
||||||
leaderId = leaderId,
|
leaderId = leaderId,
|
||||||
trade = trade,
|
trade = trade,
|
||||||
copyTradingId = copyTrading.id!!,
|
copyTradingId = copyTrading.id!!,
|
||||||
accountId = copyTrading.accountId,
|
accountId = copyTrading.accountId,
|
||||||
side = "BUY", // 订单方向是BUY
|
side = "BUY",
|
||||||
price = buyPrice.toString(),
|
price = buyPrice.toString(),
|
||||||
size = finalBuyQuantity.toString(),
|
size = finalBuyQuantity.toString(),
|
||||||
errorMessage = errorMsg,
|
errorMessage = errorMsg,
|
||||||
retryCount = 1 // 已重试一次
|
retryCount = MAX_RETRY_ATTEMPTS - 1 // 已重试次数
|
||||||
)
|
)
|
||||||
|
|
||||||
// 发送订单失败通知(异步,不阻塞,仅在 pushFailedOrders 为 true 时发送)
|
// 发送订单失败通知(异步,不阻塞,仅在 pushFailedOrders 为 true 时发送)
|
||||||
@@ -427,7 +505,8 @@ class CopyOrderTrackingService(
|
|||||||
val marketInfo = withContext(Dispatchers.IO) {
|
val marketInfo = withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
val gammaApi = retrofitFactory.createGammaApi()
|
val gammaApi = retrofitFactory.createGammaApi()
|
||||||
val marketResponse = gammaApi.listMarkets(conditionIds = listOf(trade.market))
|
val marketResponse =
|
||||||
|
gammaApi.listMarkets(conditionIds = listOf(trade.market))
|
||||||
if (marketResponse.isSuccessful && marketResponse.body() != null) {
|
if (marketResponse.isSuccessful && marketResponse.body() != null) {
|
||||||
marketResponse.body()!!.firstOrNull()
|
marketResponse.body()!!.firstOrNull()
|
||||||
} else {
|
} else {
|
||||||
@@ -544,7 +623,7 @@ class CopyOrderTrackingService(
|
|||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
java.util.Locale("zh", "CN") // 默认简体中文
|
java.util.Locale("zh", "CN") // 默认简体中文
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取 Leader 和跟单配置信息
|
// 获取 Leader 和跟单配置信息
|
||||||
val leader = leaderRepository.findById(copyTrading.leaderId).orElse(null)
|
val leader = leaderRepository.findById(copyTrading.leaderId).orElse(null)
|
||||||
val leaderName = leader?.leaderName
|
val leaderName = leader?.leaderName
|
||||||
@@ -648,8 +727,8 @@ class CopyOrderTrackingService(
|
|||||||
* 卖出订单匹配
|
* 卖出订单匹配
|
||||||
* 统一按比例计算,不区分RATIO或FIXED模式
|
* 统一按比例计算,不区分RATIO或FIXED模式
|
||||||
* 实际创建卖出订单并记录匹配关系
|
* 实际创建卖出订单并记录匹配关系
|
||||||
|
* 注意:此方法在 @Transactional 方法中被调用,会自动继承事务
|
||||||
*/
|
*/
|
||||||
@Transactional
|
|
||||||
private suspend fun matchSellOrder(
|
private suspend fun matchSellOrder(
|
||||||
copyTrading: CopyTrading,
|
copyTrading: CopyTrading,
|
||||||
leaderSellTrade: TradeResponse
|
leaderSellTrade: TradeResponse
|
||||||
@@ -693,7 +772,28 @@ class CopyOrderTrackingService(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 按FIFO顺序匹配,计算实际可以卖出的数量
|
// 4. 获取tokenId(直接使用outcomeIndex,支持多元市场)
|
||||||
|
val tokenIdResult = blockchainService.getTokenId(leaderSellTrade.market, leaderSellTrade.outcomeIndex)
|
||||||
|
if (tokenIdResult.isFailure) {
|
||||||
|
logger.error("获取tokenId失败: market=${leaderSellTrade.market}, outcomeIndex=${leaderSellTrade.outcomeIndex}, error=${tokenIdResult.exceptionOrNull()?.message}")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val tokenId = tokenIdResult.getOrNull() ?: return
|
||||||
|
|
||||||
|
// 5. 计算卖出价格(优先使用订单簿 bestBid,失败则使用 Leader 价格,固定按90%计算)
|
||||||
|
// 注意:需要先计算卖出价格,因为后续创建 matchDetails 需要使用实际卖出价格
|
||||||
|
val leaderPrice = leaderSellTrade.price.toSafeBigDecimal()
|
||||||
|
val sellPrice = runCatching {
|
||||||
|
clobService.getOrderbookByTokenId(tokenId)
|
||||||
|
.getOrNull()
|
||||||
|
?.let { calculateMarketSellPrice(it) }
|
||||||
|
}
|
||||||
|
.onFailure { e -> logger.warn("获取订单簿或计算 bestBid 失败,使用 Leader 价格: tokenId=$tokenId, error=${e.message}") }
|
||||||
|
.getOrNull()
|
||||||
|
?: calculateFallbackSellPrice(leaderPrice)
|
||||||
|
|
||||||
|
// 6. 按FIFO顺序匹配,计算实际可以卖出的数量
|
||||||
|
// 使用计算出的实际卖出价格(而不是 Leader 价格)来创建匹配明细
|
||||||
var totalMatched = BigDecimal.ZERO
|
var totalMatched = BigDecimal.ZERO
|
||||||
var remaining = needMatch
|
var remaining = needMatch
|
||||||
val matchDetails = mutableListOf<SellMatchDetail>()
|
val matchDetails = mutableListOf<SellMatchDetail>()
|
||||||
@@ -708,19 +808,18 @@ class CopyOrderTrackingService(
|
|||||||
|
|
||||||
if (matchQty.lte(BigDecimal.ZERO)) continue
|
if (matchQty.lte(BigDecimal.ZERO)) continue
|
||||||
|
|
||||||
// 计算盈亏
|
// 计算盈亏(使用实际卖出价格)
|
||||||
val buyPrice = order.price.toSafeBigDecimal()
|
val buyPrice = order.price.toSafeBigDecimal()
|
||||||
val sellPrice = leaderSellTrade.price.toSafeBigDecimal()
|
|
||||||
val realizedPnl = sellPrice.subtract(buyPrice).multi(matchQty)
|
val realizedPnl = sellPrice.subtract(buyPrice).multi(matchQty)
|
||||||
|
|
||||||
// 创建匹配明细(稍后保存)
|
// 创建匹配明细(使用实际卖出价格)
|
||||||
val detail = SellMatchDetail(
|
val detail = SellMatchDetail(
|
||||||
matchRecordId = 0, // 稍后设置
|
matchRecordId = 0, // 稍后设置
|
||||||
trackingId = order.id!!,
|
trackingId = order.id!!,
|
||||||
buyOrderId = order.buyOrderId,
|
buyOrderId = order.buyOrderId,
|
||||||
matchedQuantity = matchQty,
|
matchedQuantity = matchQty,
|
||||||
buyPrice = buyPrice,
|
buyPrice = buyPrice,
|
||||||
sellPrice = sellPrice,
|
sellPrice = sellPrice, // 使用实际卖出价格,与 SellMatchRecord 保持一致
|
||||||
realizedPnl = realizedPnl
|
realizedPnl = realizedPnl
|
||||||
)
|
)
|
||||||
matchDetails.add(detail)
|
matchDetails.add(detail)
|
||||||
@@ -733,25 +832,6 @@ class CopyOrderTrackingService(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. 获取tokenId(直接使用outcomeIndex,支持多元市场)
|
|
||||||
val tokenIdResult = blockchainService.getTokenId(leaderSellTrade.market, leaderSellTrade.outcomeIndex)
|
|
||||||
if (tokenIdResult.isFailure) {
|
|
||||||
logger.error("获取tokenId失败: market=${leaderSellTrade.market}, outcomeIndex=${leaderSellTrade.outcomeIndex}, error=${tokenIdResult.exceptionOrNull()?.message}")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val tokenId = tokenIdResult.getOrNull() ?: return
|
|
||||||
|
|
||||||
// 6. 计算卖出价格(优先使用订单簿 bestBid,失败则使用 Leader 价格,固定按90%计算)
|
|
||||||
val leaderPrice = leaderSellTrade.price.toSafeBigDecimal()
|
|
||||||
val sellPrice = runCatching {
|
|
||||||
clobService.getOrderbookByTokenId(tokenId)
|
|
||||||
.getOrNull()
|
|
||||||
?.let { calculateMarketSellPrice(it) }
|
|
||||||
}
|
|
||||||
.onFailure { e -> logger.warn("获取订单簿或计算 bestBid 失败,使用 Leader 价格: tokenId=$tokenId, error=${e.message}") }
|
|
||||||
.getOrNull()
|
|
||||||
?: calculateFallbackSellPrice(leaderPrice)
|
|
||||||
|
|
||||||
// 7. 解密私钥(在方法开始时解密一次,后续复用)
|
// 7. 解密私钥(在方法开始时解密一次,后续复用)
|
||||||
val decryptedPrivateKey = decryptPrivateKey(account)
|
val decryptedPrivateKey = decryptPrivateKey(account)
|
||||||
// 8. 创建并签名卖出订单
|
// 8. 创建并签名卖出订单
|
||||||
@@ -872,8 +952,23 @@ class CopyOrderTrackingService(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建订单(带重试机制)
|
* 创建订单(带重试机制)
|
||||||
* 失败后重试一次,如果仍然失败则返回失败结果
|
*
|
||||||
* 注意:重试时会重新生成salt并重新签名,确保每次重试都是新的订单
|
* 重试策略:
|
||||||
|
* - 最多重试 MAX_RETRY_ATTEMPTS 次(首次尝试 + 重试)
|
||||||
|
* - 每次重试前等待 RETRY_DELAY_MS 毫秒
|
||||||
|
* - 每次重试都重新生成salt并重新签名,确保签名唯一性
|
||||||
|
*
|
||||||
|
* @param clobApi CLOB API 客户端
|
||||||
|
* @param privateKey 私钥(用于签名)
|
||||||
|
* @param makerAddress 代理钱包地址
|
||||||
|
* @param tokenId Token ID
|
||||||
|
* @param side 订单方向(BUY/SELL)
|
||||||
|
* @param price 价格
|
||||||
|
* @param size 数量
|
||||||
|
* @param owner API Key(用于owner字段)
|
||||||
|
* @param copyTradingId 跟单配置ID(用于日志)
|
||||||
|
* @param tradeId Leader 交易ID(用于日志)
|
||||||
|
* @return 成功返回订单ID,失败返回异常
|
||||||
*/
|
*/
|
||||||
private suspend fun createOrderWithRetry(
|
private suspend fun createOrderWithRetry(
|
||||||
clobApi: PolymarketClobApi,
|
clobApi: PolymarketClobApi,
|
||||||
@@ -883,16 +978,16 @@ class CopyOrderTrackingService(
|
|||||||
side: String,
|
side: String,
|
||||||
price: String,
|
price: String,
|
||||||
size: String,
|
size: String,
|
||||||
owner: String, // API Key,用于owner字段
|
owner: String,
|
||||||
copyTradingId: Long,
|
copyTradingId: Long,
|
||||||
tradeId: String
|
tradeId: String
|
||||||
): Result<String> {
|
): Result<String> {
|
||||||
var lastError: Exception? = null
|
var lastError: Exception? = null
|
||||||
|
|
||||||
// 最多重试2次(首次 + 1次重试)
|
// 重试循环:最多重试 MAX_RETRY_ATTEMPTS 次
|
||||||
for (attempt in 1..2) {
|
for (attempt in 1..MAX_RETRY_ATTEMPTS) {
|
||||||
try {
|
try {
|
||||||
// 每次重试都重新生成salt并重新签名
|
// 每次重试都重新生成salt并重新签名,确保签名唯一性
|
||||||
val signedOrder = orderSigningService.createAndSignOrder(
|
val signedOrder = orderSigningService.createAndSignOrder(
|
||||||
privateKey = privateKey,
|
privateKey = privateKey,
|
||||||
makerAddress = makerAddress,
|
makerAddress = makerAddress,
|
||||||
@@ -906,76 +1001,118 @@ class CopyOrderTrackingService(
|
|||||||
expiration = "0"
|
expiration = "0"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 构建订单请求(每次重试都使用新签名的订单)
|
// 构建订单请求
|
||||||
// 跟单订单使用 FAK (Fill-And-Kill),允许部分成交,未成交部分立即取消
|
// 跟单订单使用 FAK (Fill-And-Kill),允许部分成交,未成交部分立即取消
|
||||||
// 这样可以快速响应 Leader 的交易,避免订单长期挂单导致价格不匹配
|
// 这样可以快速响应 Leader 的交易,避免订单长期挂单导致价格不匹配
|
||||||
val orderRequest = NewOrderRequest(
|
val orderRequest = NewOrderRequest(
|
||||||
order = signedOrder,
|
order = signedOrder,
|
||||||
owner = owner, // API Key
|
owner = owner,
|
||||||
orderType = "FAK", // Fill-And-Kill
|
orderType = "FAK", // Fill-And-Kill
|
||||||
deferExec = false
|
deferExec = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 调用 API 创建订单
|
||||||
val orderResponse = clobApi.createOrder(orderRequest)
|
val orderResponse = clobApi.createOrder(orderRequest)
|
||||||
|
|
||||||
|
// 检查 HTTP 响应状态
|
||||||
if (!orderResponse.isSuccessful || orderResponse.body() == null) {
|
if (!orderResponse.isSuccessful || orderResponse.body() == null) {
|
||||||
val errorBody = try {
|
val errorBody = try {
|
||||||
orderResponse.errorBody()?.string()
|
orderResponse.errorBody()?.string()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
val errorMsg =
|
val errorMsg = "code=${orderResponse.code()}, errorBody=${errorBody ?: "null"}"
|
||||||
"创建订单失败: copyTradingId=$copyTradingId, tradeId=$tradeId, attempt=$attempt, side=$side, price=$price, size=$size, tokenId=$tokenId, code=${orderResponse.code()}, message=${orderResponse.message()}${if (errorBody != null) ", errorBody=$errorBody" else ""}"
|
|
||||||
lastError = Exception(errorMsg)
|
lastError = Exception(errorMsg)
|
||||||
// 所有失败都记录详细日志
|
|
||||||
logger.error(errorMsg)
|
// 记录错误日志
|
||||||
if (attempt < 2) {
|
logger.error("创建订单失败 (尝试 $attempt/$MAX_RETRY_ATTEMPTS): copyTradingId=$copyTradingId, tradeId=$tradeId, $errorMsg")
|
||||||
delay(1000) // 重试前等待1秒
|
|
||||||
|
// 如果不是最后一次尝试,等待后重试
|
||||||
|
if (attempt < MAX_RETRY_ATTEMPTS) {
|
||||||
|
delay(RETRY_DELAY_MS)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return Result.failure(lastError)
|
return Result.failure(lastError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查业务响应状态
|
||||||
val response = orderResponse.body()!!
|
val response = orderResponse.body()!!
|
||||||
if (!response.success || response.orderId == null) {
|
if (!response.success || response.orderId == null) {
|
||||||
val errorMsg =
|
val errorMsg = "errorMsg=${response.errorMsg}"
|
||||||
"创建订单失败: copyTradingId=$copyTradingId, tradeId=$tradeId, attempt=$attempt, side=$side, price=$price, size=$size, tokenId=$tokenId, errorMsg=${response.errorMsg}"
|
|
||||||
lastError = Exception(errorMsg)
|
lastError = Exception(errorMsg)
|
||||||
// 所有失败都记录详细日志
|
|
||||||
logger.error(errorMsg)
|
// 记录错误日志
|
||||||
if (attempt < 2) {
|
logger.error("创建订单失败 (尝试 $attempt/$MAX_RETRY_ATTEMPTS): copyTradingId=$copyTradingId, tradeId=$tradeId, $errorMsg")
|
||||||
delay(1000) // 重试前等待1秒
|
|
||||||
|
// 如果不是最后一次尝试,等待后重试
|
||||||
|
if (attempt < MAX_RETRY_ATTEMPTS) {
|
||||||
|
delay(RETRY_DELAY_MS)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return Result.failure(lastError)
|
return Result.failure(lastError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 成功
|
// 创建订单成功
|
||||||
|
logger.info("创建订单成功: copyTradingId=$copyTradingId, tradeId=$tradeId, orderId=${response.orderId}, attempt=$attempt")
|
||||||
return Result.success(response.orderId)
|
return Result.success(response.orderId)
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
val errorMsg =
|
val errorMsg = "error=${e.message}"
|
||||||
"调用创建订单API异常: copyTradingId=$copyTradingId, tradeId=$tradeId, attempt=$attempt, side=$side, price=$price, size=$size, tokenId=$tokenId, error=${e.message}"
|
|
||||||
lastError = Exception(errorMsg, e)
|
lastError = Exception(errorMsg, e)
|
||||||
// 所有失败都记录详细日志(包括堆栈)
|
|
||||||
logger.error(errorMsg, e)
|
// 记录错误日志(包含堆栈)
|
||||||
if (attempt < 2) {
|
logger.error("创建订单异常 (尝试 $attempt/$MAX_RETRY_ATTEMPTS): copyTradingId=$copyTradingId, tradeId=$tradeId, $errorMsg", e)
|
||||||
delay(1000) // 重试前等待1秒
|
|
||||||
|
// 如果不是最后一次尝试,等待后重试
|
||||||
|
if (attempt < MAX_RETRY_ATTEMPTS) {
|
||||||
|
delay(RETRY_DELAY_MS)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return Result.failure(lastError)
|
return Result.failure(lastError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val finalError = lastError ?: Exception("创建订单失败:未知错误")
|
// 所有重试都失败
|
||||||
logger.error(
|
val finalError = lastError ?: Exception("error=未知错误")
|
||||||
"创建订单失败(所有重试都失败): copyTradingId=$copyTradingId, tradeId=$tradeId, side=$side, price=$price, size=$size, tokenId=$tokenId",
|
logger.error("创建订单失败(所有重试都失败): copyTradingId=$copyTradingId, tradeId=$tradeId, side=$side, price=$price, size=$size", finalError)
|
||||||
finalError
|
|
||||||
)
|
|
||||||
return Result.failure(finalError)
|
return Result.failure(finalError)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建完整的错误信息(包括堆栈)
|
* 检查是否是唯一键冲突异常
|
||||||
|
*/
|
||||||
|
private fun isUniqueConstraintViolation(e: Exception): Boolean {
|
||||||
|
// 检查是否是 DataIntegrityViolationException 或 DuplicateKeyException
|
||||||
|
if (e is DataIntegrityViolationException || e is DuplicateKeyException) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否是 SQLException(MySQL 错误码 1062 表示重复键)
|
||||||
|
var cause: Throwable? = e.cause
|
||||||
|
while (cause != null) {
|
||||||
|
if (cause is SQLException) {
|
||||||
|
val sqlException = cause as SQLException
|
||||||
|
// MySQL 错误码 1062 表示重复键(Duplicate entry)
|
||||||
|
if (sqlException.errorCode == 1062 || sqlException.sqlState == "23000") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 检查异常消息中是否包含唯一键冲突的关键字
|
||||||
|
val message = cause.message ?: ""
|
||||||
|
if (message.contains("Duplicate entry") ||
|
||||||
|
message.contains("uk_leader_trade") ||
|
||||||
|
message.contains("UNIQUE constraint")
|
||||||
|
) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
cause = cause.cause
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建简化的错误信息(只保留 code 和 errorBody)
|
||||||
*/
|
*/
|
||||||
private fun buildFullErrorMessage(
|
private fun buildFullErrorMessage(
|
||||||
exception: Throwable?,
|
exception: Throwable?,
|
||||||
@@ -985,35 +1122,29 @@ class CopyOrderTrackingService(
|
|||||||
tradeId: String
|
tradeId: String
|
||||||
): String {
|
): String {
|
||||||
if (exception == null) {
|
if (exception == null) {
|
||||||
return "创建订单失败: side=$side, price=$price, size=$size, tradeId=$tradeId, 未知错误"
|
return "code=未知, errorBody=null"
|
||||||
}
|
}
|
||||||
|
|
||||||
val errorMsg = StringBuilder()
|
val exceptionMessage = exception.message ?: ""
|
||||||
errorMsg.append("创建订单失败: side=$side, price=$price, size=$size, tradeId=$tradeId")
|
|
||||||
errorMsg.append(", error=${exception.message}")
|
|
||||||
|
|
||||||
// 添加堆栈信息(限制长度,避免过长)
|
// 从错误信息中提取 code 和 errorBody
|
||||||
val stackTrace = exception.stackTraceToString()
|
val codePattern = Regex("code=([^,}]+)")
|
||||||
val maxLength = 2000 // 限制错误信息最大长度为2000字符
|
val errorBodyPattern = Regex("errorBody=([^,}]+)")
|
||||||
if (stackTrace.length > maxLength) {
|
|
||||||
errorMsg.append(", stackTrace=${stackTrace.substring(0, maxLength)}...")
|
|
||||||
} else {
|
|
||||||
errorMsg.append(", stackTrace=$stackTrace")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果有 cause,也添加
|
val codeMatch = codePattern.find(exceptionMessage)
|
||||||
exception.cause?.let { cause ->
|
val errorBodyMatch = errorBodyPattern.find(exceptionMessage)
|
||||||
errorMsg.append(", cause=${cause.message}")
|
|
||||||
}
|
|
||||||
|
|
||||||
return errorMsg.toString()
|
val code = codeMatch?.groupValues?.get(1)?.trim() ?: "未知"
|
||||||
|
val errorBody = errorBodyMatch?.groupValues?.get(1)?.trim() ?: "null"
|
||||||
|
|
||||||
|
return "code=$code, errorBody=$errorBody"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 记录失败交易到数据库
|
* 记录失败交易到数据库
|
||||||
|
* 注意:此方法在 @Transactional 方法中被调用,会自动继承事务
|
||||||
*/
|
*/
|
||||||
@Transactional
|
private suspend fun recordFailedTrade(
|
||||||
private fun recordFailedTrade(
|
|
||||||
leaderId: Long,
|
leaderId: Long,
|
||||||
trade: TradeResponse,
|
trade: TradeResponse,
|
||||||
copyTradingId: Long,
|
copyTradingId: Long,
|
||||||
@@ -1064,21 +1195,35 @@ class CopyOrderTrackingService(
|
|||||||
processedAt = System.currentTimeMillis()
|
processedAt = System.currentTimeMillis()
|
||||||
)
|
)
|
||||||
processedTradeRepository.save(processed)
|
processedTradeRepository.save(processed)
|
||||||
} catch (e: DataIntegrityViolationException) {
|
} catch (e: Exception) {
|
||||||
// 唯一约束冲突,说明已经处理过了(可能是并发请求)
|
// 检查是否是唯一键冲突异常
|
||||||
// 检查现有记录的状态
|
if (isUniqueConstraintViolation(e)) {
|
||||||
val existing = processedTradeRepository.findByLeaderIdAndLeaderTradeId(leaderId, trade.id)
|
// 唯一约束冲突,说明已经处理过了(可能是并发请求)
|
||||||
if (existing != null) {
|
// 检查现有记录的状态
|
||||||
if (existing.status == "SUCCESS") {
|
val existing = processedTradeRepository.findByLeaderIdAndLeaderTradeId(leaderId, trade.id)
|
||||||
logger.warn("交易已成功处理,但尝试记录为失败(并发冲突): leaderId=$leaderId, tradeId=${trade.id}")
|
if (existing != null) {
|
||||||
|
if (existing.status == "SUCCESS") {
|
||||||
|
logger.warn("交易已成功处理,但尝试记录为失败(并发冲突): leaderId=$leaderId, tradeId=${trade.id}")
|
||||||
|
} else {
|
||||||
|
logger.debug("交易已标记为失败(并发检测): leaderId=$leaderId, tradeId=${trade.id}")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.debug("交易已标记为失败(并发检测): leaderId=$leaderId, tradeId=${trade.id}")
|
// 如果查询不到,等待一下再查询(可能是事务隔离级别问题)
|
||||||
|
delay(100)
|
||||||
|
val existingAfterDelay =
|
||||||
|
processedTradeRepository.findByLeaderIdAndLeaderTradeId(leaderId, trade.id)
|
||||||
|
if (existingAfterDelay != null) {
|
||||||
|
logger.debug("延迟查询到记录(并发检测): leaderId=$leaderId, tradeId=${trade.id}, status=${existingAfterDelay.status}")
|
||||||
|
} else {
|
||||||
|
logger.warn(
|
||||||
|
"保存ProcessedTrade失败记录时发生唯一约束冲突,但查询不到记录: leaderId=$leaderId, tradeId=${trade.id}",
|
||||||
|
e
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warn(
|
// 其他类型的异常,记录但不抛出(避免影响其他交易的处理)
|
||||||
"保存ProcessedTrade失败记录时发生唯一约束冲突,但查询不到记录: leaderId=$leaderId, tradeId=${trade.id}",
|
logger.warn("保存ProcessedTrade失败记录时发生异常: leaderId=$leaderId, tradeId=${trade.id}", e)
|
||||||
e
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1201,6 +1346,8 @@ class CopyOrderTrackingService(
|
|||||||
FilterStatus.FAILED_ORDERBOOK_EMPTY -> "ORDERBOOK_EMPTY"
|
FilterStatus.FAILED_ORDERBOOK_EMPTY -> "ORDERBOOK_EMPTY"
|
||||||
FilterStatus.FAILED_SPREAD -> "SPREAD"
|
FilterStatus.FAILED_SPREAD -> "SPREAD"
|
||||||
FilterStatus.FAILED_ORDER_DEPTH -> "ORDER_DEPTH"
|
FilterStatus.FAILED_ORDER_DEPTH -> "ORDER_DEPTH"
|
||||||
|
FilterStatus.FAILED_MAX_POSITION_VALUE -> "MAX_POSITION_VALUE"
|
||||||
|
FilterStatus.FAILED_MAX_POSITION_COUNT -> "MAX_POSITION_COUNT"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -298,8 +298,10 @@ class CopyTradingStatisticsService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 卖出统计
|
// 卖出统计
|
||||||
|
// 使用 SellMatchDetail 计算总卖出金额,确保准确性
|
||||||
|
// 因为每个明细都记录了准确的匹配数量和卖出价格
|
||||||
val totalSellQuantity = sellRecords.sumOf { it.totalMatchedQuantity.toSafeBigDecimal() }
|
val totalSellQuantity = sellRecords.sumOf { it.totalMatchedQuantity.toSafeBigDecimal() }
|
||||||
val totalSellAmount = sellRecords.sumOf { it.totalMatchedQuantity.toSafeBigDecimal().multi(it.sellPrice) }
|
val totalSellAmount = matchDetails.sumOf { it.matchedQuantity.toSafeBigDecimal().multi(it.sellPrice) }
|
||||||
val totalSellOrders = sellRecords.size.toLong()
|
val totalSellOrders = sellRecords.size.toLong()
|
||||||
|
|
||||||
// 持仓统计
|
// 持仓统计
|
||||||
|
|||||||
@@ -36,10 +36,38 @@ class SystemConfigService(
|
|||||||
val builderPassphrase = getConfigValue(CONFIG_KEY_BUILDER_PASSPHRASE)
|
val builderPassphrase = getConfigValue(CONFIG_KEY_BUILDER_PASSPHRASE)
|
||||||
val autoRedeem = isAutoRedeemEnabled()
|
val autoRedeem = isAutoRedeemEnabled()
|
||||||
|
|
||||||
|
// 获取完整的 API Key(用于前端展示)
|
||||||
|
val builderApiKeyDisplay = builderApiKey?.let {
|
||||||
|
try {
|
||||||
|
cryptoUtils.decrypt(it)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val builderSecretDisplay = builderSecret?.let {
|
||||||
|
try {
|
||||||
|
cryptoUtils.decrypt(it)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val builderPassphraseDisplay = builderPassphrase?.let {
|
||||||
|
try {
|
||||||
|
cryptoUtils.decrypt(it)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return SystemConfigDto(
|
return SystemConfigDto(
|
||||||
builderApiKeyConfigured = builderApiKey != null,
|
builderApiKeyConfigured = builderApiKey != null,
|
||||||
builderSecretConfigured = builderSecret != null,
|
builderSecretConfigured = builderSecret != null,
|
||||||
builderPassphraseConfigured = builderPassphrase != null,
|
builderPassphraseConfigured = builderPassphrase != null,
|
||||||
|
builderApiKeyDisplay = builderApiKeyDisplay,
|
||||||
|
builderSecretDisplay = builderSecretDisplay,
|
||||||
|
builderPassphraseDisplay = builderPassphraseDisplay,
|
||||||
autoRedeemEnabled = autoRedeem
|
autoRedeemEnabled = autoRedeem
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
-- ============================================
|
||||||
|
-- V11: 添加最大仓位配置字段
|
||||||
|
-- 在 copy_trading 表中添加最大仓位金额和最大仓位数量配置
|
||||||
|
-- ============================================
|
||||||
|
|
||||||
|
ALTER TABLE copy_trading
|
||||||
|
ADD COLUMN max_position_value DECIMAL(20, 8) NULL COMMENT '最大仓位金额(USDC),NULL表示不启用' AFTER max_price,
|
||||||
|
ADD COLUMN max_position_count INT NULL COMMENT '最大仓位数量,NULL表示不启用' AFTER max_position_value;
|
||||||
|
|
||||||
@@ -648,5 +648,5 @@ Vite uses `.env.production` file to inject environment variables during build. T
|
|||||||
|
|
||||||
## Technical Support
|
## Technical Support
|
||||||
|
|
||||||
If you have any questions, please submit an Issue to [GitHub](https://github.com/WrBug/PolyHermes) or contact [Twitter](https://x.com/quant_tr).
|
If you have any questions, please submit an Issue to [GitHub](https://github.com/WrBug/PolyHermes) or contact [Twitter](https://x.com/polyhermes).
|
||||||
|
|
||||||
|
|||||||
@@ -648,5 +648,5 @@ Vite 使用 `.env.production` 文件在构建时注入环境变量。构建脚
|
|||||||
|
|
||||||
## 技术支持
|
## 技术支持
|
||||||
|
|
||||||
如有问题,请提交 Issue 到 [GitHub](https://github.com/WrBug/PolyHermes) 或联系 [Twitter](https://x.com/quant_tr)。
|
如有问题,请提交 Issue 到 [GitHub](https://github.com/WrBug/PolyHermes) 或联系 [Twitter](https://x.com/polyhermes)。
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,342 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import { Form, Input, Button, Radio, Space, Alert } from 'antd'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { useAccountStore } from '../store/accountStore'
|
||||||
|
import {
|
||||||
|
getAddressFromPrivateKey,
|
||||||
|
getAddressFromMnemonic,
|
||||||
|
getPrivateKeyFromMnemonic,
|
||||||
|
isValidWalletAddress,
|
||||||
|
isValidPrivateKey,
|
||||||
|
isValidMnemonic
|
||||||
|
} from '../utils'
|
||||||
|
import { useMediaQuery } from 'react-responsive'
|
||||||
|
|
||||||
|
type ImportType = 'privateKey' | 'mnemonic'
|
||||||
|
|
||||||
|
interface AccountImportFormProps {
|
||||||
|
form: any
|
||||||
|
onSuccess?: (accountId: number) => void
|
||||||
|
onCancel?: () => void
|
||||||
|
showAlert?: boolean
|
||||||
|
showCancelButton?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const AccountImportForm: React.FC<AccountImportFormProps> = ({
|
||||||
|
form,
|
||||||
|
onSuccess,
|
||||||
|
onCancel,
|
||||||
|
showAlert = true,
|
||||||
|
showCancelButton = true
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const isMobile = useMediaQuery({ maxWidth: 768 })
|
||||||
|
const { importAccount, loading } = useAccountStore()
|
||||||
|
const [importType, setImportType] = useState<ImportType>('privateKey')
|
||||||
|
const [derivedAddress, setDerivedAddress] = useState<string>('')
|
||||||
|
const [addressError, setAddressError] = useState<string>('')
|
||||||
|
|
||||||
|
// 当私钥输入时,自动推导地址
|
||||||
|
const handlePrivateKeyChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
|
const privateKey = e.target.value.trim()
|
||||||
|
if (!privateKey) {
|
||||||
|
setDerivedAddress('')
|
||||||
|
setAddressError('')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证私钥格式
|
||||||
|
if (!isValidPrivateKey(privateKey)) {
|
||||||
|
setAddressError(t('accountImport.privateKeyInvalid'))
|
||||||
|
setDerivedAddress('')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const address = getAddressFromPrivateKey(privateKey)
|
||||||
|
setDerivedAddress(address)
|
||||||
|
setAddressError('')
|
||||||
|
|
||||||
|
// 自动填充钱包地址字段
|
||||||
|
form.setFieldsValue({ walletAddress: address })
|
||||||
|
} catch (error: any) {
|
||||||
|
setAddressError(error.message || t('accountImport.addressError'))
|
||||||
|
setDerivedAddress('')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 当助记词输入时,自动推导地址
|
||||||
|
const handleMnemonicChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
|
const mnemonic = e.target.value.trim()
|
||||||
|
if (!mnemonic) {
|
||||||
|
setDerivedAddress('')
|
||||||
|
setAddressError('')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证助记词格式
|
||||||
|
if (!isValidMnemonic(mnemonic)) {
|
||||||
|
setAddressError(t('accountImport.mnemonicInvalid'))
|
||||||
|
setDerivedAddress('')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const address = getAddressFromMnemonic(mnemonic, 0)
|
||||||
|
setDerivedAddress(address)
|
||||||
|
setAddressError('')
|
||||||
|
|
||||||
|
// 自动填充钱包地址字段
|
||||||
|
form.setFieldsValue({ walletAddress: address })
|
||||||
|
} catch (error: any) {
|
||||||
|
setAddressError(error.message || t('accountImport.addressErrorMnemonic'))
|
||||||
|
setDerivedAddress('')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async (values: any) => {
|
||||||
|
try {
|
||||||
|
let privateKey: string
|
||||||
|
let walletAddress: string
|
||||||
|
|
||||||
|
if (importType === 'privateKey') {
|
||||||
|
// 私钥模式
|
||||||
|
privateKey = values.privateKey
|
||||||
|
walletAddress = values.walletAddress
|
||||||
|
|
||||||
|
// 验证推导的地址和输入的地址是否一致
|
||||||
|
if (derivedAddress && walletAddress !== derivedAddress) {
|
||||||
|
return Promise.reject(new Error(t('accountImport.walletAddressMismatch')))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 助记词模式
|
||||||
|
if (!values.mnemonic) {
|
||||||
|
return Promise.reject(new Error(t('accountImport.mnemonicRequired')))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从助记词导出私钥和地址
|
||||||
|
privateKey = getPrivateKeyFromMnemonic(values.mnemonic, 0)
|
||||||
|
const derivedAddressFromMnemonic = getAddressFromMnemonic(values.mnemonic, 0)
|
||||||
|
|
||||||
|
// 如果用户手动输入了地址,验证是否与推导的地址一致
|
||||||
|
if (values.walletAddress) {
|
||||||
|
if (values.walletAddress !== derivedAddressFromMnemonic) {
|
||||||
|
// 地址不匹配,使用推导的地址(因为私钥是从助记词导出的,必须使用对应的地址)
|
||||||
|
walletAddress = derivedAddressFromMnemonic
|
||||||
|
} else {
|
||||||
|
// 地址匹配,使用用户输入的地址
|
||||||
|
walletAddress = values.walletAddress
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果用户没有输入地址,使用推导的地址
|
||||||
|
walletAddress = derivedAddressFromMnemonic
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证钱包地址格式
|
||||||
|
if (!isValidWalletAddress(walletAddress)) {
|
||||||
|
return Promise.reject(new Error(t('accountImport.walletAddressInvalid')))
|
||||||
|
}
|
||||||
|
|
||||||
|
await importAccount({
|
||||||
|
privateKey: privateKey,
|
||||||
|
walletAddress: walletAddress,
|
||||||
|
accountName: values.accountName
|
||||||
|
})
|
||||||
|
|
||||||
|
// 等待store更新
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 100))
|
||||||
|
|
||||||
|
// 获取新添加的账户ID(通过API获取,因为store可能还没更新)
|
||||||
|
const { apiService } = await import('../services/api')
|
||||||
|
const accountsResponse = await apiService.accounts.list()
|
||||||
|
if (accountsResponse.data.code === 0 && accountsResponse.data.data) {
|
||||||
|
const newAccounts = accountsResponse.data.data.list || []
|
||||||
|
const newAccount = newAccounts.find((acc: any) => acc.walletAddress === walletAddress)
|
||||||
|
if (newAccount && onSuccess) {
|
||||||
|
onSuccess(newAccount.id)
|
||||||
|
} else if (onSuccess) {
|
||||||
|
// 如果找不到账户,仍然调用onSuccess(可能在其他地方处理)
|
||||||
|
onSuccess(0)
|
||||||
|
}
|
||||||
|
} else if (onSuccess) {
|
||||||
|
// API调用失败,仍然调用onSuccess
|
||||||
|
onSuccess(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve()
|
||||||
|
} catch (error: any) {
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{showAlert && (
|
||||||
|
<Alert
|
||||||
|
message={t('accountImport.securityTip')}
|
||||||
|
description={t('accountImport.securityTipDesc')}
|
||||||
|
type="warning"
|
||||||
|
showIcon
|
||||||
|
style={{ marginBottom: '24px' }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Form
|
||||||
|
form={form}
|
||||||
|
layout="vertical"
|
||||||
|
onFinish={handleSubmit}
|
||||||
|
size={isMobile ? 'middle' : 'large'}
|
||||||
|
>
|
||||||
|
<Form.Item label={t('accountImport.importMethod')}>
|
||||||
|
<Radio.Group
|
||||||
|
value={importType}
|
||||||
|
onChange={(e) => {
|
||||||
|
setImportType(e.target.value)
|
||||||
|
setDerivedAddress('')
|
||||||
|
setAddressError('')
|
||||||
|
form.setFieldsValue({ walletAddress: '' })
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Radio value="privateKey">{t('accountImport.privateKey')}</Radio>
|
||||||
|
<Radio value="mnemonic">{t('accountImport.mnemonic')}</Radio>
|
||||||
|
</Radio.Group>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
{importType === 'privateKey' ? (
|
||||||
|
<>
|
||||||
|
<Form.Item
|
||||||
|
label={t('accountImport.privateKeyLabel')}
|
||||||
|
name="privateKey"
|
||||||
|
rules={[
|
||||||
|
{ required: true, message: t('accountImport.privateKeyRequired') },
|
||||||
|
{
|
||||||
|
validator: (_, value) => {
|
||||||
|
if (!value) return Promise.resolve()
|
||||||
|
if (!isValidPrivateKey(value)) {
|
||||||
|
return Promise.reject(new Error(t('accountImport.privateKeyInvalid')))
|
||||||
|
}
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
help={addressError || (derivedAddress ? `${t('accountImport.derivedAddress')}: ${derivedAddress}` : '')}
|
||||||
|
validateStatus={addressError ? 'error' : derivedAddress ? 'success' : ''}
|
||||||
|
>
|
||||||
|
<Input.TextArea
|
||||||
|
rows={3}
|
||||||
|
placeholder={t('accountImport.privateKeyPlaceholder')}
|
||||||
|
onChange={handlePrivateKeyChange}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
label={t('accountImport.walletAddress')}
|
||||||
|
name="walletAddress"
|
||||||
|
rules={[
|
||||||
|
{ required: true, message: t('accountImport.walletAddressRequired') },
|
||||||
|
{
|
||||||
|
validator: (_, value) => {
|
||||||
|
if (!value) return Promise.resolve()
|
||||||
|
if (!isValidWalletAddress(value)) {
|
||||||
|
return Promise.reject(new Error(t('accountImport.walletAddressInvalid')))
|
||||||
|
}
|
||||||
|
if (derivedAddress && value !== derivedAddress) {
|
||||||
|
return Promise.reject(new Error(t('accountImport.walletAddressMismatch')))
|
||||||
|
}
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
placeholder={t('accountImport.walletAddressPlaceholder')}
|
||||||
|
readOnly={!!derivedAddress}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Form.Item
|
||||||
|
label={t('accountImport.mnemonicLabel')}
|
||||||
|
name="mnemonic"
|
||||||
|
rules={[
|
||||||
|
{ required: true, message: t('accountImport.mnemonicRequired') },
|
||||||
|
{
|
||||||
|
validator: (_, value) => {
|
||||||
|
if (!value) return Promise.resolve()
|
||||||
|
if (!isValidMnemonic(value)) {
|
||||||
|
return Promise.reject(new Error(t('accountImport.mnemonicInvalid')))
|
||||||
|
}
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
help={addressError || (derivedAddress ? `${t('accountImport.derivedAddress')}: ${derivedAddress}` : '')}
|
||||||
|
validateStatus={addressError ? 'error' : derivedAddress ? 'success' : ''}
|
||||||
|
>
|
||||||
|
<Input.TextArea
|
||||||
|
rows={4}
|
||||||
|
placeholder={t('accountImport.mnemonicPlaceholder')}
|
||||||
|
onChange={handleMnemonicChange}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
label={t('accountImport.walletAddress')}
|
||||||
|
name="walletAddress"
|
||||||
|
rules={[
|
||||||
|
{ required: true, message: t('accountImport.walletAddressRequired') },
|
||||||
|
{
|
||||||
|
validator: (_, value) => {
|
||||||
|
if (!value) return Promise.resolve()
|
||||||
|
if (!isValidWalletAddress(value)) {
|
||||||
|
return Promise.reject(new Error(t('accountImport.walletAddressInvalid')))
|
||||||
|
}
|
||||||
|
if (derivedAddress && value !== derivedAddress) {
|
||||||
|
return Promise.reject(new Error(t('accountImport.walletAddressMismatchMnemonic')))
|
||||||
|
}
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
placeholder={t('accountImport.walletAddressPlaceholder')}
|
||||||
|
readOnly={!!derivedAddress}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
label={t('accountImport.accountName')}
|
||||||
|
name="accountName"
|
||||||
|
>
|
||||||
|
<Input placeholder={t('accountImport.accountNamePlaceholder')} />
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item>
|
||||||
|
<Space>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
htmlType="submit"
|
||||||
|
loading={loading}
|
||||||
|
size={isMobile ? 'middle' : 'large'}
|
||||||
|
>
|
||||||
|
{t('accountImport.importAccount')}
|
||||||
|
</Button>
|
||||||
|
{showCancelButton && onCancel && (
|
||||||
|
<Button onClick={onCancel}>
|
||||||
|
{t('common.cancel')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AccountImportForm
|
||||||
|
|
||||||
@@ -238,7 +238,7 @@ const Layout: React.FC<LayoutProps> = ({ children }) => {
|
|||||||
<GithubOutlined />
|
<GithubOutlined />
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
href="https://x.com/quant_tr"
|
href="https://x.com/polyhermes"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
style={{ color: '#fff', fontSize: '16px', display: 'flex', alignItems: 'center' }}
|
style={{ color: '#fff', fontSize: '16px', display: 'flex', alignItems: 'center' }}
|
||||||
@@ -362,7 +362,7 @@ const Layout: React.FC<LayoutProps> = ({ children }) => {
|
|||||||
<GithubOutlined />
|
<GithubOutlined />
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
href="https://x.com/quant_tr"
|
href="https://x.com/polyhermes"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
style={{ color: '#fff', fontSize: '18px', display: 'flex', alignItems: 'center' }}
|
style={{ color: '#fff', fontSize: '18px', display: 'flex', alignItems: 'center' }}
|
||||||
|
|||||||
@@ -0,0 +1,136 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import { Form, Input, Button, Space } from 'antd'
|
||||||
|
import { apiService } from '../services/api'
|
||||||
|
import { useMediaQuery } from 'react-responsive'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { isValidWalletAddress } from '../utils'
|
||||||
|
|
||||||
|
interface LeaderAddFormProps {
|
||||||
|
form: any
|
||||||
|
onSuccess?: (leaderId: number) => void
|
||||||
|
onCancel?: () => void
|
||||||
|
showCancelButton?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const LeaderAddForm: React.FC<LeaderAddFormProps> = ({
|
||||||
|
form,
|
||||||
|
onSuccess,
|
||||||
|
onCancel,
|
||||||
|
showCancelButton = true
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const isMobile = useMediaQuery({ maxWidth: 768 })
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
const handleSubmit = async (values: any) => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const response = await apiService.leaders.add({
|
||||||
|
leaderAddress: values.leaderAddress.trim(),
|
||||||
|
leaderName: values.leaderName?.trim() || undefined,
|
||||||
|
remark: values.remark?.trim() || undefined,
|
||||||
|
website: values.website?.trim() || undefined
|
||||||
|
})
|
||||||
|
|
||||||
|
if (response.data.code === 0) {
|
||||||
|
if (response.data.data && onSuccess) {
|
||||||
|
onSuccess(response.data.data.id)
|
||||||
|
}
|
||||||
|
return Promise.resolve()
|
||||||
|
} else {
|
||||||
|
return Promise.reject(new Error(response.data.msg || t('leaderAdd.addFailed') || '添加 Leader 失败'))
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
return Promise.reject(error)
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form
|
||||||
|
form={form}
|
||||||
|
layout="vertical"
|
||||||
|
onFinish={handleSubmit}
|
||||||
|
size={isMobile ? 'middle' : 'large'}
|
||||||
|
>
|
||||||
|
<Form.Item
|
||||||
|
label={t('leaderAdd.leaderAddress') || 'Leader 钱包地址'}
|
||||||
|
name="leaderAddress"
|
||||||
|
rules={[
|
||||||
|
{ required: true, message: t('leaderAdd.leaderAddressRequired') || '请输入 Leader 钱包地址' },
|
||||||
|
{
|
||||||
|
validator: (_, value) => {
|
||||||
|
if (!value) {
|
||||||
|
return Promise.reject(new Error(t('leaderAdd.leaderAddressRequired') || '请输入 Leader 钱包地址'))
|
||||||
|
}
|
||||||
|
if (!isValidWalletAddress(value.trim())) {
|
||||||
|
return Promise.reject(new Error(t('leaderAdd.leaderAddressInvalid') || '钱包地址格式不正确(必须是 0x 开头的 42 位地址)'))
|
||||||
|
}
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
tooltip={t('leaderAdd.leaderAddressTooltip') || '被跟单者的钱包地址,系统将监控该地址的交易并自动跟单'}
|
||||||
|
>
|
||||||
|
<Input placeholder="0x..." style={{ fontFamily: 'monospace' }} />
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
label={t('leaderAdd.leaderName') || 'Leader 名称'}
|
||||||
|
name="leaderName"
|
||||||
|
tooltip={t('leaderAdd.leaderNameTooltip') || '可选,用于标识 Leader,方便管理'}
|
||||||
|
>
|
||||||
|
<Input placeholder={t('leaderAdd.leaderNamePlaceholder') || '可选,用于标识 Leader'} />
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
label={t('leaderAdd.remark') || 'Leader 备注'}
|
||||||
|
name="remark"
|
||||||
|
tooltip={t('leaderAdd.remarkTooltip') || '可选,用于记录 Leader 的备注信息'}
|
||||||
|
>
|
||||||
|
<Input.TextArea
|
||||||
|
placeholder={t('leaderAdd.remarkPlaceholder') || '可选,用于记录 Leader 的备注信息'}
|
||||||
|
rows={3}
|
||||||
|
maxLength={500}
|
||||||
|
showCount
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
label={t('leaderAdd.website') || 'Leader 网站'}
|
||||||
|
name="website"
|
||||||
|
tooltip={t('leaderAdd.websiteTooltip') || '可选,Leader 的网站链接'}
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
type: 'url',
|
||||||
|
message: t('leaderAdd.websiteInvalid') || '请输入有效的 URL 地址'
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Input placeholder={t('leaderAdd.websitePlaceholder') || '可选,例如:https://example.com'} />
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item>
|
||||||
|
<Space>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
htmlType="submit"
|
||||||
|
loading={loading}
|
||||||
|
size={isMobile ? 'middle' : 'large'}
|
||||||
|
>
|
||||||
|
{t('leaderAdd.add') || '添加 Leader'}
|
||||||
|
</Button>
|
||||||
|
{showCancelButton && onCancel && (
|
||||||
|
<Button onClick={onCancel}>
|
||||||
|
{t('common.cancel')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LeaderAddForm
|
||||||
|
|
||||||
@@ -65,7 +65,8 @@
|
|||||||
"updateSuccess": "Account updated successfully",
|
"updateSuccess": "Account updated successfully",
|
||||||
"updateFailed": "Failed to update account",
|
"updateFailed": "Failed to update account",
|
||||||
"getDetailFailed": "Failed to get account details",
|
"getDetailFailed": "Failed to get account details",
|
||||||
"accountIdRequired": "Account ID cannot be empty"
|
"accountIdRequired": "Account ID cannot be empty",
|
||||||
|
"proxyAddress": "Proxy Wallet Address"
|
||||||
},
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"success": "Operation successful",
|
"success": "Operation successful",
|
||||||
@@ -426,6 +427,7 @@
|
|||||||
},
|
},
|
||||||
"leaderAdd": {
|
"leaderAdd": {
|
||||||
"title": "Add Leader",
|
"title": "Add Leader",
|
||||||
|
"back": "Back",
|
||||||
"leaderAddress": "Leader Wallet Address",
|
"leaderAddress": "Leader Wallet Address",
|
||||||
"leaderAddressRequired": "Please enter Leader wallet address",
|
"leaderAddressRequired": "Please enter Leader wallet address",
|
||||||
"leaderAddressInvalid": "Invalid wallet address format (must be a 42-character address starting with 0x)",
|
"leaderAddressInvalid": "Invalid wallet address format (must be a 42-character address starting with 0x)",
|
||||||
@@ -667,6 +669,13 @@
|
|||||||
"priceRangeTooltip": "Only copy orders where Leader's trade price is within the specified range. Leave empty to disable. Examples: Fill 0.11 and 0.89 means only copy orders with price between 0.11 and 0.89; Fill only max price 0.89 means only copy orders with price below 0.89; Fill only min price 0.11 means only copy orders with price above 0.11.",
|
"priceRangeTooltip": "Only copy orders where Leader's trade price is within the specified range. Leave empty to disable. Examples: Fill 0.11 and 0.89 means only copy orders with price between 0.11 and 0.89; Fill only max price 0.89 means only copy orders with price below 0.89; Fill only min price 0.11 means only copy orders with price above 0.11.",
|
||||||
"minPricePlaceholder": "Min Price (leave empty for no limit)",
|
"minPricePlaceholder": "Min Price (leave empty for no limit)",
|
||||||
"maxPricePlaceholder": "Max Price (leave empty for no limit)",
|
"maxPricePlaceholder": "Max Price (leave empty for no limit)",
|
||||||
|
"positionLimitFilter": "Max Position Limit",
|
||||||
|
"maxPositionValue": "Max Position Value (USDC)",
|
||||||
|
"maxPositionValueTooltip": "Limit the maximum position value for a single market. If the current position value + copy order amount exceeds this limit, the order will not be placed. Leave empty to disable",
|
||||||
|
"maxPositionValuePlaceholder": "For example: 100 (optional, leave empty to disable)",
|
||||||
|
"maxPositionCount": "Max Position Count",
|
||||||
|
"maxPositionCountTooltip": "Limit the maximum position count for a single market. If the current position count reaches or exceeds this limit, the order will not be placed. Leave empty to disable",
|
||||||
|
"maxPositionCountPlaceholder": "For example: 10 (optional, leave empty to disable)",
|
||||||
"supportSell": "Support Sell",
|
"supportSell": "Support Sell",
|
||||||
"supportSellTooltip": "Whether to copy Leader's sell orders. Enabled: copy both Leader's buy and sell orders; Disabled: only copy Leader's buy orders, ignore sell orders.",
|
"supportSellTooltip": "Whether to copy Leader's sell orders. Enabled: copy both Leader's buy and sell orders; Disabled: only copy Leader's buy orders, ignore sell orders.",
|
||||||
"invalidNumber": "Please enter a valid number"
|
"invalidNumber": "Please enter a valid number"
|
||||||
@@ -732,6 +741,13 @@
|
|||||||
"priceRangeTooltip": "Only copy orders where Leader's trade price is within the specified range. Leave empty to disable. Examples: Fill 0.11 and 0.89 means only copy orders with price between 0.11 and 0.89; Fill only max price 0.89 means only copy orders with price below 0.89; Fill only min price 0.11 means only copy orders with price above 0.11.",
|
"priceRangeTooltip": "Only copy orders where Leader's trade price is within the specified range. Leave empty to disable. Examples: Fill 0.11 and 0.89 means only copy orders with price between 0.11 and 0.89; Fill only max price 0.89 means only copy orders with price below 0.89; Fill only min price 0.11 means only copy orders with price above 0.11.",
|
||||||
"minPricePlaceholder": "Min Price (leave empty for no limit)",
|
"minPricePlaceholder": "Min Price (leave empty for no limit)",
|
||||||
"maxPricePlaceholder": "Max Price (leave empty for no limit)",
|
"maxPricePlaceholder": "Max Price (leave empty for no limit)",
|
||||||
|
"positionLimitFilter": "Max Position Limit",
|
||||||
|
"maxPositionValue": "Max Position Value (USDC)",
|
||||||
|
"maxPositionValueTooltip": "Limit the maximum position value for a single market. If the current position value + copy order amount exceeds this limit, the order will not be placed. Leave empty to disable",
|
||||||
|
"maxPositionValuePlaceholder": "For example: 100 (optional, leave empty to disable)",
|
||||||
|
"maxPositionCount": "Max Position Count",
|
||||||
|
"maxPositionCountTooltip": "Limit the maximum position count for a single market. If the current position count reaches or exceeds this limit, the order will not be placed. Leave empty to disable",
|
||||||
|
"maxPositionCountPlaceholder": "For example: 10 (optional, leave empty to disable)",
|
||||||
"configName": "Configuration Name",
|
"configName": "Configuration Name",
|
||||||
"configNameRequired": "Please enter configuration name",
|
"configNameRequired": "Please enter configuration name",
|
||||||
"configNamePlaceholder": "e.g., Copy Trading Config 1",
|
"configNamePlaceholder": "e.g., Copy Trading Config 1",
|
||||||
@@ -752,7 +768,11 @@
|
|||||||
"invalidNumber": "Please enter a valid number",
|
"invalidNumber": "Please enter a valid number",
|
||||||
"fetchLeaderFailed": "Failed to get Leader list",
|
"fetchLeaderFailed": "Failed to get Leader list",
|
||||||
"fetchTemplateFailed": "Failed to get template list",
|
"fetchTemplateFailed": "Failed to get template list",
|
||||||
"templateName": "Template Name"
|
"templateName": "Template Name",
|
||||||
|
"noAccounts": "No accounts",
|
||||||
|
"importAccount": "Import Account",
|
||||||
|
"noLeaders": "No Leaders",
|
||||||
|
"addLeader": "Add Leader"
|
||||||
},
|
},
|
||||||
"copyTradingEdit": {
|
"copyTradingEdit": {
|
||||||
"title": "Edit Copy Trading Config",
|
"title": "Edit Copy Trading Config",
|
||||||
@@ -807,6 +827,13 @@
|
|||||||
"priceRangeTooltip": "Only copy orders where Leader's trade price is within the specified range. Leave empty to disable. Examples: Fill 0.11 and 0.89 means only copy orders with price between 0.11 and 0.89; Fill only max price 0.89 means only copy orders with price below 0.89; Fill only min price 0.11 means only copy orders with price above 0.11.",
|
"priceRangeTooltip": "Only copy orders where Leader's trade price is within the specified range. Leave empty to disable. Examples: Fill 0.11 and 0.89 means only copy orders with price between 0.11 and 0.89; Fill only max price 0.89 means only copy orders with price below 0.89; Fill only min price 0.11 means only copy orders with price above 0.11.",
|
||||||
"minPricePlaceholder": "Min Price (leave empty for no limit)",
|
"minPricePlaceholder": "Min Price (leave empty for no limit)",
|
||||||
"maxPricePlaceholder": "Max Price (leave empty for no limit)",
|
"maxPricePlaceholder": "Max Price (leave empty for no limit)",
|
||||||
|
"positionLimitFilter": "Max Position Limit",
|
||||||
|
"maxPositionValue": "Max Position Value (USDC)",
|
||||||
|
"maxPositionValueTooltip": "Limit the maximum position value for a single market. If the current position value + copy order amount exceeds this limit, the order will not be placed. Leave empty to disable",
|
||||||
|
"maxPositionValuePlaceholder": "For example: 100 (optional, leave empty to disable)",
|
||||||
|
"maxPositionCount": "Max Position Count",
|
||||||
|
"maxPositionCountTooltip": "Limit the maximum position count for a single market. If the current position count reaches or exceeds this limit, the order will not be placed. Leave empty to disable",
|
||||||
|
"maxPositionCountPlaceholder": "For example: 10 (optional, leave empty to disable)",
|
||||||
"configName": "Configuration Name",
|
"configName": "Configuration Name",
|
||||||
"configNameRequired": "Please enter configuration name",
|
"configNameRequired": "Please enter configuration name",
|
||||||
"configNamePlaceholder": "e.g., Copy Trading Config 1",
|
"configNamePlaceholder": "e.g., Copy Trading Config 1",
|
||||||
@@ -849,6 +876,8 @@
|
|||||||
"orderbookError": "Orderbook Fetch Failed",
|
"orderbookError": "Orderbook Fetch Failed",
|
||||||
"orderbookEmpty": "Orderbook Empty",
|
"orderbookEmpty": "Orderbook Empty",
|
||||||
"priceRange": "Price Range Mismatch",
|
"priceRange": "Price Range Mismatch",
|
||||||
|
"maxPositionValue": "Exceeds Max Position Value",
|
||||||
|
"maxPositionCount": "Exceeds Max Position Count",
|
||||||
"unknown": "Unknown Reason"
|
"unknown": "Unknown Reason"
|
||||||
},
|
},
|
||||||
"noData": "No filtered orders"
|
"noData": "No filtered orders"
|
||||||
@@ -856,6 +885,8 @@
|
|||||||
"copyTradingList": {
|
"copyTradingList": {
|
||||||
"title": "Copy Trading Config Management",
|
"title": "Copy Trading Config Management",
|
||||||
"addCopyTrading": "Add Copy Trading",
|
"addCopyTrading": "Add Copy Trading",
|
||||||
|
"configName": "Config Name",
|
||||||
|
"configNameNotProvided": "Not Provided",
|
||||||
"wallet": "Wallet",
|
"wallet": "Wallet",
|
||||||
"account": "Account",
|
"account": "Account",
|
||||||
"template": "Template",
|
"template": "Template",
|
||||||
|
|||||||
@@ -27,7 +27,10 @@
|
|||||||
"total": "共",
|
"total": "共",
|
||||||
"items": "条",
|
"items": "条",
|
||||||
"prev": "上一页",
|
"prev": "上一页",
|
||||||
"next": "下一页"
|
"next": "下一页",
|
||||||
|
"success": "成功",
|
||||||
|
"failed": "失败",
|
||||||
|
"close": "关闭"
|
||||||
},
|
},
|
||||||
"login": {
|
"login": {
|
||||||
"title": "登录",
|
"title": "登录",
|
||||||
@@ -45,7 +48,13 @@
|
|||||||
"success": "操作成功",
|
"success": "操作成功",
|
||||||
"error": "操作失败",
|
"error": "操作失败",
|
||||||
"loading": "加载中...",
|
"loading": "加载中...",
|
||||||
"noData": "暂无数据"
|
"noData": "暂无数据",
|
||||||
|
"loginSuccess": "登录成功",
|
||||||
|
"loginFailed": "登录失败",
|
||||||
|
"createUserSuccess": "创建用户成功",
|
||||||
|
"createUserFailed": "创建用户失败",
|
||||||
|
"updatePasswordSuccess": "更新密码成功",
|
||||||
|
"updatePasswordFailed": "更新密码失败"
|
||||||
},
|
},
|
||||||
"order": {
|
"order": {
|
||||||
"create": "创建订单",
|
"create": "创建订单",
|
||||||
@@ -53,7 +62,47 @@
|
|||||||
"cancel": "取消订单",
|
"cancel": "取消订单",
|
||||||
"event": "订单事件",
|
"event": "订单事件",
|
||||||
"buy": "买入",
|
"buy": "买入",
|
||||||
"sell": "卖出"
|
"sell": "卖出",
|
||||||
|
"market": "市场",
|
||||||
|
"status": "状态",
|
||||||
|
"filled": "已成交",
|
||||||
|
"remaining": "剩余"
|
||||||
|
},
|
||||||
|
"account": {
|
||||||
|
"title": "账户管理",
|
||||||
|
"list": "账户列表",
|
||||||
|
"detail": "账户详情",
|
||||||
|
"import": "导入账户",
|
||||||
|
"update": "更新账户",
|
||||||
|
"delete": "删除账户",
|
||||||
|
"accountId": "账户ID",
|
||||||
|
"accountName": "账户名称",
|
||||||
|
"accountNamePlaceholder": "账户名称(可选)",
|
||||||
|
"accountIdRequired": "账户ID不能为空",
|
||||||
|
"walletAddress": "钱包地址",
|
||||||
|
"proxyAddress": "代理钱包地址",
|
||||||
|
"apiCredentials": "API 凭证",
|
||||||
|
"apiKey": "API Key",
|
||||||
|
"apiSecret": "API Secret",
|
||||||
|
"apiPassphrase": "API Passphrase",
|
||||||
|
"balance": "余额",
|
||||||
|
"activeOrders": "活跃订单",
|
||||||
|
"completedOrders": "已完成订单",
|
||||||
|
"positionCount": "持仓数量",
|
||||||
|
"totalOrders": "总订单数",
|
||||||
|
"totalPnl": "总盈亏",
|
||||||
|
"statistics": "交易统计",
|
||||||
|
"fullConfig": "完整配置",
|
||||||
|
"partialConfig": "部分配置",
|
||||||
|
"notConfigured": "未配置",
|
||||||
|
"configured": "已配置",
|
||||||
|
"editTip": "编辑提示",
|
||||||
|
"editTipDesc": "API 凭证字段留空表示不修改。如需更新 API 凭证,请输入新值;如需保持原值不变,请留空。",
|
||||||
|
"leaveEmptyToNotModify": "留空表示不修改",
|
||||||
|
"getDetailFailed": "获取账户详情失败",
|
||||||
|
"updateSuccess": "更新账户成功",
|
||||||
|
"updateFailed": "更新账户失败",
|
||||||
|
"refreshBalance": "刷新余额"
|
||||||
},
|
},
|
||||||
"accountList": {
|
"accountList": {
|
||||||
"title": "账户管理",
|
"title": "账户管理",
|
||||||
@@ -117,28 +166,63 @@
|
|||||||
},
|
},
|
||||||
"accountImport": {
|
"accountImport": {
|
||||||
"title": "导入账户",
|
"title": "导入账户",
|
||||||
|
"back": "返回",
|
||||||
|
"securityTip": "安全提示",
|
||||||
|
"securityTipDesc": "私钥将存储在后端数据库中,请确保数据库访问安全。建议使用 HTTPS 连接。",
|
||||||
|
"importMethod": "导入方式",
|
||||||
"privateKey": "私钥",
|
"privateKey": "私钥",
|
||||||
|
"mnemonic": "助记词",
|
||||||
|
"privateKeyLabel": "私钥",
|
||||||
|
"privateKeyPlaceholder": "请输入私钥(64位十六进制字符串,可选0x前缀)",
|
||||||
"privateKeyRequired": "请输入私钥",
|
"privateKeyRequired": "请输入私钥",
|
||||||
"privateKeyPlaceholder": "请输入或粘贴私钥",
|
"privateKeyInvalid": "私钥格式不正确(应为64位十六进制字符串)",
|
||||||
"privateKeyHelp": "私钥将加密存储,仅用于签名交易",
|
"walletAddress": "钱包地址",
|
||||||
|
"walletAddressPlaceholder": "钱包地址(将从私钥自动推导)",
|
||||||
|
"walletAddressRequired": "请输入钱包地址",
|
||||||
|
"walletAddressInvalid": "钱包地址格式不正确",
|
||||||
|
"walletAddressMismatch": "钱包地址与私钥不匹配",
|
||||||
|
"mnemonicLabel": "助记词",
|
||||||
|
"mnemonicPlaceholder": "请输入12或24个单词的助记词(用空格分隔)",
|
||||||
|
"mnemonicRequired": "请输入助记词",
|
||||||
|
"mnemonicInvalid": "助记词格式不正确(应为12或24个单词,用空格分隔)",
|
||||||
|
"walletAddressMismatchMnemonic": "钱包地址与助记词不匹配",
|
||||||
"accountName": "账户名称",
|
"accountName": "账户名称",
|
||||||
"accountNameRequired": "请输入账户名称",
|
"accountNameRequired": "请输入账户名称",
|
||||||
"accountNamePlaceholder": "请输入账户名称",
|
"accountNamePlaceholder": "可选,用于标识账户",
|
||||||
"accountNameHelp": "用于标识账户,便于管理",
|
"accountNameHelp": "用于标识账户,便于管理",
|
||||||
|
"privateKeyHelp": "私钥将加密存储,仅用于签名交易",
|
||||||
"submit": "导入",
|
"submit": "导入",
|
||||||
|
"invalidPrivateKey": "无效的私钥",
|
||||||
|
"duplicateAccount": "账户已存在",
|
||||||
|
"importAccount": "导入账户",
|
||||||
"importSuccess": "导入账户成功",
|
"importSuccess": "导入账户成功",
|
||||||
"importFailed": "导入账户失败",
|
"importFailed": "导入账户失败",
|
||||||
"invalidPrivateKey": "无效的私钥",
|
"derivedAddress": "推导地址",
|
||||||
"duplicateAccount": "账户已存在"
|
"addressError": "无法从私钥推导地址",
|
||||||
|
"addressErrorMnemonic": "无法从助记词推导地址"
|
||||||
},
|
},
|
||||||
"leader": {
|
"leader": {
|
||||||
"title": "Leader 管理",
|
"title": "Leader 管理",
|
||||||
"leaderName": "Leader 名称",
|
"leaderName": "Leader 名称",
|
||||||
"leaderAddress": "钱包地址",
|
"leaderAddress": "钱包地址",
|
||||||
|
"walletAddress": "钱包地址",
|
||||||
"category": "分类",
|
"category": "分类",
|
||||||
|
"all": "全部",
|
||||||
|
"copyTradingCount": "跟单关系数",
|
||||||
|
"createdAt": "创建时间",
|
||||||
|
"action": "操作",
|
||||||
|
"add": "添加",
|
||||||
"addLeader": "添加 Leader",
|
"addLeader": "添加 Leader",
|
||||||
|
"edit": "编辑",
|
||||||
"editLeader": "编辑 Leader",
|
"editLeader": "编辑 Leader",
|
||||||
"deleteLeader": "删除 Leader"
|
"delete": "删除",
|
||||||
|
"deleteLeader": "删除 Leader",
|
||||||
|
"listFailed": "获取 Leader 列表失败",
|
||||||
|
"deleteSuccess": "删除 Leader 成功",
|
||||||
|
"deleteFailed": "删除 Leader 失败",
|
||||||
|
"deleteConfirm": "确定要删除这个 Leader 吗?",
|
||||||
|
"deleteConfirmDesc": "删除后无法恢复,请谨慎操作!",
|
||||||
|
"deleteConfirmOk": "确定删除"
|
||||||
},
|
},
|
||||||
"menu": {
|
"menu": {
|
||||||
"accounts": "账户管理",
|
"accounts": "账户管理",
|
||||||
@@ -197,7 +281,9 @@
|
|||||||
"saveSuccess": "保存配置成功",
|
"saveSuccess": "保存配置成功",
|
||||||
"saveFailed": "保存配置失败",
|
"saveFailed": "保存配置失败",
|
||||||
"getFailed": "获取代理配置失败",
|
"getFailed": "获取代理配置失败",
|
||||||
"latency": "延迟"
|
"latency": "延迟",
|
||||||
|
"hostInvalid": "请输入有效的主机地址",
|
||||||
|
"portInvalid": "端口必须在 1-65535 之间"
|
||||||
},
|
},
|
||||||
"languageSettings": {
|
"languageSettings": {
|
||||||
"title": "语言设置",
|
"title": "语言设置",
|
||||||
@@ -341,6 +427,7 @@
|
|||||||
},
|
},
|
||||||
"leaderAdd": {
|
"leaderAdd": {
|
||||||
"title": "添加 Leader",
|
"title": "添加 Leader",
|
||||||
|
"back": "返回",
|
||||||
"leaderAddress": "Leader 钱包地址",
|
"leaderAddress": "Leader 钱包地址",
|
||||||
"leaderAddressRequired": "请输入 Leader 钱包地址",
|
"leaderAddressRequired": "请输入 Leader 钱包地址",
|
||||||
"leaderAddressInvalid": "钱包地址格式不正确(必须是 0x 开头的 42 位地址)",
|
"leaderAddressInvalid": "钱包地址格式不正确(必须是 0x 开头的 42 位地址)",
|
||||||
@@ -582,6 +669,13 @@
|
|||||||
"priceRangeTooltip": "仅跟单 Leader 交易价格在指定区间内的订单。不填写表示不限制。示例:填写 0.11 和 0.89 表示仅跟单价格在 0.11 到 0.89 之间的订单;只填写最高价 0.89 表示仅跟单价格在 0.89 以下的订单;只填写最低价 0.11 表示仅跟单价格在 0.11 以上的订单。",
|
"priceRangeTooltip": "仅跟单 Leader 交易价格在指定区间内的订单。不填写表示不限制。示例:填写 0.11 和 0.89 表示仅跟单价格在 0.11 到 0.89 之间的订单;只填写最高价 0.89 表示仅跟单价格在 0.89 以下的订单;只填写最低价 0.11 表示仅跟单价格在 0.11 以上的订单。",
|
||||||
"minPricePlaceholder": "最低价(留空不限制)",
|
"minPricePlaceholder": "最低价(留空不限制)",
|
||||||
"maxPricePlaceholder": "最高价(留空不限制)",
|
"maxPricePlaceholder": "最高价(留空不限制)",
|
||||||
|
"positionLimitFilter": "最大仓位限制",
|
||||||
|
"maxPositionValue": "最大仓位金额 (USDC)",
|
||||||
|
"maxPositionValueTooltip": "限制单个市场的最大仓位金额。如果该市场的当前仓位金额 + 跟单金额超过此限制,则不会下单。不填写则不启用此限制",
|
||||||
|
"maxPositionValuePlaceholder": "例如:100(可选,不填写表示不启用)",
|
||||||
|
"maxPositionCount": "最大仓位数量",
|
||||||
|
"maxPositionCountTooltip": "限制单个市场的最大仓位数量。如果该市场的当前仓位数量达到或超过此限制,则不会下单。不填写则不启用此限制",
|
||||||
|
"maxPositionCountPlaceholder": "例如:10(可选,不填写表示不启用)",
|
||||||
"supportSell": "跟单卖出",
|
"supportSell": "跟单卖出",
|
||||||
"supportSellTooltip": "是否跟单 Leader 的卖出订单。开启:跟单 Leader 的买入和卖出订单;关闭:只跟单 Leader 的买入订单,忽略卖出订单。",
|
"supportSellTooltip": "是否跟单 Leader 的卖出订单。开启:跟单 Leader 的买入和卖出订单;关闭:只跟单 Leader 的买入订单,忽略卖出订单。",
|
||||||
"invalidNumber": "请输入有效的数字"
|
"invalidNumber": "请输入有效的数字"
|
||||||
@@ -659,6 +753,13 @@
|
|||||||
"priceRangeTooltip": "仅跟单 Leader 交易价格在指定区间内的订单。不填写表示不限制。示例:填写 0.11 和 0.89 表示仅跟单价格在 0.11 到 0.89 之间的订单;只填写最高价 0.89 表示仅跟单价格在 0.89 以下的订单;只填写最低价 0.11 表示仅跟单价格在 0.11 以上的订单。",
|
"priceRangeTooltip": "仅跟单 Leader 交易价格在指定区间内的订单。不填写表示不限制。示例:填写 0.11 和 0.89 表示仅跟单价格在 0.11 到 0.89 之间的订单;只填写最高价 0.89 表示仅跟单价格在 0.89 以下的订单;只填写最低价 0.11 表示仅跟单价格在 0.11 以上的订单。",
|
||||||
"minPricePlaceholder": "最低价(留空不限制)",
|
"minPricePlaceholder": "最低价(留空不限制)",
|
||||||
"maxPricePlaceholder": "最高价(留空不限制)",
|
"maxPricePlaceholder": "最高价(留空不限制)",
|
||||||
|
"positionLimitFilter": "最大仓位限制",
|
||||||
|
"maxPositionValue": "最大仓位金额 (USDC)",
|
||||||
|
"maxPositionValueTooltip": "限制单个市场的最大仓位金额。如果该市场的当前仓位金额 + 跟单金额超过此限制,则不会下单。不填写则不启用此限制",
|
||||||
|
"maxPositionValuePlaceholder": "例如:100(可选,不填写表示不启用)",
|
||||||
|
"maxPositionCount": "最大仓位数量",
|
||||||
|
"maxPositionCountTooltip": "限制单个市场的最大仓位数量。如果该市场的当前仓位数量达到或超过此限制,则不会下单。不填写则不启用此限制",
|
||||||
|
"maxPositionCountPlaceholder": "例如:10(可选,不填写表示不启用)",
|
||||||
"supportSell": "跟单卖出",
|
"supportSell": "跟单卖出",
|
||||||
"supportSellTooltip": "是否跟单 Leader 的卖出订单",
|
"supportSellTooltip": "是否跟单 Leader 的卖出订单",
|
||||||
"create": "创建跟单配置",
|
"create": "创建跟单配置",
|
||||||
@@ -667,7 +768,11 @@
|
|||||||
"invalidNumber": "请输入有效的数字",
|
"invalidNumber": "请输入有效的数字",
|
||||||
"fetchLeaderFailed": "获取 Leader 列表失败",
|
"fetchLeaderFailed": "获取 Leader 列表失败",
|
||||||
"fetchTemplateFailed": "获取模板列表失败",
|
"fetchTemplateFailed": "获取模板列表失败",
|
||||||
"templateName": "模板名称"
|
"templateName": "模板名称",
|
||||||
|
"noAccounts": "暂无账户",
|
||||||
|
"importAccount": "导入账户",
|
||||||
|
"noLeaders": "暂无 Leader",
|
||||||
|
"addLeader": "添加 Leader"
|
||||||
},
|
},
|
||||||
"copyTradingEdit": {
|
"copyTradingEdit": {
|
||||||
"title": "编辑跟单配置",
|
"title": "编辑跟单配置",
|
||||||
@@ -734,6 +839,13 @@
|
|||||||
"priceRangeTooltip": "仅跟单 Leader 交易价格在指定区间内的订单。不填写表示不限制。示例:填写 0.11 和 0.89 表示仅跟单价格在 0.11 到 0.89 之间的订单;只填写最高价 0.89 表示仅跟单价格在 0.89 以下的订单;只填写最低价 0.11 表示仅跟单价格在 0.11 以上的订单。",
|
"priceRangeTooltip": "仅跟单 Leader 交易价格在指定区间内的订单。不填写表示不限制。示例:填写 0.11 和 0.89 表示仅跟单价格在 0.11 到 0.89 之间的订单;只填写最高价 0.89 表示仅跟单价格在 0.89 以下的订单;只填写最低价 0.11 表示仅跟单价格在 0.11 以上的订单。",
|
||||||
"minPricePlaceholder": "最低价(留空不限制)",
|
"minPricePlaceholder": "最低价(留空不限制)",
|
||||||
"maxPricePlaceholder": "最高价(留空不限制)",
|
"maxPricePlaceholder": "最高价(留空不限制)",
|
||||||
|
"positionLimitFilter": "最大仓位限制",
|
||||||
|
"maxPositionValue": "最大仓位金额 (USDC)",
|
||||||
|
"maxPositionValueTooltip": "限制单个市场的最大仓位金额。如果该市场的当前仓位金额 + 跟单金额超过此限制,则不会下单。不填写则不启用此限制",
|
||||||
|
"maxPositionValuePlaceholder": "例如:100(可选,不填写表示不启用)",
|
||||||
|
"maxPositionCount": "最大仓位数量",
|
||||||
|
"maxPositionCountTooltip": "限制单个市场的最大仓位数量。如果该市场的当前仓位数量达到或超过此限制,则不会下单。不填写则不启用此限制",
|
||||||
|
"maxPositionCountPlaceholder": "例如:10(可选,不填写表示不启用)",
|
||||||
"supportSell": "跟单卖出",
|
"supportSell": "跟单卖出",
|
||||||
"supportSellTooltip": "是否跟单 Leader 的卖出订单",
|
"supportSellTooltip": "是否跟单 Leader 的卖出订单",
|
||||||
"save": "保存",
|
"save": "保存",
|
||||||
@@ -764,6 +876,8 @@
|
|||||||
"orderbookError": "订单簿获取失败",
|
"orderbookError": "订单簿获取失败",
|
||||||
"orderbookEmpty": "订单簿为空",
|
"orderbookEmpty": "订单簿为空",
|
||||||
"priceRange": "价格区间不符",
|
"priceRange": "价格区间不符",
|
||||||
|
"maxPositionValue": "超过最大仓位金额",
|
||||||
|
"maxPositionCount": "超过最大仓位数量",
|
||||||
"unknown": "未知原因"
|
"unknown": "未知原因"
|
||||||
},
|
},
|
||||||
"noData": "暂无已过滤订单"
|
"noData": "暂无已过滤订单"
|
||||||
|
|||||||
@@ -65,7 +65,8 @@
|
|||||||
"updateSuccess": "更新賬戶成功",
|
"updateSuccess": "更新賬戶成功",
|
||||||
"updateFailed": "更新賬戶失敗",
|
"updateFailed": "更新賬戶失敗",
|
||||||
"getDetailFailed": "獲取賬戶詳情失敗",
|
"getDetailFailed": "獲取賬戶詳情失敗",
|
||||||
"accountIdRequired": "賬戶ID不能為空"
|
"accountIdRequired": "賬戶ID不能為空",
|
||||||
|
"proxyAddress": "代理錢包地址"
|
||||||
},
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"success": "操作成功",
|
"success": "操作成功",
|
||||||
@@ -426,6 +427,7 @@
|
|||||||
},
|
},
|
||||||
"leaderAdd": {
|
"leaderAdd": {
|
||||||
"title": "添加 Leader",
|
"title": "添加 Leader",
|
||||||
|
"back": "返回",
|
||||||
"leaderAddress": "Leader 錢包地址",
|
"leaderAddress": "Leader 錢包地址",
|
||||||
"leaderAddressRequired": "請輸入 Leader 錢包地址",
|
"leaderAddressRequired": "請輸入 Leader 錢包地址",
|
||||||
"leaderAddressInvalid": "錢包地址格式不正確(必須是 0x 開頭的 42 位地址)",
|
"leaderAddressInvalid": "錢包地址格式不正確(必須是 0x 開頭的 42 位地址)",
|
||||||
@@ -667,6 +669,13 @@
|
|||||||
"priceRangeTooltip": "僅跟單 Leader 交易價格在指定區間內的訂單。不填寫表示不限制。示例:填寫 0.11 和 0.89 表示僅跟單價格在 0.11 到 0.89 之間的訂單;只填寫最高價 0.89 表示僅跟單價格在 0.89 以下的訂單;只填寫最低價 0.11 表示僅跟單價格在 0.11 以上的訂單。",
|
"priceRangeTooltip": "僅跟單 Leader 交易價格在指定區間內的訂單。不填寫表示不限制。示例:填寫 0.11 和 0.89 表示僅跟單價格在 0.11 到 0.89 之間的訂單;只填寫最高價 0.89 表示僅跟單價格在 0.89 以下的訂單;只填寫最低價 0.11 表示僅跟單價格在 0.11 以上的訂單。",
|
||||||
"minPricePlaceholder": "最低價(留空不限制)",
|
"minPricePlaceholder": "最低價(留空不限制)",
|
||||||
"maxPricePlaceholder": "最高價(留空不限制)",
|
"maxPricePlaceholder": "最高價(留空不限制)",
|
||||||
|
"positionLimitFilter": "最大倉位限制",
|
||||||
|
"maxPositionValue": "最大倉位金額 (USDC)",
|
||||||
|
"maxPositionValueTooltip": "限制單個市場的最大倉位金額。如果該市場的當前倉位金額 + 跟單金額超過此限制,則不會下單。不填寫則不啟用此限制",
|
||||||
|
"maxPositionValuePlaceholder": "例如:100(可選,不填寫表示不啟用)",
|
||||||
|
"maxPositionCount": "最大倉位數量",
|
||||||
|
"maxPositionCountTooltip": "限制單個市場的最大倉位數量。如果該市場的當前倉位數量達到或超過此限制,則不會下單。不填寫則不啟用此限制",
|
||||||
|
"maxPositionCountPlaceholder": "例如:10(可選,不填寫表示不啟用)",
|
||||||
"supportSell": "跟單賣出",
|
"supportSell": "跟單賣出",
|
||||||
"supportSellTooltip": "是否跟單 Leader 的賣出訂單。開啟:跟單 Leader 的買入和賣出訂單;關閉:只跟單 Leader 的買入訂單,忽略賣出訂單。",
|
"supportSellTooltip": "是否跟單 Leader 的賣出訂單。開啟:跟單 Leader 的買入和賣出訂單;關閉:只跟單 Leader 的買入訂單,忽略賣出訂單。",
|
||||||
"invalidNumber": "請輸入有效的數字"
|
"invalidNumber": "請輸入有效的數字"
|
||||||
@@ -732,6 +741,13 @@
|
|||||||
"priceRangeTooltip": "僅跟單 Leader 交易價格在指定區間內的訂單。不填寫表示不限制。示例:填寫 0.11 和 0.89 表示僅跟單價格在 0.11 到 0.89 之間的訂單;只填寫最高價 0.89 表示僅跟單價格在 0.89 以下的訂單;只填寫最低價 0.11 表示僅跟單價格在 0.11 以上的訂單。",
|
"priceRangeTooltip": "僅跟單 Leader 交易價格在指定區間內的訂單。不填寫表示不限制。示例:填寫 0.11 和 0.89 表示僅跟單價格在 0.11 到 0.89 之間的訂單;只填寫最高價 0.89 表示僅跟單價格在 0.89 以下的訂單;只填寫最低價 0.11 表示僅跟單價格在 0.11 以上的訂單。",
|
||||||
"minPricePlaceholder": "最低價(留空不限制)",
|
"minPricePlaceholder": "最低價(留空不限制)",
|
||||||
"maxPricePlaceholder": "最高價(留空不限制)",
|
"maxPricePlaceholder": "最高價(留空不限制)",
|
||||||
|
"positionLimitFilter": "最大倉位限制",
|
||||||
|
"maxPositionValue": "最大倉位金額 (USDC)",
|
||||||
|
"maxPositionValueTooltip": "限制單個市場的最大倉位金額。如果該市場的當前倉位金額 + 跟單金額超過此限制,則不會下單。不填寫則不啟用此限制",
|
||||||
|
"maxPositionValuePlaceholder": "例如:100(可選,不填寫表示不啟用)",
|
||||||
|
"maxPositionCount": "最大倉位數量",
|
||||||
|
"maxPositionCountTooltip": "限制單個市場的最大倉位數量。如果該市場的當前倉位數量達到或超過此限制,則不會下單。不填寫則不啟用此限制",
|
||||||
|
"maxPositionCountPlaceholder": "例如:10(可選,不填寫表示不啟用)",
|
||||||
"configName": "配置名",
|
"configName": "配置名",
|
||||||
"configNameRequired": "請輸入配置名",
|
"configNameRequired": "請輸入配置名",
|
||||||
"configNamePlaceholder": "例如:跟單配置1",
|
"configNamePlaceholder": "例如:跟單配置1",
|
||||||
@@ -752,7 +768,11 @@
|
|||||||
"invalidNumber": "請輸入有效的數字",
|
"invalidNumber": "請輸入有效的數字",
|
||||||
"fetchLeaderFailed": "獲取 Leader 列表失敗",
|
"fetchLeaderFailed": "獲取 Leader 列表失敗",
|
||||||
"fetchTemplateFailed": "獲取模板列表失敗",
|
"fetchTemplateFailed": "獲取模板列表失敗",
|
||||||
"templateName": "模板名稱"
|
"templateName": "模板名稱",
|
||||||
|
"noAccounts": "暫無賬戶",
|
||||||
|
"importAccount": "導入賬戶",
|
||||||
|
"noLeaders": "暫無 Leader",
|
||||||
|
"addLeader": "添加 Leader"
|
||||||
},
|
},
|
||||||
"copyTradingEdit": {
|
"copyTradingEdit": {
|
||||||
"title": "編輯跟單配置",
|
"title": "編輯跟單配置",
|
||||||
@@ -807,6 +827,13 @@
|
|||||||
"priceRangeTooltip": "僅跟單 Leader 交易價格在指定區間內的訂單。不填寫表示不限制。示例:填寫 0.11 和 0.89 表示僅跟單價格在 0.11 到 0.89 之間的訂單;只填寫最高價 0.89 表示僅跟單價格在 0.89 以下的訂單;只填寫最低價 0.11 表示僅跟單價格在 0.11 以上的訂單。",
|
"priceRangeTooltip": "僅跟單 Leader 交易價格在指定區間內的訂單。不填寫表示不限制。示例:填寫 0.11 和 0.89 表示僅跟單價格在 0.11 到 0.89 之間的訂單;只填寫最高價 0.89 表示僅跟單價格在 0.89 以下的訂單;只填寫最低價 0.11 表示僅跟單價格在 0.11 以上的訂單。",
|
||||||
"minPricePlaceholder": "最低價(留空不限制)",
|
"minPricePlaceholder": "最低價(留空不限制)",
|
||||||
"maxPricePlaceholder": "最高價(留空不限制)",
|
"maxPricePlaceholder": "最高價(留空不限制)",
|
||||||
|
"positionLimitFilter": "最大倉位限制",
|
||||||
|
"maxPositionValue": "最大倉位金額 (USDC)",
|
||||||
|
"maxPositionValueTooltip": "限制單個市場的最大倉位金額。如果該市場的當前倉位金額 + 跟單金額超過此限制,則不會下單。不填寫則不啟用此限制",
|
||||||
|
"maxPositionValuePlaceholder": "例如:100(可選,不填寫表示不啟用)",
|
||||||
|
"maxPositionCount": "最大倉位數量",
|
||||||
|
"maxPositionCountTooltip": "限制單個市場的最大倉位數量。如果該市場的當前倉位數量達到或超過此限制,則不會下單。不填寫則不啟用此限制",
|
||||||
|
"maxPositionCountPlaceholder": "例如:10(可選,不填寫表示不啟用)",
|
||||||
"configName": "配置名",
|
"configName": "配置名",
|
||||||
"configNameRequired": "請輸入配置名",
|
"configNameRequired": "請輸入配置名",
|
||||||
"configNamePlaceholder": "例如:跟單配置1",
|
"configNamePlaceholder": "例如:跟單配置1",
|
||||||
@@ -849,6 +876,8 @@
|
|||||||
"orderbookError": "訂單簿獲取失敗",
|
"orderbookError": "訂單簿獲取失敗",
|
||||||
"orderbookEmpty": "訂單簿為空",
|
"orderbookEmpty": "訂單簿為空",
|
||||||
"priceRange": "價格區間不符",
|
"priceRange": "價格區間不符",
|
||||||
|
"maxPositionValue": "超過最大倉位金額",
|
||||||
|
"maxPositionCount": "超過最大倉位數量",
|
||||||
"unknown": "未知原因"
|
"unknown": "未知原因"
|
||||||
},
|
},
|
||||||
"noData": "暫無已過濾訂單"
|
"noData": "暫無已過濾訂單"
|
||||||
@@ -856,6 +885,8 @@
|
|||||||
"copyTradingList": {
|
"copyTradingList": {
|
||||||
"title": "跟單配置管理",
|
"title": "跟單配置管理",
|
||||||
"addCopyTrading": "新增跟單",
|
"addCopyTrading": "新增跟單",
|
||||||
|
"configName": "配置名",
|
||||||
|
"configNameNotProvided": "未提供",
|
||||||
"wallet": "錢包",
|
"wallet": "錢包",
|
||||||
"account": "賬戶",
|
"account": "賬戶",
|
||||||
"template": "模板",
|
"template": "模板",
|
||||||
|
|||||||
@@ -1,150 +1,20 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { Card, Form, Input, Button, message, Typography, Radio, Space, Alert } from 'antd'
|
import { Card, Form, Button, Typography } from 'antd'
|
||||||
import { ArrowLeftOutlined } from '@ant-design/icons'
|
import { ArrowLeftOutlined } from '@ant-design/icons'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useAccountStore } from '../store/accountStore'
|
import { message } from 'antd'
|
||||||
import {
|
import AccountImportForm from '../components/AccountImportForm'
|
||||||
getAddressFromPrivateKey,
|
|
||||||
getAddressFromMnemonic,
|
|
||||||
getPrivateKeyFromMnemonic,
|
|
||||||
isValidWalletAddress,
|
|
||||||
isValidPrivateKey,
|
|
||||||
isValidMnemonic
|
|
||||||
} from '../utils'
|
|
||||||
import { useMediaQuery } from 'react-responsive'
|
|
||||||
|
|
||||||
const { Title } = Typography
|
const { Title } = Typography
|
||||||
|
|
||||||
type ImportType = 'privateKey' | 'mnemonic'
|
|
||||||
|
|
||||||
const AccountImport: React.FC = () => {
|
const AccountImport: React.FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const isMobile = useMediaQuery({ maxWidth: 768 })
|
|
||||||
const { importAccount, loading } = useAccountStore()
|
|
||||||
const [form] = Form.useForm()
|
const [form] = Form.useForm()
|
||||||
const [importType, setImportType] = useState<ImportType>('privateKey')
|
|
||||||
const [derivedAddress, setDerivedAddress] = useState<string>('')
|
|
||||||
const [addressError, setAddressError] = useState<string>('')
|
|
||||||
|
|
||||||
// 当私钥输入时,自动推导地址
|
const handleSuccess = async () => {
|
||||||
const handlePrivateKeyChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
message.success(t('accountImport.importSuccess'))
|
||||||
const privateKey = e.target.value.trim()
|
navigate('/accounts')
|
||||||
if (!privateKey) {
|
|
||||||
setDerivedAddress('')
|
|
||||||
setAddressError('')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证私钥格式
|
|
||||||
if (!isValidPrivateKey(privateKey)) {
|
|
||||||
setAddressError(t('accountImport.privateKeyInvalid'))
|
|
||||||
setDerivedAddress('')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const address = getAddressFromPrivateKey(privateKey)
|
|
||||||
setDerivedAddress(address)
|
|
||||||
setAddressError('')
|
|
||||||
|
|
||||||
// 自动填充钱包地址字段
|
|
||||||
form.setFieldsValue({ walletAddress: address })
|
|
||||||
} catch (error: any) {
|
|
||||||
setAddressError(error.message || t('accountImport.addressError'))
|
|
||||||
setDerivedAddress('')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 当助记词输入时,自动推导地址
|
|
||||||
const handleMnemonicChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
||||||
const mnemonic = e.target.value.trim()
|
|
||||||
if (!mnemonic) {
|
|
||||||
setDerivedAddress('')
|
|
||||||
setAddressError('')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证助记词格式
|
|
||||||
if (!isValidMnemonic(mnemonic)) {
|
|
||||||
setAddressError(t('accountImport.mnemonicInvalid'))
|
|
||||||
setDerivedAddress('')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const address = getAddressFromMnemonic(mnemonic, 0)
|
|
||||||
setDerivedAddress(address)
|
|
||||||
setAddressError('')
|
|
||||||
|
|
||||||
// 自动填充钱包地址字段
|
|
||||||
form.setFieldsValue({ walletAddress: address })
|
|
||||||
} catch (error: any) {
|
|
||||||
setAddressError(error.message || t('accountImport.addressErrorMnemonic'))
|
|
||||||
setDerivedAddress('')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSubmit = async (values: any) => {
|
|
||||||
try {
|
|
||||||
let privateKey: string
|
|
||||||
let walletAddress: string
|
|
||||||
|
|
||||||
if (importType === 'privateKey') {
|
|
||||||
// 私钥模式
|
|
||||||
privateKey = values.privateKey
|
|
||||||
walletAddress = values.walletAddress
|
|
||||||
|
|
||||||
// 验证推导的地址和输入的地址是否一致
|
|
||||||
if (derivedAddress && walletAddress !== derivedAddress) {
|
|
||||||
message.error(t('accountImport.walletAddressMismatch'))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 助记词模式
|
|
||||||
if (!values.mnemonic) {
|
|
||||||
message.error(t('accountImport.mnemonicRequired'))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 从助记词导出私钥和地址
|
|
||||||
privateKey = getPrivateKeyFromMnemonic(values.mnemonic, 0)
|
|
||||||
const derivedAddressFromMnemonic = getAddressFromMnemonic(values.mnemonic, 0)
|
|
||||||
|
|
||||||
// 如果用户手动输入了地址,验证是否与推导的地址一致
|
|
||||||
if (values.walletAddress) {
|
|
||||||
if (values.walletAddress !== derivedAddressFromMnemonic) {
|
|
||||||
// 地址不匹配,使用推导的地址(因为私钥是从助记词导出的,必须使用对应的地址)
|
|
||||||
message.warning(`${t('accountImport.walletAddressMismatchMnemonic')}: ${derivedAddressFromMnemonic}`)
|
|
||||||
walletAddress = derivedAddressFromMnemonic
|
|
||||||
} else {
|
|
||||||
// 地址匹配,使用用户输入的地址
|
|
||||||
walletAddress = values.walletAddress
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 如果用户没有输入地址,使用推导的地址
|
|
||||||
walletAddress = derivedAddressFromMnemonic
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证钱包地址格式
|
|
||||||
if (!isValidWalletAddress(walletAddress)) {
|
|
||||||
message.error(t('accountImport.walletAddressInvalid'))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
await importAccount({
|
|
||||||
privateKey: privateKey,
|
|
||||||
walletAddress: walletAddress,
|
|
||||||
accountName: values.accountName
|
|
||||||
})
|
|
||||||
|
|
||||||
message.success(t('accountImport.importSuccess'))
|
|
||||||
navigate('/accounts')
|
|
||||||
} catch (error: any) {
|
|
||||||
message.error(error.message || t('accountImport.importFailed'))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -161,165 +31,13 @@ const AccountImport: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<Alert
|
<AccountImportForm
|
||||||
message={t('accountImport.securityTip')}
|
|
||||||
description={t('accountImport.securityTipDesc')}
|
|
||||||
type="warning"
|
|
||||||
showIcon
|
|
||||||
style={{ marginBottom: '24px' }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Form
|
|
||||||
form={form}
|
form={form}
|
||||||
layout="vertical"
|
onSuccess={handleSuccess}
|
||||||
onFinish={handleSubmit}
|
onCancel={() => navigate('/accounts')}
|
||||||
size={isMobile ? 'middle' : 'large'}
|
showAlert={true}
|
||||||
>
|
showCancelButton={true}
|
||||||
<Form.Item label={t('accountImport.importMethod')}>
|
/>
|
||||||
<Radio.Group
|
|
||||||
value={importType}
|
|
||||||
onChange={(e) => {
|
|
||||||
setImportType(e.target.value)
|
|
||||||
setDerivedAddress('')
|
|
||||||
setAddressError('')
|
|
||||||
form.setFieldsValue({ walletAddress: '' })
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Radio value="privateKey">{t('accountImport.privateKey')}</Radio>
|
|
||||||
<Radio value="mnemonic">{t('accountImport.mnemonic')}</Radio>
|
|
||||||
</Radio.Group>
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
{importType === 'privateKey' ? (
|
|
||||||
<>
|
|
||||||
<Form.Item
|
|
||||||
label={t('accountImport.privateKeyLabel')}
|
|
||||||
name="privateKey"
|
|
||||||
rules={[
|
|
||||||
{ required: true, message: t('accountImport.privateKeyRequired') },
|
|
||||||
{
|
|
||||||
validator: (_, value) => {
|
|
||||||
if (!value) return Promise.resolve()
|
|
||||||
if (!isValidPrivateKey(value)) {
|
|
||||||
return Promise.reject(new Error(t('accountImport.privateKeyInvalid')))
|
|
||||||
}
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
help={addressError || (derivedAddress ? `${t('accountImport.derivedAddress')}: ${derivedAddress}` : '')}
|
|
||||||
validateStatus={addressError ? 'error' : derivedAddress ? 'success' : ''}
|
|
||||||
>
|
|
||||||
<Input.TextArea
|
|
||||||
rows={3}
|
|
||||||
placeholder={t('accountImport.privateKeyPlaceholder')}
|
|
||||||
onChange={handlePrivateKeyChange}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
label={t('accountImport.walletAddress')}
|
|
||||||
name="walletAddress"
|
|
||||||
rules={[
|
|
||||||
{ required: true, message: t('accountImport.walletAddressRequired') },
|
|
||||||
{
|
|
||||||
validator: (_, value) => {
|
|
||||||
if (!value) return Promise.resolve()
|
|
||||||
if (!isValidWalletAddress(value)) {
|
|
||||||
return Promise.reject(new Error(t('accountImport.walletAddressInvalid')))
|
|
||||||
}
|
|
||||||
if (derivedAddress && value !== derivedAddress) {
|
|
||||||
return Promise.reject(new Error(t('accountImport.walletAddressMismatch')))
|
|
||||||
}
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Input
|
|
||||||
placeholder={t('accountImport.walletAddressPlaceholder')}
|
|
||||||
readOnly={!!derivedAddress}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Form.Item
|
|
||||||
label={t('accountImport.mnemonicLabel')}
|
|
||||||
name="mnemonic"
|
|
||||||
rules={[
|
|
||||||
{ required: true, message: t('accountImport.mnemonicRequired') },
|
|
||||||
{
|
|
||||||
validator: (_, value) => {
|
|
||||||
if (!value) return Promise.resolve()
|
|
||||||
if (!isValidMnemonic(value)) {
|
|
||||||
return Promise.reject(new Error(t('accountImport.mnemonicInvalid')))
|
|
||||||
}
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
help={addressError || (derivedAddress ? `${t('accountImport.derivedAddress')}: ${derivedAddress}` : '')}
|
|
||||||
validateStatus={addressError ? 'error' : derivedAddress ? 'success' : ''}
|
|
||||||
>
|
|
||||||
<Input.TextArea
|
|
||||||
rows={4}
|
|
||||||
placeholder={t('accountImport.mnemonicPlaceholder')}
|
|
||||||
onChange={handleMnemonicChange}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
label={t('accountImport.walletAddress')}
|
|
||||||
name="walletAddress"
|
|
||||||
rules={[
|
|
||||||
{ required: true, message: t('accountImport.walletAddressRequired') },
|
|
||||||
{
|
|
||||||
validator: (_, value) => {
|
|
||||||
if (!value) return Promise.resolve()
|
|
||||||
if (!isValidWalletAddress(value)) {
|
|
||||||
return Promise.reject(new Error(t('accountImport.walletAddressInvalid')))
|
|
||||||
}
|
|
||||||
if (derivedAddress && value !== derivedAddress) {
|
|
||||||
return Promise.reject(new Error(t('accountImport.walletAddressMismatchMnemonic')))
|
|
||||||
}
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Input
|
|
||||||
placeholder={t('accountImport.walletAddressPlaceholder')}
|
|
||||||
readOnly={!!derivedAddress}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
label={t('accountImport.accountName')}
|
|
||||||
name="accountName"
|
|
||||||
>
|
|
||||||
<Input placeholder={t('accountImport.accountNamePlaceholder')} />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
|
|
||||||
<Form.Item>
|
|
||||||
<Space>
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
htmlType="submit"
|
|
||||||
loading={loading}
|
|
||||||
size={isMobile ? 'middle' : 'large'}
|
|
||||||
>
|
|
||||||
{t('accountImport.importAccount')}
|
|
||||||
</Button>
|
|
||||||
<Button onClick={() => navigate('/accounts')}>
|
|
||||||
{t('common.cancel')}
|
|
||||||
</Button>
|
|
||||||
</Space>
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { Card, Form, Button, Switch, message, Typography, Space, Radio, InputNumber, Modal, Table, Select, Divider, Input } from 'antd'
|
import { Card, Form, Button, Switch, message, Typography, Space, Radio, InputNumber, Modal, Table, Select, Divider, Input } from 'antd'
|
||||||
import { ArrowLeftOutlined, SaveOutlined, FileTextOutlined } from '@ant-design/icons'
|
import { ArrowLeftOutlined, SaveOutlined, FileTextOutlined, PlusOutlined } from '@ant-design/icons'
|
||||||
import { apiService } from '../services/api'
|
import { apiService } from '../services/api'
|
||||||
import { useAccountStore } from '../store/accountStore'
|
import { useAccountStore } from '../store/accountStore'
|
||||||
import type { Leader, CopyTradingTemplate, CopyTradingCreateRequest } from '../types'
|
import type { Leader, CopyTradingTemplate, CopyTradingCreateRequest } from '../types'
|
||||||
import { formatUSDC } from '../utils'
|
import { formatUSDC } from '../utils'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { useMediaQuery } from 'react-responsive'
|
||||||
|
import AccountImportForm from '../components/AccountImportForm'
|
||||||
|
import LeaderAddForm from '../components/LeaderAddForm'
|
||||||
|
|
||||||
const { Title } = Typography
|
const { Title } = Typography
|
||||||
const { Option } = Select
|
const { Option } = Select
|
||||||
@@ -14,6 +17,7 @@ const { Option } = Select
|
|||||||
const CopyTradingAdd: React.FC = () => {
|
const CopyTradingAdd: React.FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
const isMobile = useMediaQuery({ maxWidth: 768 })
|
||||||
const { accounts, fetchAccounts } = useAccountStore()
|
const { accounts, fetchAccounts } = useAccountStore()
|
||||||
const [form] = Form.useForm()
|
const [form] = Form.useForm()
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
@@ -22,6 +26,14 @@ const CopyTradingAdd: React.FC = () => {
|
|||||||
const [templateModalVisible, setTemplateModalVisible] = useState(false)
|
const [templateModalVisible, setTemplateModalVisible] = useState(false)
|
||||||
const [copyMode, setCopyMode] = useState<'RATIO' | 'FIXED'>('RATIO')
|
const [copyMode, setCopyMode] = useState<'RATIO' | 'FIXED'>('RATIO')
|
||||||
|
|
||||||
|
// 导入账户modal相关状态
|
||||||
|
const [accountImportModalVisible, setAccountImportModalVisible] = useState(false)
|
||||||
|
const [accountImportForm] = Form.useForm()
|
||||||
|
|
||||||
|
// 添加leader modal相关状态
|
||||||
|
const [leaderAddModalVisible, setLeaderAddModalVisible] = useState(false)
|
||||||
|
const [leaderAddForm] = Form.useForm()
|
||||||
|
|
||||||
// 生成默认配置名
|
// 生成默认配置名
|
||||||
const generateDefaultConfigName = (): string => {
|
const generateDefaultConfigName = (): string => {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
@@ -85,7 +97,9 @@ const CopyTradingAdd: React.FC = () => {
|
|||||||
minOrderDepth: template.minOrderDepth ? parseFloat(template.minOrderDepth) : undefined,
|
minOrderDepth: template.minOrderDepth ? parseFloat(template.minOrderDepth) : undefined,
|
||||||
maxSpread: template.maxSpread ? parseFloat(template.maxSpread) : undefined,
|
maxSpread: template.maxSpread ? parseFloat(template.maxSpread) : undefined,
|
||||||
minPrice: template.minPrice ? parseFloat(template.minPrice) : undefined,
|
minPrice: template.minPrice ? parseFloat(template.minPrice) : undefined,
|
||||||
maxPrice: template.maxPrice ? parseFloat(template.maxPrice) : undefined
|
maxPrice: template.maxPrice ? parseFloat(template.maxPrice) : undefined,
|
||||||
|
maxPositionValue: (template as any).maxPositionValue ? parseFloat((template as any).maxPositionValue) : undefined,
|
||||||
|
maxPositionCount: (template as any).maxPositionCount
|
||||||
})
|
})
|
||||||
setCopyMode(template.copyMode)
|
setCopyMode(template.copyMode)
|
||||||
setTemplateModalVisible(false)
|
setTemplateModalVisible(false)
|
||||||
@@ -96,6 +110,36 @@ const CopyTradingAdd: React.FC = () => {
|
|||||||
setCopyMode(mode)
|
setCopyMode(mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理导入账户成功
|
||||||
|
const handleAccountImportSuccess = async (accountId: number) => {
|
||||||
|
message.success(t('accountImport.importSuccess'))
|
||||||
|
|
||||||
|
// 刷新账户列表
|
||||||
|
await fetchAccounts()
|
||||||
|
|
||||||
|
// 自动选择新添加的账户
|
||||||
|
form.setFieldsValue({ accountId })
|
||||||
|
|
||||||
|
// 关闭modal并重置表单
|
||||||
|
setAccountImportModalVisible(false)
|
||||||
|
accountImportForm.resetFields()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理添加leader成功
|
||||||
|
const handleLeaderAddSuccess = async (leaderId: number) => {
|
||||||
|
message.success(t('leaderAdd.addSuccess') || '添加 Leader 成功')
|
||||||
|
|
||||||
|
// 刷新leader列表
|
||||||
|
await fetchLeaders()
|
||||||
|
|
||||||
|
// 自动选择新添加的leader
|
||||||
|
form.setFieldsValue({ leaderId })
|
||||||
|
|
||||||
|
// 关闭modal并重置表单
|
||||||
|
setLeaderAddModalVisible(false)
|
||||||
|
leaderAddForm.resetFields()
|
||||||
|
}
|
||||||
|
|
||||||
const handleSubmit = async (values: any) => {
|
const handleSubmit = async (values: any) => {
|
||||||
// 前端校验
|
// 前端校验
|
||||||
if (values.copyMode === 'FIXED') {
|
if (values.copyMode === 'FIXED') {
|
||||||
@@ -134,6 +178,8 @@ const CopyTradingAdd: React.FC = () => {
|
|||||||
maxSpread: values.maxSpread?.toString(),
|
maxSpread: values.maxSpread?.toString(),
|
||||||
minPrice: values.minPrice?.toString(),
|
minPrice: values.minPrice?.toString(),
|
||||||
maxPrice: values.maxPrice?.toString(),
|
maxPrice: values.maxPrice?.toString(),
|
||||||
|
maxPositionValue: values.maxPositionValue?.toString(),
|
||||||
|
maxPositionCount: values.maxPositionCount,
|
||||||
configName: values.configName?.trim(),
|
configName: values.configName?.trim(),
|
||||||
pushFailedOrders: values.pushFailedOrders ?? false
|
pushFailedOrders: values.pushFailedOrders ?? false
|
||||||
}
|
}
|
||||||
@@ -209,7 +255,24 @@ const CopyTradingAdd: React.FC = () => {
|
|||||||
name="accountId"
|
name="accountId"
|
||||||
rules={[{ required: true, message: t('copyTradingAdd.walletRequired') || '请选择钱包' }]}
|
rules={[{ required: true, message: t('copyTradingAdd.walletRequired') || '请选择钱包' }]}
|
||||||
>
|
>
|
||||||
<Select placeholder={t('copyTradingAdd.selectWalletPlaceholder') || '请选择钱包'}>
|
<Select
|
||||||
|
placeholder={t('copyTradingAdd.selectWalletPlaceholder') || '请选择钱包'}
|
||||||
|
notFoundContent={
|
||||||
|
accounts.length === 0 ? (
|
||||||
|
<div style={{ textAlign: 'center', padding: '12px' }}>
|
||||||
|
<div style={{ marginBottom: '8px' }}>{t('copyTradingAdd.noAccounts') || '暂无账户'}</div>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
icon={<PlusOutlined />}
|
||||||
|
onClick={() => setAccountImportModalVisible(true)}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
{t('copyTradingAdd.importAccount') || '导入账户'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
>
|
||||||
{accounts.map(account => (
|
{accounts.map(account => (
|
||||||
<Option key={account.id} value={account.id}>
|
<Option key={account.id} value={account.id}>
|
||||||
{account.accountName || `账户 ${account.id}`} ({account.walletAddress.slice(0, 6)}...{account.walletAddress.slice(-4)})
|
{account.accountName || `账户 ${account.id}`} ({account.walletAddress.slice(0, 6)}...{account.walletAddress.slice(-4)})
|
||||||
@@ -223,7 +286,24 @@ const CopyTradingAdd: React.FC = () => {
|
|||||||
name="leaderId"
|
name="leaderId"
|
||||||
rules={[{ required: true, message: t('copyTradingAdd.leaderRequired') || '请选择 Leader' }]}
|
rules={[{ required: true, message: t('copyTradingAdd.leaderRequired') || '请选择 Leader' }]}
|
||||||
>
|
>
|
||||||
<Select placeholder={t('copyTradingAdd.selectLeaderPlaceholder') || '请选择 Leader'}>
|
<Select
|
||||||
|
placeholder={t('copyTradingAdd.selectLeaderPlaceholder') || '请选择 Leader'}
|
||||||
|
notFoundContent={
|
||||||
|
leaders.length === 0 ? (
|
||||||
|
<div style={{ textAlign: 'center', padding: '12px' }}>
|
||||||
|
<div style={{ marginBottom: '8px' }}>{t('copyTradingAdd.noLeaders') || '暂无 Leader'}</div>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
icon={<PlusOutlined />}
|
||||||
|
onClick={() => setLeaderAddModalVisible(true)}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
{t('copyTradingAdd.addLeader') || '添加 Leader'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
>
|
||||||
{leaders.map(leader => (
|
{leaders.map(leader => (
|
||||||
<Option key={leader.id} value={leader.id}>
|
<Option key={leader.id} value={leader.id}>
|
||||||
{leader.leaderName || `Leader ${leader.id}`} ({leader.leaderAddress.slice(0, 6)}...{leader.leaderAddress.slice(-4)})
|
{leader.leaderName || `Leader ${leader.id}`} ({leader.leaderAddress.slice(0, 6)}...{leader.leaderAddress.slice(-4)})
|
||||||
@@ -467,6 +547,35 @@ const CopyTradingAdd: React.FC = () => {
|
|||||||
</Input.Group>
|
</Input.Group>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
<Divider>{t('copyTradingAdd.positionLimitFilter') || '最大仓位限制'}</Divider>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
label={t('copyTradingAdd.maxPositionValue') || '最大仓位金额 (USDC)'}
|
||||||
|
name="maxPositionValue"
|
||||||
|
tooltip={t('copyTradingAdd.maxPositionValueTooltip') || '限制单个市场的最大仓位金额。如果该市场的当前仓位金额 + 跟单金额超过此限制,则不会下单。不填写则不启用此限制'}
|
||||||
|
>
|
||||||
|
<InputNumber
|
||||||
|
min={0}
|
||||||
|
step={0.0001}
|
||||||
|
precision={4}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
placeholder={t('copyTradingAdd.maxPositionValuePlaceholder') || '例如:100(可选,不填写表示不启用)'}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
label={t('copyTradingAdd.maxPositionCount') || '最大仓位数量'}
|
||||||
|
name="maxPositionCount"
|
||||||
|
tooltip={t('copyTradingAdd.maxPositionCountTooltip') || '限制单个市场的最大仓位数量。如果该市场的当前仓位数量达到或超过此限制,则不会下单。不填写则不启用此限制'}
|
||||||
|
>
|
||||||
|
<InputNumber
|
||||||
|
min={1}
|
||||||
|
step={1}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
placeholder={t('copyTradingAdd.maxPositionCountPlaceholder') || '例如:10(可选,不填写表示不启用)'}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
<Divider>{t('copyTradingAdd.advancedSettings') || '高级设置'}</Divider>
|
<Divider>{t('copyTradingAdd.advancedSettings') || '高级设置'}</Divider>
|
||||||
|
|
||||||
{/* 跟单卖出 */}
|
{/* 跟单卖出 */}
|
||||||
@@ -550,6 +659,61 @@ const CopyTradingAdd: React.FC = () => {
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
{/* 导入账户 Modal */}
|
||||||
|
<Modal
|
||||||
|
title={t('accountImport.title') || '导入账户'}
|
||||||
|
open={accountImportModalVisible}
|
||||||
|
onCancel={() => {
|
||||||
|
setAccountImportModalVisible(false)
|
||||||
|
accountImportForm.resetFields()
|
||||||
|
}}
|
||||||
|
footer={null}
|
||||||
|
width={isMobile ? '95%' : 600}
|
||||||
|
style={{ top: isMobile ? 20 : 50 }}
|
||||||
|
bodyStyle={{ padding: '24px', maxHeight: 'calc(100vh - 150px)', overflow: 'auto' }}
|
||||||
|
destroyOnClose
|
||||||
|
maskClosable
|
||||||
|
closable
|
||||||
|
>
|
||||||
|
<AccountImportForm
|
||||||
|
form={accountImportForm}
|
||||||
|
onSuccess={handleAccountImportSuccess}
|
||||||
|
onCancel={() => {
|
||||||
|
setAccountImportModalVisible(false)
|
||||||
|
accountImportForm.resetFields()
|
||||||
|
}}
|
||||||
|
showAlert={true}
|
||||||
|
showCancelButton={true}
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
{/* 添加 Leader Modal */}
|
||||||
|
<Modal
|
||||||
|
title={t('leaderAdd.title') || '添加 Leader'}
|
||||||
|
open={leaderAddModalVisible}
|
||||||
|
onCancel={() => {
|
||||||
|
setLeaderAddModalVisible(false)
|
||||||
|
leaderAddForm.resetFields()
|
||||||
|
}}
|
||||||
|
footer={null}
|
||||||
|
width={isMobile ? '95%' : 600}
|
||||||
|
style={{ top: isMobile ? 20 : 50 }}
|
||||||
|
bodyStyle={{ padding: '24px', maxHeight: 'calc(100vh - 150px)', overflow: 'auto' }}
|
||||||
|
destroyOnClose
|
||||||
|
maskClosable
|
||||||
|
closable
|
||||||
|
>
|
||||||
|
<LeaderAddForm
|
||||||
|
form={leaderAddForm}
|
||||||
|
onSuccess={handleLeaderAddSuccess}
|
||||||
|
onCancel={() => {
|
||||||
|
setLeaderAddModalVisible(false)
|
||||||
|
leaderAddForm.resetFields()
|
||||||
|
}}
|
||||||
|
showCancelButton={true}
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ const CopyTradingEdit: React.FC = () => {
|
|||||||
maxSpread: found.maxSpread ? parseFloat(found.maxSpread) : undefined,
|
maxSpread: found.maxSpread ? parseFloat(found.maxSpread) : undefined,
|
||||||
minPrice: found.minPrice ? parseFloat(found.minPrice) : undefined,
|
minPrice: found.minPrice ? parseFloat(found.minPrice) : undefined,
|
||||||
maxPrice: found.maxPrice ? parseFloat(found.maxPrice) : undefined,
|
maxPrice: found.maxPrice ? parseFloat(found.maxPrice) : undefined,
|
||||||
|
maxPositionValue: found.maxPositionValue ? parseFloat(found.maxPositionValue) : undefined,
|
||||||
|
maxPositionCount: found.maxPositionCount,
|
||||||
configName: found.configName || '',
|
configName: found.configName || '',
|
||||||
pushFailedOrders: found.pushFailedOrders ?? false
|
pushFailedOrders: found.pushFailedOrders ?? false
|
||||||
})
|
})
|
||||||
@@ -123,6 +125,8 @@ const CopyTradingEdit: React.FC = () => {
|
|||||||
maxSpread: values.maxSpread?.toString(),
|
maxSpread: values.maxSpread?.toString(),
|
||||||
minPrice: values.minPrice?.toString(),
|
minPrice: values.minPrice?.toString(),
|
||||||
maxPrice: values.maxPrice?.toString(),
|
maxPrice: values.maxPrice?.toString(),
|
||||||
|
maxPositionValue: values.maxPositionValue?.toString(),
|
||||||
|
maxPositionCount: values.maxPositionCount,
|
||||||
configName: values.configName?.trim() || undefined,
|
configName: values.configName?.trim() || undefined,
|
||||||
pushFailedOrders: values.pushFailedOrders
|
pushFailedOrders: values.pushFailedOrders
|
||||||
}
|
}
|
||||||
@@ -436,6 +440,35 @@ const CopyTradingEdit: React.FC = () => {
|
|||||||
</Input.Group>
|
</Input.Group>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
<Divider>{t('copyTradingEdit.positionLimitFilter') || '最大仓位限制'}</Divider>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
label={t('copyTradingEdit.maxPositionValue') || '最大仓位金额 (USDC)'}
|
||||||
|
name="maxPositionValue"
|
||||||
|
tooltip={t('copyTradingEdit.maxPositionValueTooltip') || '限制单个市场的最大仓位金额。如果该市场的当前仓位金额 + 跟单金额超过此限制,则不会下单。不填写则不启用此限制'}
|
||||||
|
>
|
||||||
|
<InputNumber
|
||||||
|
min={0}
|
||||||
|
step={0.0001}
|
||||||
|
precision={4}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
placeholder={t('copyTradingEdit.maxPositionValuePlaceholder') || '例如:100(可选,不填写表示不启用)'}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
label={t('copyTradingEdit.maxPositionCount') || '最大仓位数量'}
|
||||||
|
name="maxPositionCount"
|
||||||
|
tooltip={t('copyTradingEdit.maxPositionCountTooltip') || '限制单个市场的最大仓位数量。如果该市场的当前仓位数量达到或超过此限制,则不会下单。不填写则不启用此限制'}
|
||||||
|
>
|
||||||
|
<InputNumber
|
||||||
|
min={1}
|
||||||
|
step={1}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
placeholder={t('copyTradingEdit.maxPositionCountPlaceholder') || '例如:10(可选,不填写表示不启用)'}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
<Divider>{t('copyTradingEdit.advancedSettings') || '高级设置'}</Divider>
|
<Divider>{t('copyTradingEdit.advancedSettings') || '高级设置'}</Divider>
|
||||||
|
|
||||||
{/* 跟单卖出 */}
|
{/* 跟单卖出 */}
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ const EditModal: React.FC<EditModalProps> = ({
|
|||||||
maxSpread: found.maxSpread ? parseFloat(found.maxSpread) : undefined,
|
maxSpread: found.maxSpread ? parseFloat(found.maxSpread) : undefined,
|
||||||
minPrice: found.minPrice ? parseFloat(found.minPrice) : undefined,
|
minPrice: found.minPrice ? parseFloat(found.minPrice) : undefined,
|
||||||
maxPrice: found.maxPrice ? parseFloat(found.maxPrice) : undefined,
|
maxPrice: found.maxPrice ? parseFloat(found.maxPrice) : undefined,
|
||||||
|
maxPositionValue: found.maxPositionValue ? parseFloat(found.maxPositionValue) : undefined,
|
||||||
|
maxPositionCount: found.maxPositionCount,
|
||||||
configName: found.configName || '',
|
configName: found.configName || '',
|
||||||
pushFailedOrders: found.pushFailedOrders ?? false
|
pushFailedOrders: found.pushFailedOrders ?? false
|
||||||
})
|
})
|
||||||
@@ -129,6 +131,8 @@ const EditModal: React.FC<EditModalProps> = ({
|
|||||||
maxSpread: values.maxSpread?.toString(),
|
maxSpread: values.maxSpread?.toString(),
|
||||||
minPrice: values.minPrice?.toString(),
|
minPrice: values.minPrice?.toString(),
|
||||||
maxPrice: values.maxPrice?.toString(),
|
maxPrice: values.maxPrice?.toString(),
|
||||||
|
maxPositionValue: values.maxPositionValue?.toString(),
|
||||||
|
maxPositionCount: values.maxPositionCount,
|
||||||
configName: values.configName?.trim() || undefined,
|
configName: values.configName?.trim() || undefined,
|
||||||
pushFailedOrders: values.pushFailedOrders
|
pushFailedOrders: values.pushFailedOrders
|
||||||
}
|
}
|
||||||
@@ -436,6 +440,35 @@ const EditModal: React.FC<EditModalProps> = ({
|
|||||||
</Input.Group>
|
</Input.Group>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
<Divider>{t('copyTradingEdit.positionLimitFilter') || '最大仓位限制'}</Divider>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
label={t('copyTradingEdit.maxPositionValue') || '最大仓位金额 (USDC)'}
|
||||||
|
name="maxPositionValue"
|
||||||
|
tooltip={t('copyTradingEdit.maxPositionValueTooltip') || '限制单个市场的最大仓位金额。如果该市场的当前仓位金额 + 跟单金额超过此限制,则不会下单。不填写则不启用此限制'}
|
||||||
|
>
|
||||||
|
<InputNumber
|
||||||
|
min={0}
|
||||||
|
step={0.0001}
|
||||||
|
precision={4}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
placeholder={t('copyTradingEdit.maxPositionValuePlaceholder') || '例如:100(可选,不填写表示不启用)'}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
label={t('copyTradingEdit.maxPositionCount') || '最大仓位数量'}
|
||||||
|
name="maxPositionCount"
|
||||||
|
tooltip={t('copyTradingEdit.maxPositionCountTooltip') || '限制单个市场的最大仓位数量。如果该市场的当前仓位数量达到或超过此限制,则不会下单。不填写则不启用此限制'}
|
||||||
|
>
|
||||||
|
<InputNumber
|
||||||
|
min={1}
|
||||||
|
step={1}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
placeholder={t('copyTradingEdit.maxPositionCountPlaceholder') || '例如:10(可选,不填写表示不启用)'}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
<Divider>{t('copyTradingEdit.advancedSettings') || '高级设置'}</Divider>
|
<Divider>{t('copyTradingEdit.advancedSettings') || '高级设置'}</Divider>
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -1,44 +1,20 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { Card, Form, Input, Button, Select, message, Typography, Space } from 'antd'
|
import { Card, Form, Button, Typography } from 'antd'
|
||||||
import { ArrowLeftOutlined } from '@ant-design/icons'
|
import { ArrowLeftOutlined } from '@ant-design/icons'
|
||||||
import { apiService } from '../services/api'
|
|
||||||
import { useMediaQuery } from 'react-responsive'
|
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { isValidWalletAddress } from '../utils'
|
import { message } from 'antd'
|
||||||
|
import LeaderAddForm from '../components/LeaderAddForm'
|
||||||
|
|
||||||
const { Title } = Typography
|
const { Title } = Typography
|
||||||
const { Option } = Select
|
|
||||||
|
|
||||||
const LeaderAdd: React.FC = () => {
|
const LeaderAdd: React.FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const isMobile = useMediaQuery({ maxWidth: 768 })
|
|
||||||
const [form] = Form.useForm()
|
const [form] = Form.useForm()
|
||||||
const [loading, setLoading] = useState(false)
|
|
||||||
|
|
||||||
const handleSubmit = async (values: any) => {
|
const handleSuccess = async () => {
|
||||||
setLoading(true)
|
message.success(t('leaderAdd.addSuccess') || '添加 Leader 成功')
|
||||||
try {
|
navigate('/leaders')
|
||||||
const response = await apiService.leaders.add({
|
|
||||||
leaderAddress: values.leaderAddress.trim(),
|
|
||||||
leaderName: values.leaderName?.trim() || undefined,
|
|
||||||
remark: values.remark?.trim() || undefined,
|
|
||||||
website: values.website?.trim() || undefined,
|
|
||||||
category: values.category || undefined
|
|
||||||
})
|
|
||||||
|
|
||||||
if (response.data.code === 0) {
|
|
||||||
message.success(t('leaderAdd.addSuccess') || '添加 Leader 成功')
|
|
||||||
navigate('/leaders')
|
|
||||||
} else {
|
|
||||||
message.error(response.data.msg || t('leaderAdd.addFailed') || '添加 Leader 失败')
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
|
||||||
message.error(error.message || t('leaderAdd.addFailed') || '添加 Leader 失败')
|
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -49,105 +25,18 @@ const LeaderAdd: React.FC = () => {
|
|||||||
onClick={() => navigate('/leaders')}
|
onClick={() => navigate('/leaders')}
|
||||||
style={{ marginBottom: '16px' }}
|
style={{ marginBottom: '16px' }}
|
||||||
>
|
>
|
||||||
返回
|
{t('leaderAdd.back') || '返回'}
|
||||||
</Button>
|
</Button>
|
||||||
<Title level={2} style={{ margin: 0 }}>{t('leaderAdd.title') || '添加 Leader'}</Title>
|
<Title level={2} style={{ margin: 0 }}>{t('leaderAdd.title') || '添加 Leader'}</Title>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<Form
|
<LeaderAddForm
|
||||||
form={form}
|
form={form}
|
||||||
layout="vertical"
|
onSuccess={handleSuccess}
|
||||||
onFinish={handleSubmit}
|
onCancel={() => navigate('/leaders')}
|
||||||
size={isMobile ? 'middle' : 'large'}
|
showCancelButton={true}
|
||||||
initialValues={{
|
/>
|
||||||
enabled: true
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Form.Item
|
|
||||||
label={t('leaderAdd.leaderAddress') || 'Leader 钱包地址'}
|
|
||||||
name="leaderAddress"
|
|
||||||
rules={[
|
|
||||||
{ required: true, message: t('leaderAdd.leaderAddressRequired') || '请输入 Leader 钱包地址' },
|
|
||||||
{
|
|
||||||
validator: (_, value) => {
|
|
||||||
if (!value) {
|
|
||||||
return Promise.reject(new Error(t('leaderAdd.leaderAddressRequired') || '请输入 Leader 钱包地址'))
|
|
||||||
}
|
|
||||||
if (!isValidWalletAddress(value.trim())) {
|
|
||||||
return Promise.reject(new Error(t('leaderAdd.leaderAddressInvalid') || '钱包地址格式不正确(必须是 0x 开头的 42 位地址)'))
|
|
||||||
}
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
tooltip={t('leaderAdd.leaderAddressTooltip') || '被跟单者的钱包地址,系统将监控该地址的交易并自动跟单'}
|
|
||||||
>
|
|
||||||
<Input placeholder="0x..." style={{ fontFamily: 'monospace' }} />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
label={t('leaderAdd.leaderName') || 'Leader 名称'}
|
|
||||||
name="leaderName"
|
|
||||||
tooltip={t('leaderAdd.leaderNameTooltip') || '可选,用于标识 Leader,方便管理'}
|
|
||||||
>
|
|
||||||
<Input placeholder={t('leaderAdd.leaderNamePlaceholder') || '可选,用于标识 Leader'} />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
label={t('leaderAdd.remark') || 'Leader 备注'}
|
|
||||||
name="remark"
|
|
||||||
tooltip={t('leaderAdd.remarkTooltip') || '可选,用于记录 Leader 的备注信息'}
|
|
||||||
>
|
|
||||||
<Input.TextArea
|
|
||||||
placeholder={t('leaderAdd.remarkPlaceholder') || '可选,用于记录 Leader 的备注信息'}
|
|
||||||
rows={3}
|
|
||||||
maxLength={500}
|
|
||||||
showCount
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
label={t('leaderAdd.website') || 'Leader 网站'}
|
|
||||||
name="website"
|
|
||||||
tooltip={t('leaderAdd.websiteTooltip') || '可选,Leader 的网站链接'}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
type: 'url',
|
|
||||||
message: t('leaderAdd.websiteInvalid') || '请输入有效的 URL 地址'
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Input placeholder={t('leaderAdd.websitePlaceholder') || '可选,例如:https://example.com'} />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
label={t('leaderAdd.category') || '分类筛选'}
|
|
||||||
name="category"
|
|
||||||
tooltip={t('leaderAdd.categoryTooltip') || '仅跟单该分类的交易,不选择则跟单所有分类(sports 或 crypto)'}
|
|
||||||
>
|
|
||||||
<Select placeholder={t('leaderAdd.categoryPlaceholder') || '选择分类(可选)'} allowClear>
|
|
||||||
<Option value="sports">Sports</Option>
|
|
||||||
<Option value="crypto">Crypto</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item>
|
|
||||||
<Space>
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
htmlType="submit"
|
|
||||||
loading={loading}
|
|
||||||
size={isMobile ? 'middle' : 'large'}
|
|
||||||
>
|
|
||||||
{t('leaderAdd.add') || '添加 Leader'}
|
|
||||||
</Button>
|
|
||||||
<Button onClick={() => navigate('/leaders')}>
|
|
||||||
{t('leaderAdd.cancel') || '取消'}
|
|
||||||
</Button>
|
|
||||||
</Space>
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import { useNavigate, useSearchParams } from 'react-router-dom'
|
import { useNavigate, useSearchParams } from 'react-router-dom'
|
||||||
import { Card, Form, Input, Button, Select, message, Typography, Space, Spin } from 'antd'
|
import { Card, Form, Input, Button, message, Typography, Space, Spin } from 'antd'
|
||||||
import { ArrowLeftOutlined } from '@ant-design/icons'
|
import { ArrowLeftOutlined } from '@ant-design/icons'
|
||||||
import { apiService } from '../services/api'
|
import { apiService } from '../services/api'
|
||||||
import { useMediaQuery } from 'react-responsive'
|
import { useMediaQuery } from 'react-responsive'
|
||||||
@@ -8,7 +8,6 @@ import { useTranslation } from 'react-i18next'
|
|||||||
import type { Leader } from '../types'
|
import type { Leader } from '../types'
|
||||||
|
|
||||||
const { Title } = Typography
|
const { Title } = Typography
|
||||||
const { Option } = Select
|
|
||||||
|
|
||||||
const LeaderEdit: React.FC = () => {
|
const LeaderEdit: React.FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@@ -38,8 +37,7 @@ const LeaderEdit: React.FC = () => {
|
|||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
leaderName: leader.leaderName || '',
|
leaderName: leader.leaderName || '',
|
||||||
remark: leader.remark || '',
|
remark: leader.remark || '',
|
||||||
website: leader.website || '',
|
website: leader.website || ''
|
||||||
category: leader.category || undefined
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
message.error(response.data.msg || t('leaderEdit.fetchFailed') || '获取 Leader 详情失败')
|
message.error(response.data.msg || t('leaderEdit.fetchFailed') || '获取 Leader 详情失败')
|
||||||
@@ -65,8 +63,7 @@ const LeaderEdit: React.FC = () => {
|
|||||||
leaderId: parseInt(leaderId),
|
leaderId: parseInt(leaderId),
|
||||||
leaderName: values.leaderName?.trim() || undefined,
|
leaderName: values.leaderName?.trim() || undefined,
|
||||||
remark: values.remark?.trim() || undefined,
|
remark: values.remark?.trim() || undefined,
|
||||||
website: values.website?.trim() || undefined,
|
website: values.website?.trim() || undefined
|
||||||
category: values.category || undefined
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (response.data.code === 0) {
|
if (response.data.code === 0) {
|
||||||
@@ -145,17 +142,6 @@ const LeaderEdit: React.FC = () => {
|
|||||||
<Input placeholder={t('leaderEdit.websitePlaceholder') || '可选,例如:https://example.com'} />
|
<Input placeholder={t('leaderEdit.websitePlaceholder') || '可选,例如:https://example.com'} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item
|
|
||||||
label={t('leaderEdit.category') || '分类筛选'}
|
|
||||||
name="category"
|
|
||||||
tooltip={t('leaderEdit.categoryTooltip') || '仅跟单该分类的交易,不选择则跟单所有分类(sports 或 crypto)'}
|
|
||||||
>
|
|
||||||
<Select placeholder={t('leaderEdit.categoryPlaceholder') || '选择分类(可选)'} allowClear>
|
|
||||||
<Option value="sports">Sports</Option>
|
|
||||||
<Option value="crypto">Crypto</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
<Space>
|
<Space>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { Card, Table, Button, Space, Tag, Popconfirm, message, List, Empty, Spin, Divider, Typography } from 'antd'
|
import { Card, Table, Button, Space, Tag, Popconfirm, message, List, Empty, Spin, Divider, Typography } from 'antd'
|
||||||
import { PlusOutlined, EditOutlined, DeleteOutlined, LinkOutlined, GlobalOutlined } from '@ant-design/icons'
|
import { PlusOutlined, EditOutlined, DeleteOutlined, GlobalOutlined } from '@ant-design/icons'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { apiService } from '../services/api'
|
import { apiService } from '../services/api'
|
||||||
import type { Leader } from '../types'
|
import type { Leader } from '../types'
|
||||||
@@ -67,14 +67,6 @@ const LeaderList: React.FC = () => {
|
|||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: t('leaderList.category') || '分类',
|
|
||||||
dataIndex: 'category',
|
|
||||||
key: 'category',
|
|
||||||
render: (category: string | undefined) => category ? (
|
|
||||||
<Tag color={category === 'sports' ? 'blue' : 'green'}>{category}</Tag>
|
|
||||||
) : <Tag>{t('leaderList.all') || '全部'}</Tag>
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: t('leaderList.remark') || '备注',
|
title: t('leaderList.remark') || '备注',
|
||||||
dataIndex: 'remark',
|
dataIndex: 'remark',
|
||||||
@@ -233,37 +225,11 @@ const LeaderList: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* 网站 */}
|
|
||||||
{leader.website && (
|
|
||||||
<div style={{ marginBottom: '12px' }}>
|
|
||||||
<Text type="secondary" style={{ fontSize: '12px' }}>
|
|
||||||
{t('leaderList.website') || '网站'}:
|
|
||||||
</Text>
|
|
||||||
<a
|
|
||||||
href={leader.website}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
style={{ fontSize: '12px', marginLeft: '4px' }}
|
|
||||||
>
|
|
||||||
<LinkOutlined /> {leader.website}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Divider style={{ margin: '12px 0' }} />
|
<Divider style={{ margin: '12px 0' }} />
|
||||||
|
|
||||||
{/* 分类和跟单关系数 */}
|
{/* 跟单关系数 */}
|
||||||
<div style={{ marginBottom: '12px' }}>
|
<div style={{ marginBottom: '12px' }}>
|
||||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '6px', alignItems: 'center' }}>
|
<Tag>{t('leaderList.copyTradingRelations', { count: leader.copyTradingCount }) || `${leader.copyTradingCount} 个跟单关系`}</Tag>
|
||||||
{leader.category ? (
|
|
||||||
<Tag color={leader.category === 'sports' ? 'blue' : 'green'}>
|
|
||||||
{leader.category}
|
|
||||||
</Tag>
|
|
||||||
) : (
|
|
||||||
<Tag>{t('leaderList.all') || '全部'}</Tag>
|
|
||||||
)}
|
|
||||||
<Tag>{t('leaderList.copyTradingRelations', { count: leader.copyTradingCount }) || `${leader.copyTradingCount} 个跟单关系`}</Tag>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 创建时间 */}
|
{/* 创建时间 */}
|
||||||
|
|||||||
@@ -348,10 +348,11 @@ const SystemSettings: React.FC = () => {
|
|||||||
if (response.data.code === 0 && response.data.data) {
|
if (response.data.code === 0 && response.data.data) {
|
||||||
const config = response.data.data
|
const config = response.data.data
|
||||||
setSystemConfig(config)
|
setSystemConfig(config)
|
||||||
|
// 将已配置的值填充到输入框中
|
||||||
relayerForm.setFieldsValue({
|
relayerForm.setFieldsValue({
|
||||||
builderApiKey: '',
|
builderApiKey: config.builderApiKeyDisplay || '',
|
||||||
builderSecret: '',
|
builderSecret: config.builderSecretDisplay || '',
|
||||||
builderPassphrase: '',
|
builderPassphrase: config.builderPassphraseDisplay || '',
|
||||||
})
|
})
|
||||||
autoRedeemForm.setFieldsValue({
|
autoRedeemForm.setFieldsValue({
|
||||||
autoRedeemEnabled: config.autoRedeemEnabled
|
autoRedeemEnabled: config.autoRedeemEnabled
|
||||||
@@ -685,30 +686,32 @@ const SystemSettings: React.FC = () => {
|
|||||||
<Form.Item
|
<Form.Item
|
||||||
label={t('builderApiKey.apiKey')}
|
label={t('builderApiKey.apiKey')}
|
||||||
name="builderApiKey"
|
name="builderApiKey"
|
||||||
help={systemConfig?.builderApiKeyConfigured ? t('builderApiKey.apiKeyHelp') : t('builderApiKey.apiKeyPlaceholder')}
|
|
||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
placeholder={systemConfig?.builderApiKeyConfigured ? t('builderApiKey.apiKeyHelp') : t('builderApiKey.apiKeyPlaceholder')}
|
placeholder={t('builderApiKey.apiKeyPlaceholder')}
|
||||||
|
style={{ fontFamily: 'monospace' }}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t('builderApiKey.secret')}
|
label={t('builderApiKey.secret')}
|
||||||
name="builderSecret"
|
name="builderSecret"
|
||||||
help={systemConfig?.builderSecretConfigured ? t('builderApiKey.secretHelp') : t('builderApiKey.secretPlaceholder')}
|
|
||||||
>
|
>
|
||||||
<Input
|
<Input.Password
|
||||||
placeholder={systemConfig?.builderSecretConfigured ? t('builderApiKey.secretHelp') : t('builderApiKey.secretPlaceholder')}
|
placeholder={t('builderApiKey.secretPlaceholder')}
|
||||||
|
style={{ fontFamily: 'monospace' }}
|
||||||
|
iconRender={(visible) => (visible ? <span>👁️</span> : <span>👁️🗨️</span>)}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t('builderApiKey.passphrase')}
|
label={t('builderApiKey.passphrase')}
|
||||||
name="builderPassphrase"
|
name="builderPassphrase"
|
||||||
help={systemConfig?.builderPassphraseConfigured ? t('builderApiKey.passphraseHelp') : t('builderApiKey.passphrasePlaceholder')}
|
|
||||||
>
|
>
|
||||||
<Input
|
<Input.Password
|
||||||
placeholder={systemConfig?.builderPassphraseConfigured ? t('builderApiKey.passphraseHelp') : t('builderApiKey.passphrasePlaceholder')}
|
placeholder={t('builderApiKey.passphrasePlaceholder')}
|
||||||
|
style={{ fontFamily: 'monospace' }}
|
||||||
|
iconRender={(visible) => (visible ? <span>👁️</span> : <span>👁️🗨️</span>)}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
|||||||
@@ -205,6 +205,9 @@ export interface CopyTrading {
|
|||||||
maxSpread?: string
|
maxSpread?: string
|
||||||
minPrice?: string // 最低价格(可选),NULL表示不限制最低价
|
minPrice?: string // 最低价格(可选),NULL表示不限制最低价
|
||||||
maxPrice?: string // 最高价格(可选),NULL表示不限制最高价
|
maxPrice?: string // 最高价格(可选),NULL表示不限制最高价
|
||||||
|
// 最大仓位配置
|
||||||
|
maxPositionValue?: string // 最大仓位金额(USDC),NULL表示不启用
|
||||||
|
maxPositionCount?: number // 最大仓位数量,NULL表示不启用
|
||||||
// 新增配置字段
|
// 新增配置字段
|
||||||
configName?: string // 配置名(可选,但提供时必须非空)
|
configName?: string // 配置名(可选,但提供时必须非空)
|
||||||
pushFailedOrders: boolean // 推送失败订单(默认关闭)
|
pushFailedOrders: boolean // 推送失败订单(默认关闭)
|
||||||
@@ -248,6 +251,9 @@ export interface CopyTradingCreateRequest {
|
|||||||
maxSpread?: string
|
maxSpread?: string
|
||||||
minPrice?: string // 最低价格(可选),NULL表示不限制最低价
|
minPrice?: string // 最低价格(可选),NULL表示不限制最低价
|
||||||
maxPrice?: string // 最高价格(可选),NULL表示不限制最高价
|
maxPrice?: string // 最高价格(可选),NULL表示不限制最高价
|
||||||
|
// 最大仓位配置
|
||||||
|
maxPositionValue?: string // 最大仓位金额(USDC),NULL表示不启用
|
||||||
|
maxPositionCount?: number // 最大仓位数量,NULL表示不启用
|
||||||
// 新增配置字段
|
// 新增配置字段
|
||||||
configName?: string // 配置名(可选,但提供时必须非空)
|
configName?: string // 配置名(可选,但提供时必须非空)
|
||||||
pushFailedOrders?: boolean // 推送失败订单(可选)
|
pushFailedOrders?: boolean // 推送失败订单(可选)
|
||||||
@@ -279,6 +285,9 @@ export interface CopyTradingUpdateRequest {
|
|||||||
maxSpread?: string
|
maxSpread?: string
|
||||||
minPrice?: string // 最低价格(可选),NULL表示不限制最低价
|
minPrice?: string // 最低价格(可选),NULL表示不限制最低价
|
||||||
maxPrice?: string // 最高价格(可选),NULL表示不限制最高价
|
maxPrice?: string // 最高价格(可选),NULL表示不限制最高价
|
||||||
|
// 最大仓位配置
|
||||||
|
maxPositionValue?: string // 最大仓位金额(USDC),NULL表示不启用
|
||||||
|
maxPositionCount?: number // 最大仓位数量,NULL表示不启用
|
||||||
// 新增配置字段
|
// 新增配置字段
|
||||||
configName?: string // 配置名(可选,但提供时必须非空)
|
configName?: string // 配置名(可选,但提供时必须非空)
|
||||||
pushFailedOrders?: boolean // 推送失败订单(可选)
|
pushFailedOrders?: boolean // 推送失败订单(可选)
|
||||||
@@ -770,6 +779,9 @@ export interface SystemConfig {
|
|||||||
builderApiKeyConfigured: boolean
|
builderApiKeyConfigured: boolean
|
||||||
builderSecretConfigured: boolean
|
builderSecretConfigured: boolean
|
||||||
builderPassphraseConfigured: boolean
|
builderPassphraseConfigured: boolean
|
||||||
|
builderApiKeyDisplay?: string // Builder API Key 显示值(部分显示)
|
||||||
|
builderSecretDisplay?: string // Builder Secret 显示值(部分显示)
|
||||||
|
builderPassphraseDisplay?: string // Builder Passphrase 显示值(部分显示)
|
||||||
autoRedeemEnabled: boolean // 自动赎回(系统级别配置,默认开启)
|
autoRedeemEnabled: boolean // 自动赎回(系统级别配置,默认开启)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user