Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: [xdepthmaker] add disableHedge option and put profix fixer before Initialize() #1562

Merged
merged 4 commits into from Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 20 additions & 16 deletions pkg/strategy/xdepthmaker/strategy.go
Expand Up @@ -181,6 +181,8 @@ type Strategy struct {
// MaxExposurePosition defines the unhedged quantity of stop
MaxExposurePosition fixedpoint.Value `json:"maxExposurePosition"`

DisableHedge bool `json:"disableHedge"`

NotifyTrade bool `json:"notifyTrade"`

// RecoverTrade tries to find the missing trades via the REStful API
Expand Down Expand Up @@ -267,11 +269,11 @@ func (s *Strategy) Validate() error {

func (s *Strategy) Defaults() error {
if s.UpdateInterval == 0 {
s.UpdateInterval = types.Duration(time.Second)
s.UpdateInterval = types.Duration(5 * time.Second)
}

if s.FullReplenishInterval == 0 {
s.FullReplenishInterval = types.Duration(15 * time.Minute)
s.FullReplenishInterval = types.Duration(10 * time.Minute)
}

if s.HedgeInterval == 0 {
Expand Down Expand Up @@ -317,19 +319,6 @@ func (s *Strategy) CrossRun(

log.Infof("makerSession: %s hedgeSession: %s", makerSession.Name, hedgeSession.Name)

if err := s.CrossExchangeMarketMakingStrategy.Initialize(ctx, s.Environment, makerSession, hedgeSession, s.Symbol, ID, s.InstanceID()); err != nil {
return err
}

s.pricingBook = types.NewStreamBook(s.Symbol)
s.pricingBook.BindStream(s.hedgeSession.MarketDataStream)

s.stopC = make(chan struct{})

s.authedC = make(chan struct{}, 5)
bindAuthSignal(ctx, s.makerSession.UserDataStream, s.authedC)
bindAuthSignal(ctx, s.hedgeSession.UserDataStream, s.authedC)

if s.ProfitFixerConfig != nil {
if s.ProfitFixerConfig.TradesSince.Time().IsZero() {
return errors.New("tradesSince time can not be zero")
Expand All @@ -347,6 +336,19 @@ func (s *Strategy) CrossRun(
}
}

if err := s.CrossExchangeMarketMakingStrategy.Initialize(ctx, s.Environment, makerSession, hedgeSession, s.Symbol, ID, s.InstanceID()); err != nil {
return err
}

s.pricingBook = types.NewStreamBook(s.Symbol)
s.pricingBook.BindStream(s.hedgeSession.MarketDataStream)

s.stopC = make(chan struct{})

s.authedC = make(chan struct{}, 5)
bindAuthSignal(ctx, s.makerSession.UserDataStream, s.authedC)
bindAuthSignal(ctx, s.hedgeSession.UserDataStream, s.authedC)

if s.RecoverTrade {
go s.runTradeRecover(ctx)
}
Expand Down Expand Up @@ -441,7 +443,9 @@ func (s *Strategy) CrossRun(
uncoverPosition,
)

s.Hedge(ctx, uncoverPosition.Neg())
if !s.DisableHedge {
s.Hedge(ctx, uncoverPosition.Neg())
}
}
}
}
Expand Down