Skip to content

Commit

Permalink
bollmaker: define EMACrossSetting
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Dec 19, 2023
1 parent ec4f43b commit 6a07af8
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions pkg/strategy/bollmaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6a07af8

Please sign in to comment.