mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-24 07:45:15 +00:00
43 lines
940 B
Go
43 lines
940 B
Go
|
package kline
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"github.com/sirupsen/logrus"
|
||
|
|
||
|
"github.com/c9s/bbgo/pkg/bbgo"
|
||
|
"github.com/c9s/bbgo/pkg/types"
|
||
|
)
|
||
|
|
||
|
const ID = "kline"
|
||
|
|
||
|
var log = logrus.WithField("strategy", ID)
|
||
|
|
||
|
func init() {
|
||
|
bbgo.RegisterStrategy(ID, &Strategy{})
|
||
|
}
|
||
|
|
||
|
type Strategy struct {
|
||
|
Symbol string `json:"symbol"`
|
||
|
MovingAverage types.IntervalWindow `json:"movingAverage"`
|
||
|
}
|
||
|
|
||
|
func (s *Strategy) ID() string {
|
||
|
return ID
|
||
|
}
|
||
|
|
||
|
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
|
||
|
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: string(s.MovingAverage.Interval)})
|
||
|
}
|
||
|
|
||
|
func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
|
||
|
session.MarketDataStream.OnKLineClosed(func(kline types.KLine) {
|
||
|
// skip k-lines from other symbols
|
||
|
if kline.Symbol != s.Symbol {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
log.Infof("%s", kline.String())
|
||
|
})
|
||
|
return nil
|
||
|
}
|