From c2aed38785ef22e0eb93086b1551e2bc748fd92d Mon Sep 17 00:00:00 2001 From: ZhouYongyou <128128010+zhouyongyou@users.noreply.github.com> Date: Sun, 2 Nov 2025 06:06:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=BE=A9=E9=97=9C=E9=8D=B5=20BUG?= =?UTF-8?q?=EF=BC=9AvalidActions=20=E7=BC=BA=E5=B0=91=E6=96=B0=E5=8B=95?= =?UTF-8?q?=E4=BD=9C=E5=B0=8E=E8=87=B4=E9=A9=97=E8=AD=89=E5=A4=B1=E6=95=97?= =?UTF-8?q?=20=E5=95=8F=E9=A1=8C=E6=A0=B9=E5=9B=A0=EF=BC=9A=20-=20auto=5Ft?= =?UTF-8?q?rader.go=20=E5=B7=B2=E5=AF=A6=E7=8F=BE=20update=5Fstop=5Floss/u?= =?UTF-8?q?pdate=5Ftake=5Fprofit/partial=5Fclose=20=E8=99=95=E7=90=86=20-?= =?UTF-8?q?=20adaptive.txt=20=E5=B7=B2=E6=8F=8F=E8=BF=B0=E9=80=99=E4=BA=9B?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20-=20=E4=BD=86=20validateDecision=20?= =?UTF-8?q?=E7=9A=84=20validActions=20map=20=E7=BC=BA=E5=B0=91=E9=80=99?= =?UTF-8?q?=E4=B8=89=E5=80=8B=E5=8B=95=E4=BD=9C=20-=20=E5=B0=8E=E8=87=B4?= =?UTF-8?q?=20AI=20=E7=94=9F=E6=88=90=E7=9A=84=E6=B1=BA=E7=AD=96=E5=9C=A8?= =?UTF-8?q?=E9=A9=97=E8=AD=89=E9=9A=8E=E6=AE=B5=E8=A2=AB=E6=8B=92=E7=B5=95?= =?UTF-8?q?=EF=BC=9A=E3=80=8C=E6=97=A0=E6=95=88=E7=9A=84action:update=5Fst?= =?UTF-8?q?op=5Floss=E3=80=8D=20=E4=BF=AE=E5=BE=A9=E5=85=A7=E5=AE=B9?= =?UTF-8?q?=EF=BC=9A=201.=20validActions=20=E6=B7=BB=E5=8A=A0=E4=B8=89?= =?UTF-8?q?=E5=80=8B=E6=96=B0=E5=8B=95=E4=BD=9C=202.=20=E7=82=BA=E6=AF=8F?= =?UTF-8?q?=E5=80=8B=E6=96=B0=E5=8B=95=E4=BD=9C=E6=B7=BB=E5=8A=A0=E5=8F=83?= =?UTF-8?q?=E6=95=B8=E9=A9=97=E8=AD=89=EF=BC=9A=20=20=20=20-=20update=5Fst?= =?UTF-8?q?op=5Floss:=20=E9=A9=97=E8=AD=89=20NewStopLoss=20>=200=20=20=20?= =?UTF-8?q?=20-=20update=5Ftake=5Fprofit:=20=E9=A9=97=E8=AD=89=20NewTakePr?= =?UTF-8?q?ofit=20>=200=20=20=20=20-=20partial=5Fclose:=20=E9=A9=97?= =?UTF-8?q?=E8=AD=89=20ClosePercentage=20=E5=9C=A8=200-100=20=E4=B9=8B?= =?UTF-8?q?=E9=96=93=203.=20=E4=BF=AE=E6=AD=A3=E8=A8=BB=E9=87=8B=EF=BC=9Aa?= =?UTF-8?q?djust=5F*=20=E2=86=92=20update=5F*=20=E6=B8=AC=E8=A9=A6?= =?UTF-8?q?=E7=8B=80=E6=85=8B=EF=BC=9Afeature=20=E5=88=86=E6=94=AF?= =?UTF-8?q?=EF=BC=8C=E7=AD=89=E5=BE=85=E6=B8=AC=E8=A9=A6=E7=A2=BA=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- decision/engine.go | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/decision/engine.go b/decision/engine.go index 1f187883..fa3e5233 100644 --- a/decision/engine.go +++ b/decision/engine.go @@ -80,8 +80,8 @@ type Decision struct { TakeProfit float64 `json:"take_profit,omitempty"` // 调整参数(新增) - NewStopLoss float64 `json:"new_stop_loss,omitempty"` // 用于 adjust_stop_loss - NewTakeProfit float64 `json:"new_take_profit,omitempty"` // 用于 adjust_take_profit + NewStopLoss float64 `json:"new_stop_loss,omitempty"` // 用于 update_stop_loss + NewTakeProfit float64 `json:"new_take_profit,omitempty"` // 用于 update_take_profit ClosePercentage float64 `json:"close_percentage,omitempty"` // 用于 partial_close (0-100) // 通用参数 @@ -513,12 +513,15 @@ func findMatchingBracket(s string, start int) int { func validateDecision(d *Decision, accountEquity float64, btcEthLeverage, altcoinLeverage int) error { // 验证action validActions := map[string]bool{ - "open_long": true, - "open_short": true, - "close_long": true, - "close_short": true, - "hold": true, - "wait": true, + "open_long": true, + "open_short": true, + "close_long": true, + "close_short": true, + "update_stop_loss": true, + "update_take_profit": true, + "partial_close": true, + "hold": true, + "wait": true, } if !validActions[d.Action] { @@ -598,5 +601,26 @@ func validateDecision(d *Decision, accountEquity float64, btcEthLeverage, altcoi } } + // 动态调整止损验证 + if d.Action == "update_stop_loss" { + if d.NewStopLoss <= 0 { + return fmt.Errorf("新止损价格必须大于0: %.2f", d.NewStopLoss) + } + } + + // 动态调整止盈验证 + if d.Action == "update_take_profit" { + if d.NewTakeProfit <= 0 { + return fmt.Errorf("新止盈价格必须大于0: %.2f", d.NewTakeProfit) + } + } + + // 部分平仓验证 + if d.Action == "partial_close" { + if d.ClosePercentage <= 0 || d.ClosePercentage > 100 { + return fmt.Errorf("平仓百分比必须在0-100之间: %.1f", d.ClosePercentage) + } + } + return nil }