mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
strategy/bollmaker: preload dynamic spreads
This commit is contained in:
parent
702ce5220b
commit
fcaa6466b6
|
@ -11,8 +11,7 @@ import (
|
|||
type DynamicSpreadSettings struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// Window is the window of the SMAs of spreads
|
||||
Window int `json:"window"`
|
||||
types.IntervalWindow
|
||||
|
||||
// AskSpreadScale is used to define the ask spread range with the given percentage.
|
||||
AskSpreadScale *bbgo.PercentageScale `json:"askSpreadScale"`
|
||||
|
@ -45,6 +44,19 @@ func (ds *DynamicSpreadSettings) Update(kline types.KLine) {
|
|||
}
|
||||
}
|
||||
|
||||
// Initialize dynamic spreads and preload SMAs
|
||||
func (ds *DynamicSpreadSettings) Initialize(symbol string, session *bbgo.ExchangeSession) {
|
||||
ds.DynamicBidSpread = &indicator.SMA{IntervalWindow: types.IntervalWindow{Interval: ds.Interval, Window: ds.Window}}
|
||||
ds.DynamicAskSpread = &indicator.SMA{IntervalWindow: types.IntervalWindow{Interval: ds.Interval, Window: ds.Window}}
|
||||
|
||||
kLineStore, _ := session.MarketDataStore(symbol)
|
||||
if klines, ok := kLineStore.KLinesOfInterval(ds.Interval); ok {
|
||||
for i := 0; i < len(*klines); i++ {
|
||||
ds.Update((*klines)[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetAskSpread returns current ask spread
|
||||
func (ds *DynamicSpreadSettings) GetAskSpread() (askSpread float64, err error) {
|
||||
if !ds.Enabled {
|
||||
|
|
|
@ -434,8 +434,10 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
|
||||
// Setup dynamic spread
|
||||
if s.DynamicSpread.Enabled {
|
||||
s.DynamicSpread.DynamicBidSpread = &indicator.SMA{IntervalWindow: types.IntervalWindow{Interval: s.Interval, Window: s.DynamicSpread.Window}}
|
||||
s.DynamicSpread.DynamicAskSpread = &indicator.SMA{IntervalWindow: types.IntervalWindow{Interval: s.Interval, Window: s.DynamicSpread.Window}}
|
||||
if s.DynamicSpread.Interval == "" {
|
||||
s.DynamicSpread.Interval = s.Interval
|
||||
}
|
||||
s.DynamicSpread.Initialize(s.Symbol, s.session)
|
||||
}
|
||||
|
||||
if s.DisableShort {
|
||||
|
|
Loading…
Reference in New Issue
Block a user