service: fix margin sync with asset condition

This commit is contained in:
c9s 2022-12-22 14:10:35 +08:00
parent c59c8638be
commit 1ea72099ed
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -34,7 +34,7 @@ func (s *MarginService) Sync(ctx context.Context, ex types.Exchange, asset strin
tasks := []SyncTask{ tasks := []SyncTask{
{ {
Select: SelectLastMarginLoans(ex.Name(), 100), Select: SelectLastMarginLoans(ex.Name(), asset, 100),
Type: types.MarginLoan{}, Type: types.MarginLoan{},
BatchQuery: func(ctx context.Context, startTime, endTime time.Time) (interface{}, chan error) { BatchQuery: func(ctx context.Context, startTime, endTime time.Time) (interface{}, chan error) {
query := &batch.MarginLoanBatchQuery{ query := &batch.MarginLoanBatchQuery{
@ -51,7 +51,7 @@ func (s *MarginService) Sync(ctx context.Context, ex types.Exchange, asset strin
LogInsert: true, LogInsert: true,
}, },
{ {
Select: SelectLastMarginRepays(ex.Name(), 100), Select: SelectLastMarginRepays(ex.Name(), asset, 100),
Type: types.MarginRepay{}, Type: types.MarginRepay{},
BatchQuery: func(ctx context.Context, startTime, endTime time.Time) (interface{}, chan error) { BatchQuery: func(ctx context.Context, startTime, endTime time.Time) (interface{}, chan error) {
query := &batch.MarginRepayBatchQuery{ query := &batch.MarginRepayBatchQuery{
@ -68,7 +68,7 @@ func (s *MarginService) Sync(ctx context.Context, ex types.Exchange, asset strin
LogInsert: true, LogInsert: true,
}, },
{ {
Select: SelectLastMarginInterests(ex.Name(), 100), Select: SelectLastMarginInterests(ex.Name(), asset, 100),
Type: types.MarginInterest{}, Type: types.MarginInterest{},
BatchQuery: func(ctx context.Context, startTime, endTime time.Time) (interface{}, chan error) { BatchQuery: func(ctx context.Context, startTime, endTime time.Time) (interface{}, chan error) {
query := &batch.MarginInterestBatchQuery{ query := &batch.MarginInterestBatchQuery{
@ -114,26 +114,26 @@ func (s *MarginService) Sync(ctx context.Context, ex types.Exchange, asset strin
return nil return nil
} }
func SelectLastMarginLoans(ex types.ExchangeName, limit uint64) sq.SelectBuilder { func SelectLastMarginLoans(ex types.ExchangeName, asset string, limit uint64) sq.SelectBuilder {
return sq.Select("*"). return sq.Select("*").
From("margin_loans"). From("margin_loans").
Where(sq.Eq{"exchange": ex}). Where(sq.Eq{"exchange": ex, "asset": asset}).
OrderBy("time DESC"). OrderBy("time DESC").
Limit(limit) Limit(limit)
} }
func SelectLastMarginRepays(ex types.ExchangeName, limit uint64) sq.SelectBuilder { func SelectLastMarginRepays(ex types.ExchangeName, asset string, limit uint64) sq.SelectBuilder {
return sq.Select("*"). return sq.Select("*").
From("margin_repays"). From("margin_repays").
Where(sq.Eq{"exchange": ex}). Where(sq.Eq{"exchange": ex, "asset": asset}).
OrderBy("time DESC"). OrderBy("time DESC").
Limit(limit) Limit(limit)
} }
func SelectLastMarginInterests(ex types.ExchangeName, limit uint64) sq.SelectBuilder { func SelectLastMarginInterests(ex types.ExchangeName, asset string, limit uint64) sq.SelectBuilder {
return sq.Select("*"). return sq.Select("*").
From("margin_interests"). From("margin_interests").
Where(sq.Eq{"exchange": ex}). Where(sq.Eq{"exchange": ex, "asset": asset}).
OrderBy("time DESC"). OrderBy("time DESC").
Limit(limit) Limit(limit)
} }