mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: add environment config for disabling some klines defaults
This commit is contained in:
parent
28c8fda2db
commit
b28b5e4097
|
@ -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"`
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user