mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
add xtemplate strategy
This commit is contained in:
parent
2058ce808b
commit
01ecb58536
14
config/xtemplate.yaml
Normal file
14
config/xtemplate.yaml
Normal file
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
sessions:
|
||||
max:
|
||||
exchange: max
|
||||
envVarPrefix: max
|
||||
|
||||
binance:
|
||||
exchange: binance
|
||||
envVarPrefix: binance
|
||||
|
||||
crossExchangeStrategies:
|
||||
- xtemplate:
|
||||
symbol: BTCUSDT
|
||||
interval: 1m
|
|
@ -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"
|
||||
)
|
||||
|
|
51
pkg/strategy/xtemplate/strategy.go
Normal file
51
pkg/strategy/xtemplate/strategy.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user