add xtemplate strategy

This commit is contained in:
narumi 2023-09-28 13:53:22 +08:00
parent 2058ce808b
commit 01ecb58536
3 changed files with 66 additions and 0 deletions

14
config/xtemplate.yaml Normal file
View File

@ -0,0 +1,14 @@
---
sessions:
max:
exchange: max
envVarPrefix: max
binance:
exchange: binance
envVarPrefix: binance
crossExchangeStrategies:
- xtemplate:
symbol: BTCUSDT
interval: 1m

View File

@ -48,4 +48,5 @@ import (
_ "github.com/c9s/bbgo/pkg/strategy/xmaker"
_ "github.com/c9s/bbgo/pkg/strategy/xnav"
_ "github.com/c9s/bbgo/pkg/strategy/xpuremaker"
_ "github.com/c9s/bbgo/pkg/strategy/xtemplate"
)

View File

@ -0,0 +1,51 @@
package xtemplate
import (
"context"
"sync"
"github.com/sirupsen/logrus"
"github.com/c9s/bbgo/pkg/bbgo"
"github.com/c9s/bbgo/pkg/types"
)
const ID = "xtemplate"
var log = logrus.WithField("strategy", ID)
func init() {
bbgo.RegisterStrategy(ID, &Strategy{})
}
type Strategy struct {
Environment *bbgo.Environment
Market types.Market
Symbol string `json:"symbol"`
Interval types.Interval `json:"interval"`
}
func (s *Strategy) ID() string {
return ID
}
func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) {
for _, session := range sessions {
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval})
}
}
func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, sessions map[string]*bbgo.ExchangeSession) error {
bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
bbgo.Sync(ctx, s)
})
for _, session := range sessions {
session.MarketDataStream.OnKLineClosed(func(kline types.KLine) {
log.Infof("session: %s, kline: %s", session.Exchange.Name().String(), kline.String())
})
}
return nil
}