diff --git a/config/sync.yaml b/config/sync.yaml index fc05b1006..b1cba855c 100644 --- a/config/sync.yaml +++ b/config/sync.yaml @@ -8,14 +8,6 @@ sessions: exchange: max envVarPrefix: max - okex: - exchange: okex - envVarPrefix: okex - - kucoin: - exchange: kucoin - envVarPrefix: kucoin - sync: # userDataStream is used to sync the trading data in real-time # it uses the websocket connection to insert the trades diff --git a/pkg/bbgo/config.go b/pkg/bbgo/config.go index 81a5a1dd1..ceea5a9ad 100644 --- a/pkg/bbgo/config.go +++ b/pkg/bbgo/config.go @@ -187,6 +187,15 @@ type SyncConfig struct { // Symbols is the list of symbol to sync, if ignored, symbols wlll be discovered by your existing crypto balances Symbols []string `json:"symbols,omitempty" yaml:"symbols,omitempty"` + // DepositHistory for syncing deposit history + DepositHistory bool `json:"depositHistory" yaml:"depositHistory"` + + // WithdrawHistory for syncing withdraw history + WithdrawHistory bool `json:"withdrawHistory" yaml:"withdrawHistory"` + + // RewardHistory for syncing reward history + RewardHistory bool `json:"rewardHistory" yaml:"rewardHistory"` + // Since is the date where you want to start syncing data Since *types.LooseFormatTime `json:"since,omitempty"` diff --git a/pkg/bbgo/environment.go b/pkg/bbgo/environment.go index 4c06d2cc5..e328e396d 100644 --- a/pkg/bbgo/environment.go +++ b/pkg/bbgo/environment.go @@ -561,11 +561,31 @@ func (environ *Environment) Sync(ctx context.Context, userConfig ...*Config) err if len(selectedSessions) > 0 { sessions = environ.SelectSessions(selectedSessions...) } + for _, session := range sessions { if err := environ.syncSession(ctx, session, syncSymbols...); err != nil { return err } + + if userConfig[0].Sync.DepositHistory { + if err := environ.SyncService.SyncDepositHistory(ctx, session.Exchange); err != nil { + return err + } + } + + if userConfig[0].Sync.WithdrawHistory { + if err := environ.SyncService.SyncWithdrawHistory(ctx, session.Exchange); err != nil { + return err + } + } + + if userConfig[0].Sync.RewardHistory { + if err := environ.SyncService.SyncRewardHistory(ctx, session.Exchange); err != nil { + return err + } + } } + return nil } @@ -574,6 +594,24 @@ func (environ *Environment) Sync(ctx context.Context, userConfig ...*Config) err if err := environ.syncSession(ctx, session); err != nil { return err } + + if userConfig[0].Sync.DepositHistory { + if err := environ.SyncService.SyncDepositHistory(ctx, session.Exchange); err != nil { + return err + } + } + + if userConfig[0].Sync.WithdrawHistory { + if err := environ.SyncService.SyncWithdrawHistory(ctx, session.Exchange); err != nil { + return err + } + } + + if userConfig[0].Sync.RewardHistory { + if err := environ.SyncService.SyncRewardHistory(ctx, session.Exchange); err != nil { + return err + } + } } return nil diff --git a/pkg/exchange/max/maxapi/account.go b/pkg/exchange/max/maxapi/account.go index 2d7ad6ef0..b1c4d4d13 100644 --- a/pkg/exchange/max/maxapi/account.go +++ b/pkg/exchange/max/maxapi/account.go @@ -128,7 +128,7 @@ type Deposit struct { type GetDepositHistoryRequest struct { client requestgen.AuthenticatedAPIClient - currency *string `param:"currency"` + currency *string `param:"currency"` from *int64 `param:"from"` // seconds to *int64 `param:"to"` // seconds state *string `param:"state"` // submitting, submitted, rejected, accepted, checking, refunded, canceled, suspect diff --git a/pkg/service/sync.go b/pkg/service/sync.go index 5a072a0a9..5db3b549b 100644 --- a/pkg/service/sync.go +++ b/pkg/service/sync.go @@ -54,24 +54,38 @@ func (s *SyncService) SyncSessionSymbols(ctx context.Context, exchange types.Exc return nil } - log.Infof("syncing %s deposit records...", exchange.Name()) - if err := s.DepositService.Sync(ctx, exchange); err != nil { - if err != ErrNotImplemented { - return err - } - } - - log.Infof("syncing %s withdraw records...", exchange.Name()) - if err := s.WithdrawService.Sync(ctx, exchange); err != nil { - if err != ErrNotImplemented { - return err - } - } + return nil +} +func (s *SyncService) SyncRewardHistory(ctx context.Context, exchange types.Exchange) error { log.Infof("syncing %s reward records...", exchange.Name()) if err := s.RewardService.Sync(ctx, exchange); err != nil { if err != ErrExchangeRewardServiceNotImplemented { - log.Infof("%s reward service is not supported", exchange.Name()) + log.Warnf("%s reward service is not supported", exchange.Name()) + return err + } + } + + return nil +} + +func (s *SyncService) SyncDepositHistory(ctx context.Context, exchange types.Exchange) error { + log.Infof("syncing %s deposit records...", exchange.Name()) + if err := s.DepositService.Sync(ctx, exchange); err != nil { + if err != ErrNotImplemented { + log.Warnf("%s deposit service is not supported", exchange.Name()) + return err + } + } + + return nil +} + +func (s *SyncService) SyncWithdrawHistory(ctx context.Context, exchange types.Exchange) error { + log.Infof("syncing %s withdraw records...", exchange.Name()) + if err := s.WithdrawService.Sync(ctx, exchange); err != nil { + if err != ErrNotImplemented { + log.Warnf("%s withdraw service is not supported", exchange.Name()) return err } } diff --git a/pkg/types/order.go b/pkg/types/order.go index 7b747ab79..076327f19 100644 --- a/pkg/types/order.go +++ b/pkg/types/order.go @@ -240,7 +240,7 @@ func (o Order) String() string { orderID = strconv.FormatUint(o.OrderID, 10) } - return fmt.Sprintf("ORDER %s %s %s %s %s/%s @ %s -> %s", + return fmt.Sprintf("ORDER %s %s %s %s %s/%s @ %s -> %s %s", o.Exchange.String(), orderID, o.Symbol, @@ -248,7 +248,7 @@ func (o Order) String() string { o.ExecutedQuantity.String(), o.Quantity.String(), o.Price.String(), - o.Status) + o.Status, o.CreationTime.Time().Format(time.RFC1123)) } // PlainText is used for telegram-styled messages