-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
service: implement margin service for syncing margin related data
- Loading branch information
Showing
14 changed files
with
392 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package batch | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
"time" | ||
|
||
"golang.org/x/time/rate" | ||
|
||
"github.com/c9s/bbgo/pkg/types" | ||
) | ||
|
||
type MarginLiquidationBatchQuery struct { | ||
types.MarginHistory | ||
} | ||
|
||
func (e *MarginLiquidationBatchQuery) Query(ctx context.Context, startTime, endTime time.Time) (c chan types.MarginLiquidation, errC chan error) { | ||
query := &AsyncTimeRangedBatchQuery{ | ||
Type: types.MarginLiquidation{}, | ||
Limiter: rate.NewLimiter(rate.Every(5*time.Second), 2), | ||
Q: func(startTime, endTime time.Time) (interface{}, error) { | ||
return e.QueryLiquidationHistory(ctx, &startTime, &endTime) | ||
}, | ||
T: func(obj interface{}) time.Time { | ||
return time.Time(obj.(types.MarginLiquidation).UpdatedTime) | ||
}, | ||
ID: func(obj interface{}) string { | ||
liquidation := obj.(types.MarginLiquidation) | ||
return strconv.FormatUint(liquidation.OrderID, 10) | ||
}, | ||
} | ||
|
||
c = make(chan types.MarginLiquidation, 100) | ||
errC = query.Query(ctx, c, startTime, endTime) | ||
return c, errC | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.