mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
service: add time function
This commit is contained in:
parent
5eaa4706f0
commit
5a4a2db66f
|
@ -2,7 +2,6 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -20,17 +19,17 @@ type MarginService struct {
|
||||||
func (s *MarginService) Sync(ctx context.Context, ex types.Exchange, asset string, startTime time.Time) error {
|
func (s *MarginService) Sync(ctx context.Context, ex types.Exchange, asset string, startTime time.Time) error {
|
||||||
api, ok := ex.(types.MarginHistory)
|
api, ok := ex.(types.MarginHistory)
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrNotImplemented
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
marginExchange, ok := ex.(types.MarginExchange)
|
marginExchange, ok := ex.(types.MarginExchange)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("%T does not implement margin service", ex)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
marginSettings := marginExchange.GetMarginSettings()
|
marginSettings := marginExchange.GetMarginSettings()
|
||||||
if !marginSettings.IsMargin {
|
if !marginSettings.IsMargin {
|
||||||
return fmt.Errorf("exchange instance %s is not using margin", ex.Name())
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks := []SyncTask{
|
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)
|
return query.Query(ctx, asset, startTime, endTime)
|
||||||
},
|
},
|
||||||
|
Time: func(obj interface{}) time.Time {
|
||||||
|
return obj.(types.MarginLoan).Time.Time()
|
||||||
|
},
|
||||||
ID: func(obj interface{}) string {
|
ID: func(obj interface{}) string {
|
||||||
return strconv.FormatUint(obj.(types.MarginLoan).TransactionID, 10)
|
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)
|
return query.Query(ctx, asset, startTime, endTime)
|
||||||
},
|
},
|
||||||
|
Time: func(obj interface{}) time.Time {
|
||||||
|
return obj.(types.MarginRepay).Time.Time()
|
||||||
|
},
|
||||||
ID: func(obj interface{}) string {
|
ID: func(obj interface{}) string {
|
||||||
return strconv.FormatUint(obj.(types.MarginRepay).TransactionID, 10)
|
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)
|
return query.Query(ctx, asset, startTime, endTime)
|
||||||
},
|
},
|
||||||
|
Time: func(obj interface{}) time.Time {
|
||||||
|
return obj.(types.MarginInterest).Time.Time()
|
||||||
|
},
|
||||||
ID: func(obj interface{}) string {
|
ID: func(obj interface{}) string {
|
||||||
m := obj.(types.MarginInterest)
|
m := obj.(types.MarginInterest)
|
||||||
return m.Asset + m.IsolatedSymbol + strconv.FormatInt(m.Time.UnixMilli(), 10)
|
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)
|
return query.Query(ctx, startTime, endTime)
|
||||||
},
|
},
|
||||||
|
Time: func(obj interface{}) time.Time {
|
||||||
|
return obj.(types.MarginLiquidation).UpdatedTime.Time()
|
||||||
|
},
|
||||||
ID: func(obj interface{}) string {
|
ID: func(obj interface{}) string {
|
||||||
m := obj.(types.MarginLiquidation)
|
m := obj.(types.MarginLiquidation)
|
||||||
return strconv.FormatUint(m.OrderID, 10)
|
return strconv.FormatUint(m.OrderID, 10)
|
||||||
|
@ -130,4 +141,3 @@ func SelectLastMarginLiquidations(ex types.ExchangeName, limit uint64) sq.Select
|
||||||
OrderBy("time").
|
OrderBy("time").
|
||||||
Limit(limit)
|
Limit(limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user