From 956ad1068384752cf54330aec01b72b49f346fb6 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 9 Oct 2024 11:54:13 +0800 Subject: [PATCH] xmaker: stores calculated signal in lastAggregatedSignal --- pkg/strategy/xmaker/strategy.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pkg/strategy/xmaker/strategy.go b/pkg/strategy/xmaker/strategy.go index c48a9e313..122b3ca4b 100644 --- a/pkg/strategy/xmaker/strategy.go +++ b/pkg/strategy/xmaker/strategy.go @@ -35,6 +35,24 @@ const ID = "xmaker" var log = logrus.WithField("strategy", ID) +type MutexFloat64 struct { + value float64 + mu sync.Mutex +} + +func (m *MutexFloat64) Set(v float64) { + m.mu.Lock() + m.value = v + m.mu.Unlock() +} + +func (m *MutexFloat64) Get() float64 { + m.mu.Lock() + v := m.value + m.mu.Unlock() + return v +} + type Quote struct { BestBidPrice, BestAskPrice fixedpoint.Value @@ -194,6 +212,10 @@ type Strategy struct { metricsLabels prometheus.Labels connectivityGroup *types.ConnectivityGroup + + // lastAggregatedSignal stores the last aggregated signal with mutex + // TODO: use float64 series instead, so that we can store history signal values + lastAggregatedSignal MutexFloat64 } func (s *Strategy) ID() string { @@ -305,6 +327,7 @@ func (s *Strategy) applySignalMargin(ctx context.Context, quote *Quote) error { return err } + s.lastAggregatedSignal.Set(signal) s.logger.Infof("aggregated signal: %f", signal) if signal == 0.0 {