bbgo: add supportTakeProfit method to the core exit methods

This commit is contained in:
c9s 2022-08-26 18:11:45 +08:00
parent 11854db51a
commit fb9a4994c0
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -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)
}