mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-13 15:57:01 +08:00
Feature: Add position details to Trade History
Add missing fields to TradeOutcome: - Quantity: Position size - Leverage: Leverage multiplier - PositionValue: Total position value (quantity × openPrice) - MarginUsed: Margin required (positionValue / leverage) This provides complete trade information for analysis and display. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -269,16 +269,20 @@ type Statistics struct {
|
|||||||
|
|
||||||
// TradeOutcome 单笔交易结果
|
// TradeOutcome 单笔交易结果
|
||||||
type TradeOutcome struct {
|
type TradeOutcome struct {
|
||||||
Symbol string `json:"symbol"` // 币种
|
Symbol string `json:"symbol"` // 币种
|
||||||
Side string `json:"side"` // long/short
|
Side string `json:"side"` // long/short
|
||||||
OpenPrice float64 `json:"open_price"` // 开仓价
|
Quantity float64 `json:"quantity"` // 仓位数量
|
||||||
ClosePrice float64 `json:"close_price"` // 平仓价
|
Leverage int `json:"leverage"` // 杠杆倍数
|
||||||
PnL float64 `json:"pn_l"` // 盈亏(USDT)
|
OpenPrice float64 `json:"open_price"` // 开仓价
|
||||||
PnLPct float64 `json:"pn_l_pct"` // 盈亏百分比
|
ClosePrice float64 `json:"close_price"` // 平仓价
|
||||||
Duration string `json:"duration"` // 持仓时长
|
PositionValue float64 `json:"position_value"` // 仓位价值(quantity × openPrice)
|
||||||
OpenTime time.Time `json:"open_time"` // 开仓时间
|
MarginUsed float64 `json:"margin_used"` // 保证金使用(positionValue / leverage)
|
||||||
CloseTime time.Time `json:"close_time"` // 平仓时间
|
PnL float64 `json:"pn_l"` // 盈亏(USDT)
|
||||||
WasStopLoss bool `json:"was_stop_loss"` // 是否止损
|
PnLPct float64 `json:"pn_l_pct"` // 盈亏百分比(相对保证金)
|
||||||
|
Duration string `json:"duration"` // 持仓时长
|
||||||
|
OpenTime time.Time `json:"open_time"` // 开仓时间
|
||||||
|
CloseTime time.Time `json:"close_time"` // 平仓时间
|
||||||
|
WasStopLoss bool `json:"was_stop_loss"` // 是否止损
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerformanceAnalysis 交易表现分析
|
// PerformanceAnalysis 交易表现分析
|
||||||
@@ -424,15 +428,19 @@ func (l *DecisionLogger) AnalyzePerformance(lookbackCycles int) (*PerformanceAna
|
|||||||
|
|
||||||
// 记录交易结果
|
// 记录交易结果
|
||||||
outcome := TradeOutcome{
|
outcome := TradeOutcome{
|
||||||
Symbol: symbol,
|
Symbol: symbol,
|
||||||
Side: side,
|
Side: side,
|
||||||
OpenPrice: openPrice,
|
Quantity: quantity,
|
||||||
ClosePrice: action.Price,
|
Leverage: leverage,
|
||||||
PnL: pnl,
|
OpenPrice: openPrice,
|
||||||
PnLPct: pnlPct,
|
ClosePrice: action.Price,
|
||||||
Duration: action.Timestamp.Sub(openTime).String(),
|
PositionValue: positionValue,
|
||||||
OpenTime: openTime,
|
MarginUsed: marginUsed,
|
||||||
CloseTime: action.Timestamp,
|
PnL: pnl,
|
||||||
|
PnLPct: pnlPct,
|
||||||
|
Duration: action.Timestamp.Sub(openTime).String(),
|
||||||
|
OpenTime: openTime,
|
||||||
|
CloseTime: action.Timestamp,
|
||||||
}
|
}
|
||||||
|
|
||||||
analysis.RecentTrades = append(analysis.RecentTrades, outcome)
|
analysis.RecentTrades = append(analysis.RecentTrades, outcome)
|
||||||
|
|||||||
Reference in New Issue
Block a user