From fb9a4994c00b3d67bd4a427c6892581f819c65ce Mon Sep 17 00:00:00 2001 From: c9s Date: Fri, 26 Aug 2022 18:11:45 +0800 Subject: [PATCH] bbgo: add supportTakeProfit method to the core exit methods --- pkg/bbgo/exit.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/bbgo/exit.go b/pkg/bbgo/exit.go index 4c554ce7e..68282cecb 100644 --- a/pkg/bbgo/exit.go +++ b/pkg/bbgo/exit.go @@ -32,9 +32,13 @@ type ExitMethod struct { RoiStopLoss *RoiStopLoss `json:"roiStopLoss"` ProtectiveStopLoss *ProtectiveStopLoss `json:"protectiveStopLoss"` RoiTakeProfit *RoiTakeProfit `json:"roiTakeProfit"` + TrailingStop *TrailingStop2 `json:"trailingStop"` + + // Exit methods for short positions + // ================================================= LowerShadowTakeProfit *LowerShadowTakeProfit `json:"lowerShadowTakeProfit"` CumulatedVolumeTakeProfit *CumulatedVolumeTakeProfit `json:"cumulatedVolumeTakeProfit"` - TrailingStop *TrailingStop2 `json:"trailingStop"` + SupportTakeProfit []*SupportTakeProfit `json:"supportTakeProfit"` } func (e ExitMethod) String() string { @@ -43,26 +47,37 @@ func (e ExitMethod) String() string { b, _ := json.Marshal(e.RoiStopLoss) buf.WriteString("roiStopLoss: " + string(b) + ", ") } + if e.ProtectiveStopLoss != nil { b, _ := json.Marshal(e.ProtectiveStopLoss) buf.WriteString("protectiveStopLoss: " + string(b) + ", ") } + if e.RoiTakeProfit != nil { b, _ := json.Marshal(e.RoiTakeProfit) buf.WriteString("rioTakeProft: " + string(b) + ", ") } + if e.LowerShadowTakeProfit != nil { b, _ := json.Marshal(e.LowerShadowTakeProfit) buf.WriteString("lowerShadowTakeProft: " + string(b) + ", ") } + if e.CumulatedVolumeTakeProfit != nil { b, _ := json.Marshal(e.CumulatedVolumeTakeProfit) buf.WriteString("cumulatedVolumeTakeProfit: " + string(b) + ", ") } + if e.TrailingStop != nil { b, _ := json.Marshal(e.TrailingStop) buf.WriteString("trailingStop: " + string(b) + ", ") } + + if e.SupportTakeProfit != nil { + b, _ := json.Marshal(e.SupportTakeProfit) + buf.WriteString("supportTakeProfit: " + string(b) + ", ") + } + return buf.String() } @@ -113,6 +128,10 @@ func (m *ExitMethod) Bind(session *ExchangeSession, orderExecutor *GeneralOrderE m.CumulatedVolumeTakeProfit.Bind(session, orderExecutor) } + if m.SupportTakeProfit != nil { + m.SupportTakeProfit.Bind(session, orderExecutor) + } + if m.TrailingStop != nil { m.TrailingStop.Bind(session, orderExecutor) }