bbgo: add environment config for disabling some klines defaults

This commit is contained in:
c9s 2023-11-11 07:42:29 +08:00
parent 28c8fda2db
commit b28b5e4097
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 50 additions and 39 deletions

View File

@ -326,6 +326,11 @@ type ServiceConfig struct {
GoogleSpreadSheetService *GoogleSpreadSheetServiceConfig `json:"googleSpreadSheet" yaml:"googleSpreadSheet"`
}
type EnvironmentConfig struct {
DisableDefaultKLineSubscription bool `json:"disableDefaultKLineSubscription"`
DisableHistoryKLinePreload bool `json:"disableHistoryKLinePreload"`
}
type Config struct {
Build *BuildConfig `json:"build,omitempty" yaml:"build,omitempty"`
@ -343,6 +348,8 @@ type Config struct {
Service *ServiceConfig `json:"services,omitempty" yaml:"services,omitempty"`
Environment *EnvironmentConfig `json:"environment,omitempty" yaml:"environment,omitempty"`
Sessions map[string]*ExchangeSession `json:"sessions,omitempty" yaml:"sessions,omitempty"`
RiskControls *RiskControls `json:"riskControls,omitempty" yaml:"riskControls,omitempty"`

View File

@ -109,12 +109,12 @@ type Environment struct {
syncConfig *SyncConfig
loggingConfig *LoggingConfig
environmentConfig *EnvironmentConfig
sessions map[string]*ExchangeSession
}
func NewEnvironment() *Environment {
now := time.Now()
return &Environment{
// default trade scan time

View File

@ -472,14 +472,17 @@ func (session *ExchangeSession) initSymbol(ctx context.Context, environ *Environ
}
if sub.Symbol == symbol {
klineSubscriptions[types.Interval(sub.Options.Interval)] = struct{}{}
klineSubscriptions[sub.Options.Interval] = struct{}{}
}
}
}
// always subscribe the 1m kline so we can make sure the connection persists.
if !(environ.environmentConfig != nil && environ.environmentConfig.DisableDefaultKLineSubscription) {
// subscribe the 1m kline by default so we can make sure the connection persists.
klineSubscriptions[minInterval] = struct{}{}
}
if !(environ.environmentConfig != nil && environ.environmentConfig.DisableHistoryKLinePreload) {
for interval := range klineSubscriptions {
// avoid querying the last unclosed kline
endTime := environ.startTime
@ -515,6 +518,7 @@ func (session *ExchangeSession) initSymbol(ctx context.Context, environ *Environ
}
log.Infof("%s last price: %v", symbol, session.lastPrices[symbol])
}
session.initializedSymbols[symbol] = struct{}{}
return nil