From 5a4a2db66f991b7d11bc040cdd61b5e229598f4a Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 1 Jun 2022 15:52:45 +0800 Subject: [PATCH] service: add time function --- pkg/service/margin.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pkg/service/margin.go b/pkg/service/margin.go index 536a7b37d..302699fc3 100644 --- a/pkg/service/margin.go +++ b/pkg/service/margin.go @@ -2,7 +2,6 @@ package service import ( "context" - "fmt" "strconv" "time" @@ -20,17 +19,17 @@ type MarginService struct { func (s *MarginService) Sync(ctx context.Context, ex types.Exchange, asset string, startTime time.Time) error { api, ok := ex.(types.MarginHistory) if !ok { - return ErrNotImplemented + return nil } marginExchange, ok := ex.(types.MarginExchange) if !ok { - return fmt.Errorf("%T does not implement margin service", ex) + return nil } marginSettings := marginExchange.GetMarginSettings() if !marginSettings.IsMargin { - return fmt.Errorf("exchange instance %s is not using margin", ex.Name()) + return nil } tasks := []SyncTask{ @@ -43,6 +42,9 @@ func (s *MarginService) Sync(ctx context.Context, ex types.Exchange, asset strin } return query.Query(ctx, asset, startTime, endTime) }, + Time: func(obj interface{}) time.Time { + return obj.(types.MarginLoan).Time.Time() + }, ID: func(obj interface{}) string { return strconv.FormatUint(obj.(types.MarginLoan).TransactionID, 10) }, @@ -56,6 +58,9 @@ func (s *MarginService) Sync(ctx context.Context, ex types.Exchange, asset strin } return query.Query(ctx, asset, startTime, endTime) }, + Time: func(obj interface{}) time.Time { + return obj.(types.MarginRepay).Time.Time() + }, ID: func(obj interface{}) string { return strconv.FormatUint(obj.(types.MarginRepay).TransactionID, 10) }, @@ -69,6 +74,9 @@ func (s *MarginService) Sync(ctx context.Context, ex types.Exchange, asset strin } return query.Query(ctx, asset, startTime, endTime) }, + Time: func(obj interface{}) time.Time { + return obj.(types.MarginInterest).Time.Time() + }, ID: func(obj interface{}) string { m := obj.(types.MarginInterest) return m.Asset + m.IsolatedSymbol + strconv.FormatInt(m.Time.UnixMilli(), 10) @@ -83,6 +91,9 @@ func (s *MarginService) Sync(ctx context.Context, ex types.Exchange, asset strin } return query.Query(ctx, startTime, endTime) }, + Time: func(obj interface{}) time.Time { + return obj.(types.MarginLiquidation).UpdatedTime.Time() + }, ID: func(obj interface{}) string { m := obj.(types.MarginLiquidation) return strconv.FormatUint(m.OrderID, 10) @@ -130,4 +141,3 @@ func SelectLastMarginLiquidations(ex types.ExchangeName, limit uint64) sq.Select OrderBy("time"). Limit(limit) } -