Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions pkg/strategy/xmaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ type StrategyConfig struct {
// the fixed UpdateInterval is used.
AdaptiveQuoteInterval *AdaptiveQuoteInterval `json:"adaptiveQuoteInterval,omitempty"`

// SourceBookUpdateMonitor tracks the source order book's update frequency
// and polls a fresh snapshot via REST when it drops too low.
SourceBookUpdateMonitor *types.StreamBookMonitor `json:"sourceBookUpdateMonitor,omitempty"`

EnableSignalMargin bool `json:"enableSignalMargin"`

// Direction-divergence (D2) control — optional risk widener driven by signal direction conflicts
Expand Down Expand Up @@ -1161,6 +1165,15 @@ func (s *Strategy) updateQuote(ctx context.Context) error {
}

} else {
if s.SourceBookUpdateMonitor != nil && s.SourceBookUpdateMonitor.Enabled && s.SourceBookUpdateMonitor.IsStale(now) {
s.logger.Warnf("source book (%s) is stale, attempting to poll via REST", s.hedgeSession.Name)
if depthService, ok := s.hedgeSession.Exchange.(types.ExchangeDepthQueryService); ok {
if err := s.SourceBookUpdateMonitor.PollUpdate(ctx, depthService); err != nil {
s.logger.WithError(err).Warnf("unable to poll source order book via REST")
}
}
}

bestBid, bestAsk, hasPrice := s.sourceBook.BestBidAndAsk()
if !hasPrice {
s.logger.Warnf("no valid price, skip quoting")
Expand Down Expand Up @@ -2489,6 +2502,12 @@ func (s *Strategy) Defaults() error {
}
}

if s.SourceBookUpdateMonitor != nil && s.SourceBookUpdateMonitor.Enabled {
if err := s.SourceBookUpdateMonitor.Defaults(); err != nil {
return err
}
}

if s.HedgeInterval == 0 {
s.HedgeInterval = types.Duration(10 * time.Second)
}
Expand Down Expand Up @@ -2653,6 +2672,12 @@ func (s *Strategy) Validate() error {
}
}

if s.SourceBookUpdateMonitor != nil && s.SourceBookUpdateMonitor.Enabled {
if err := s.SourceBookUpdateMonitor.Validate(); err != nil {
return err
}
}

if err := registerInstance(s); err != nil {
return err
}
Expand Down Expand Up @@ -3144,6 +3169,10 @@ func (s *Strategy) CrossRun(
s.sourceBook.BindStream(s.sourceBookStream)
s.depthSourceBook = types.NewDepthBook(s.sourceBook)

if s.SourceBookUpdateMonitor != nil && s.SourceBookUpdateMonitor.Enabled {
s.SourceBookUpdateMonitor.Bind(s.sourceBook)
}

s.CircuitBreaker.OnPanic(
func() {
s.gracefulShutDown(context.Background())
Expand Down
Loading