bollmaker: define EMACrossSetting

This commit is contained in:
c9s 2023-12-19 22:04:24 +08:00
parent ec4f43b100
commit 6a07af80d8
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -6,12 +6,11 @@ import (
"math"
"sync"
indicatorv2 "github.com/c9s/bbgo/pkg/indicator/v2"
"github.com/c9s/bbgo/pkg/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
indicatorv2 "github.com/c9s/bbgo/pkg/indicator/v2"
"github.com/c9s/bbgo/pkg/bbgo"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
@ -46,6 +45,12 @@ type BollingerSetting struct {
BandWidth float64 `json:"bandWidth"`
}
type EMACrossSetting struct {
Interval types.Interval `json:"interval"`
FastWindow int `json:"fastWindow"`
SlowWindow int `json:"slowWindow"`
}
type Strategy struct {
Environment *bbgo.Environment
StandardIndicatorSet *bbgo.StandardIndicatorSet
@ -121,6 +126,9 @@ type Strategy struct {
// BuyBelowNeutralSMA if true, the market maker will only place buy order when the current price is below the neutral band SMA.
BuyBelowNeutralSMA bool `json:"buyBelowNeutralSMA"`
// EMACrossSetting is used for defining ema cross signal to turn on/off buy
EMACrossSetting *EMACrossSetting `json:"emaCross"`
// NeutralBollinger is the smaller range of the bollinger band
// If price is in this band, it usually means the price is oscillating.
// If price goes out of this band, we tend to not place sell orders or buy orders
@ -150,19 +158,16 @@ type Strategy struct {
ShadowProtection bool `json:"shadowProtection"`
ShadowProtectionRatio fixedpoint.Value `json:"shadowProtectionRatio"`
session *bbgo.ExchangeSession
book *types.StreamOrderBook
ExitMethods bbgo.ExitMethodSet `json:"exits"`
// persistence fields
Position *types.Position `json:"position,omitempty" persistence:"position"`
ProfitStats *types.ProfitStats `json:"profitStats,omitempty" persistence:"profit_stats"`
session *bbgo.ExchangeSession
book *types.StreamOrderBook
orderExecutor *bbgo.GeneralOrderExecutor
groupID uint32
// defaultBoll is the BOLLINGER indicator we used for predicting the price.
defaultBoll *indicatorv2.BOLLStream
@ -274,7 +279,6 @@ func (s *Strategy) placeOrders(ctx context.Context, midPrice fixedpoint.Value, k
Quantity: sellQuantity,
Price: askPrice,
Market: s.Market,
GroupID: s.groupID,
}
buyOrder := types.SubmitOrder{
Symbol: s.Symbol,
@ -283,7 +287,6 @@ func (s *Strategy) placeOrders(ctx context.Context, midPrice fixedpoint.Value, k
Quantity: buyQuantity,
Price: bidPrice,
Market: s.Market,
GroupID: s.groupID,
}
var submitOrders []types.SubmitOrder
@ -511,7 +514,6 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
// calculate group id for orders
instanceID := s.InstanceID()
s.groupID = util.FNV32(instanceID)
// If position is nil, we need to allocate a new position for calculation
if s.Position == nil {