bbgo_origin/pkg/service/sync.go

54 lines
1.2 KiB
Go
Raw Normal View History

package service
import (
"context"
"errors"
"time"
"github.com/c9s/bbgo/pkg/types"
)
var ErrNotImplemented = errors.New("not implemented")
var ErrExchangeRewardServiceNotImplemented = errors.New("exchange does not implement ExchangeRewardService interface")
type SyncService struct {
2021-03-14 03:04:56 +00:00
TradeService *TradeService
OrderService *OrderService
RewardService *RewardService
WithdrawService *WithdrawService
DepositService *DepositService
}
2021-02-19 02:26:13 +00:00
// SyncSessionSymbols syncs the trades from the given exchange session
2021-02-19 02:42:24 +00:00
func (s *SyncService) SyncSessionSymbols(ctx context.Context, exchange types.Exchange, startTime time.Time, symbols ...string) error {
2021-02-19 02:26:13 +00:00
for _, symbol := range symbols {
2021-03-14 03:04:56 +00:00
if err := s.TradeService.Sync(ctx, exchange, symbol); err != nil {
2021-02-19 02:26:13 +00:00
return err
}
2021-03-14 03:04:56 +00:00
if err := s.OrderService.Sync(ctx, exchange, symbol, startTime); err != nil {
2021-02-19 02:26:13 +00:00
return err
}
2021-03-14 03:04:56 +00:00
}
if err := s.DepositService.Sync(ctx, exchange); err != nil {
if err != ErrNotImplemented {
return err
}
}
if err := s.WithdrawService.Sync(ctx, exchange); err != nil {
if err != ErrNotImplemented {
return err
}
}
2021-03-14 03:04:56 +00:00
if err := s.RewardService.Sync(ctx, exchange); err != nil {
if err != ErrExchangeRewardServiceNotImplemented {
return err
}
2021-02-19 02:26:13 +00:00
}
return nil
}