2022-06-28 17:58:15 +00:00
|
|
|
package bbgo
|
2022-06-26 08:31:48 +00:00
|
|
|
|
2022-06-28 17:58:15 +00:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
|
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
|
|
)
|
2022-06-26 08:31:48 +00:00
|
|
|
|
|
|
|
type ExitMethod struct {
|
2022-06-27 11:54:58 +00:00
|
|
|
RoiStopLoss *RoiStopLoss `json:"roiStopLoss"`
|
2022-06-28 17:31:56 +00:00
|
|
|
ProtectiveStopLoss *ProtectiveStopLoss `json:"protectiveStopLoss"`
|
2022-06-27 11:54:58 +00:00
|
|
|
RoiTakeProfit *RoiTakeProfit `json:"roiTakeProfit"`
|
|
|
|
LowerShadowTakeProfit *LowerShadowTakeProfit `json:"lowerShadowTakeProfit"`
|
2022-06-26 08:31:48 +00:00
|
|
|
CumulatedVolumeTakeProfit *CumulatedVolumeTakeProfit `json:"cumulatedVolumeTakeProfit"`
|
|
|
|
}
|
|
|
|
|
2022-06-28 17:58:15 +00:00
|
|
|
func (m *ExitMethod) Subscribe() {
|
2022-06-28 18:03:00 +00:00
|
|
|
// TODO: pull out this implementation as a simple function to reflect.go
|
2022-06-28 18:02:23 +00:00
|
|
|
rv := reflect.ValueOf(m)
|
2022-06-28 17:58:15 +00:00
|
|
|
rt := reflect.TypeOf(m)
|
2022-06-28 18:02:23 +00:00
|
|
|
|
|
|
|
rv = rv.Elem()
|
2022-06-28 17:58:15 +00:00
|
|
|
rt = rt.Elem()
|
2022-06-28 18:02:23 +00:00
|
|
|
infType := reflect.TypeOf((*types.Subscriber)(nil)).Elem()
|
|
|
|
for i := 0; i < rt.NumField(); i++ {
|
2022-06-28 17:58:15 +00:00
|
|
|
fieldType := rt.Field(i)
|
2022-06-28 18:02:23 +00:00
|
|
|
if fieldType.Type.Implements(infType) {
|
2022-06-28 17:58:15 +00:00
|
|
|
method := rv.Field(i).MethodByName("Subscribe")
|
|
|
|
method.Call(nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ExitMethod) Bind(session *ExchangeSession, orderExecutor *GeneralOrderExecutor) {
|
2022-06-28 17:31:56 +00:00
|
|
|
if m.ProtectiveStopLoss != nil {
|
|
|
|
m.ProtectiveStopLoss.Bind(session, orderExecutor)
|
2022-06-26 08:31:48 +00:00
|
|
|
} else if m.RoiStopLoss != nil {
|
|
|
|
m.RoiStopLoss.Bind(session, orderExecutor)
|
|
|
|
} else if m.RoiTakeProfit != nil {
|
|
|
|
m.RoiTakeProfit.Bind(session, orderExecutor)
|
|
|
|
} else if m.LowerShadowTakeProfit != nil {
|
|
|
|
m.LowerShadowTakeProfit.Bind(session, orderExecutor)
|
|
|
|
} else if m.CumulatedVolumeTakeProfit != nil {
|
|
|
|
m.CumulatedVolumeTakeProfit.Bind(session, orderExecutor)
|
|
|
|
}
|
|
|
|
}
|