Merge pull request #1441 from c9s/c9s/fix-sync-since-time-override

FIX: fix since time override
This commit is contained in:
c9s 2023-12-08 15:33:48 +08:00 committed by GitHub
commit 0a3269e38e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 13 deletions

View File

@ -139,15 +139,19 @@ the implementation.
## Requirements ## Requirements
Get your exchange API key and secret after you register the accounts (you can choose one or more exchanges): * Go SDK 1.20
- MAX: <https://max.maicoin.com/signup?r=c7982718> * Linux / MacOS / Windows (WSL)
- Binance: <https://accounts.binance.com/en/register?ref=38192708>
- OKEx: <https://www.okex.com/join/2412712?src=from:ios-share>
- Kucoin: <https://www.kucoin.com/ucenter/signup?rcode=r3KX2D4>
This project is maintained and supported by a small group of team. If you would like to support this project, please * Get your exchange API key and secret after you register the accounts (you can choose one or more exchanges):
register on the exchanges using the provided links with referral codes above.
- MAX: <https://max.maicoin.com/signup?r=c7982718>
- Binance: <https://accounts.binance.com/en/register?ref=38192708>
- OKEx: <https://www.okex.com/join/2412712?src=from:ios-share>
- Kucoin: <https://www.kucoin.com/ucenter/signup?rcode=r3KX2D4>
This project is maintained and supported by a small group of team. If you would like to support this project, please
register on the exchanges using the provided links with referral codes above.
## Installation ## Installation

View File

@ -451,11 +451,13 @@ func (environ *Environment) syncWithUserConfig(ctx context.Context, userConfig *
sessions = environ.SelectSessions(selectedSessions...) sessions = environ.SelectSessions(selectedSessions...)
} }
since := time.Now().AddDate(0, -6, 0) since := defaultSyncSinceTime()
if userConfig.Sync.Since != nil { if userConfig.Sync.Since != nil {
since = userConfig.Sync.Since.Time() since = userConfig.Sync.Since.Time()
} }
environ.SetSyncStartTime(since)
syncSymbolMap, restSymbols := categorizeSyncSymbol(userConfig.Sync.Symbols) syncSymbolMap, restSymbols := categorizeSyncSymbol(userConfig.Sync.Symbols)
for _, session := range sessions { for _, session := range sessions {
syncSymbols := restSymbols syncSymbols := restSymbols
@ -463,7 +465,7 @@ func (environ *Environment) syncWithUserConfig(ctx context.Context, userConfig *
syncSymbols = append(syncSymbols, ss...) syncSymbols = append(syncSymbols, ss...)
} }
if err := environ.syncSession(ctx, session, syncSymbols...); err != nil { if err := environ.syncSession(ctx, session, since, syncSymbols...); err != nil {
return err return err
} }
@ -520,8 +522,9 @@ func (environ *Environment) Sync(ctx context.Context, userConfig ...*Config) err
} }
// the default sync logics // the default sync logics
since := defaultSyncSinceTime()
for _, session := range environ.sessions { for _, session := range environ.sessions {
if err := environ.syncSession(ctx, session); err != nil { if err := environ.syncSession(ctx, session, since); err != nil {
return err return err
} }
} }
@ -616,10 +619,13 @@ func (environ *Environment) SyncSession(ctx context.Context, session *ExchangeSe
environ.setSyncing(Syncing) environ.setSyncing(Syncing)
defer environ.setSyncing(SyncDone) defer environ.setSyncing(SyncDone)
return environ.syncSession(ctx, session, defaultSymbols...) since := defaultSyncSinceTime()
return environ.syncSession(ctx, session, since, defaultSymbols...)
} }
func (environ *Environment) syncSession(ctx context.Context, session *ExchangeSession, defaultSymbols ...string) error { func (environ *Environment) syncSession(
ctx context.Context, session *ExchangeSession, syncStartTime time.Time, defaultSymbols ...string,
) error {
symbols, err := session.getSessionSymbols(defaultSymbols...) symbols, err := session.getSessionSymbols(defaultSymbols...)
if err != nil { if err != nil {
return err return err
@ -627,7 +633,7 @@ func (environ *Environment) syncSession(ctx context.Context, session *ExchangeSe
log.Infof("syncing symbols %v from session %s", symbols, session.Name) log.Infof("syncing symbols %v from session %s", symbols, session.Name)
return environ.SyncService.SyncSessionSymbols(ctx, session.Exchange, environ.syncStartTime, symbols...) return environ.SyncService.SyncSessionSymbols(ctx, session.Exchange, syncStartTime, symbols...)
} }
func (environ *Environment) ConfigureNotificationSystem(ctx context.Context, userConfig *Config) error { func (environ *Environment) ConfigureNotificationSystem(ctx context.Context, userConfig *Config) error {
@ -1014,3 +1020,7 @@ func (session *ExchangeSession) getSessionSymbols(defaultSymbols ...string) ([]s
return session.FindPossibleSymbols() return session.FindPossibleSymbols()
} }
func defaultSyncSinceTime() time.Time {
return time.Now().AddDate(0, -6, 0)
}