mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-14 19:13:52 +00:00
xmaker: check connectivity before calling updateQuote
This commit is contained in:
parent
738cb24ecb
commit
9f7521b754
|
@ -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
|
||||||
|
|
|
@ -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...")
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user