mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
cmd: handle user config sync options in the run command
This commit is contained in:
parent
0d0d8b05bf
commit
70f02a1c19
|
@ -492,7 +492,7 @@ func (environ *Environment) setSyncing(status SyncStatus) {
|
|||
}
|
||||
|
||||
// Sync syncs all registered exchange sessions
|
||||
func (environ *Environment) Sync(ctx context.Context) error {
|
||||
func (environ *Environment) Sync(ctx context.Context, userConfig ...*Config) error {
|
||||
if environ.SyncService == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -503,6 +503,23 @@ func (environ *Environment) Sync(ctx context.Context) error {
|
|||
environ.setSyncing(Syncing)
|
||||
defer environ.setSyncing(SyncDone)
|
||||
|
||||
// sync by the defined user config
|
||||
if len(userConfig) > 0 && userConfig[0] != nil && userConfig[0].Sync != nil {
|
||||
syncSymbols := userConfig[0].Sync.Symbols
|
||||
sessions := environ.sessions
|
||||
selectedSessions := userConfig[0].Sync.Sessions
|
||||
if len(selectedSessions) > 0 {
|
||||
sessions = environ.SelectSessions(selectedSessions...)
|
||||
}
|
||||
for _, session := range sessions {
|
||||
if err := environ.syncSession(ctx, session, syncSymbols...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// the default sync logics
|
||||
for _, session := range environ.sessions {
|
||||
if err := environ.syncSession(ctx, session); err != nil {
|
||||
return err
|
||||
|
|
|
@ -131,7 +131,7 @@ func runConfig(basectx context.Context, userConfig *bbgo.Config, enableWebServer
|
|||
return err
|
||||
}
|
||||
|
||||
if err := environ.Sync(ctx); err != nil {
|
||||
if err := environ.Sync(ctx, userConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user