Slide 117
Slide 117 text
func init() {
bbgo.RegisterStrategy("skeleton", &Strategy{})
}
type Strategy struct {
Symbol string `json:"symbol"`
}
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"})
}
func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
session.Stream.OnKLineClosed(func(kline types.KLine) {
_, err := orderExecutor.SubmitOrders(ctx, types.SubmitOrder{
Symbol: kline.Symbol,
Side: types.SideTypeBuy,
Type: types.OrderTypeMarket,
Quantity: 0.01,
})
if err != nil {
log.WithError(err).Error("submit order error")
}
})
return nil
}
策略的 struct, ⽤來讀設定