bbgo_origin/pkg/strategy/skeleton/strategy.go

48 lines
995 B
Go
Raw Normal View History

2020-10-24 09:58:45 +00:00
package skeleton
import (
"context"
log "github.com/sirupsen/logrus"
"github.com/c9s/bbgo/pkg/bbgo"
"github.com/c9s/bbgo/pkg/types"
)
func init() {
2020-10-28 23:54:59 +00:00
bbgo.RegisterStrategy("skeleton", &Strategy{})
2020-10-24 09:58:45 +00:00
}
type Strategy struct {
Symbol string `json:"symbol"`
types.Market
2020-10-24 09:58:45 +00:00
}
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
2020-10-24 09:58:45 +00:00
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"})
}
2020-10-24 09:58:45 +00:00
func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
session.Stream.OnKLineClosed(func(kline types.KLine) {
quoteBalance, ok := session.Account.Balance(s.Market.QuoteCurrency)
2020-10-24 09:58:45 +00:00
if !ok {
return
}
_ = quoteBalance
_, err := orderExecutor.SubmitOrders(ctx, types.SubmitOrder{
2020-10-24 09:58:45 +00:00
Symbol: kline.Symbol,
Side: types.SideTypeBuy,
Type: types.OrderTypeMarket,
Quantity: 0.01,
})
if err != nil {
log.WithError(err).Error("submit order error")
}
})
return nil
}