xmaker: check connectivity before calling updateQuote

This commit is contained in:
c9s 2024-10-24 16:12:09 +08:00
parent 738cb24ecb
commit 9f7521b754
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 29 additions and 4 deletions

View File

@ -17,6 +17,8 @@ const (
TransferAssetTypeIsolatedMarginToMain TransferAssetType = "ISOLATED_MARGIN_MAIN" TransferAssetTypeIsolatedMarginToMain TransferAssetType = "ISOLATED_MARGIN_MAIN"
) )
// User Universal Transfer (USER_DATA)
//
//go:generate requestgen -method POST -url "/sapi/v1/asset/transfer" -type TransferAssetRequest -responseType .TransferResponse //go:generate requestgen -method POST -url "/sapi/v1/asset/transfer" -type TransferAssetRequest -responseType .TransferResponse
type TransferAssetRequest struct { type TransferAssetRequest struct {
client requestgen.AuthenticatedAPIClient client requestgen.AuthenticatedAPIClient

View File

@ -232,6 +232,7 @@ type Strategy struct {
metricsLabels prometheus.Labels metricsLabels prometheus.Labels
sourceMarketDataConnectivity, sourceUserDataConnectivity *types.Connectivity
connectivityGroup *types.ConnectivityGroup connectivityGroup *types.ConnectivityGroup
// lastAggregatedSignal stores the last aggregated signal with mutex // lastAggregatedSignal stores the last aggregated signal with mutex
@ -599,6 +600,10 @@ func (s *Strategy) updateQuote(ctx context.Context) error {
return nil return nil
} }
if !s.sourceMarketDataConnectivity.IsConnected() || !s.sourceUserDataConnectivity.IsConnected() {
return nil
}
signal, err := s.aggregateSignal(ctx) signal, err := s.aggregateSignal(ctx)
if err != nil { if err != nil {
return err return err
@ -1442,6 +1447,7 @@ func (s *Strategy) quoteWorker(ctx context.Context) {
return return
case <-ticker.C: case <-ticker.C:
if err := s.updateQuote(ctx); err != nil { if err := s.updateQuote(ctx); err != nil {
s.logger.WithError(err).Errorf("unable to place maker orders") s.logger.WithError(err).Errorf("unable to place maker orders")
} }
@ -1810,10 +1816,13 @@ func (s *Strategy) CrossRun(
s.stopC = make(chan struct{}) s.stopC = make(chan struct{})
sourceConnectivity := types.NewConnectivity() s.sourceUserDataConnectivity = types.NewConnectivity()
sourceConnectivity.Bind(s.sourceSession.UserDataStream) s.sourceUserDataConnectivity.Bind(s.sourceSession.UserDataStream)
s.connectivityGroup = types.NewConnectivityGroup(sourceConnectivity) s.sourceMarketDataConnectivity = types.NewConnectivity()
s.sourceMarketDataConnectivity.Bind(s.sourceSession.MarketDataStream)
s.connectivityGroup = types.NewConnectivityGroup(s.sourceUserDataConnectivity)
go func() { go func() {
s.logger.Infof("waiting for authentication connections to be ready...") s.logger.Infof("waiting for authentication connections to be ready...")

View File

@ -127,6 +127,20 @@ func NewConnectivity() *Connectivity {
} }
} }
func (c *Connectivity) IsConnected() (conn bool) {
c.mu.Lock()
conn = c.connected
c.mu.Unlock()
return conn
}
func (c *Connectivity) IsAuthed() (authed bool) {
c.mu.Lock()
authed = c.authed
c.mu.Unlock()
return authed
}
func (c *Connectivity) handleConnect() { func (c *Connectivity) handleConnect() {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()