mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
Merge pull request #1439 from c9s/feature/maxapi/get-closed-orders
FIX: fix list closed orders api limit
This commit is contained in:
commit
b79bd8e48b
|
@ -270,18 +270,34 @@ func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders [
|
|||
return orders, err
|
||||
}
|
||||
|
||||
// lastOrderID is not supported on MAX
|
||||
func (e *Exchange) QueryClosedOrders(
|
||||
ctx context.Context, symbol string, since, until time.Time, lastOrderID uint64,
|
||||
) ([]types.Order, error) {
|
||||
log.Warn("!!!MAX EXCHANGE API NOTICE!!! the since/until conditions will not be effected on closed orders query, max exchange does not support time-range-based query")
|
||||
if !since.IsZero() || !until.IsZero() {
|
||||
return e.queryClosedOrdersByTime(ctx, symbol, since, until)
|
||||
return e.queryClosedOrdersByTime(ctx, symbol, since, until, maxapi.OrderByAsc)
|
||||
}
|
||||
|
||||
return e.queryClosedOrdersByLastOrderID(ctx, symbol, lastOrderID)
|
||||
}
|
||||
|
||||
func (e *Exchange) QueryClosedOrdersDesc(
|
||||
ctx context.Context, symbol string, since, until time.Time, lastOrderID uint64,
|
||||
) ([]types.Order, error) {
|
||||
closedOrders, err := e.queryClosedOrdersByTime(ctx, symbol, since, until, maxapi.OrderByDesc)
|
||||
if lastOrderID == 0 {
|
||||
return closedOrders, err
|
||||
}
|
||||
|
||||
var filterClosedOrders []types.Order
|
||||
for _, closedOrder := range closedOrders {
|
||||
if closedOrder.OrderID > lastOrderID {
|
||||
filterClosedOrders = append(filterClosedOrders, closedOrder)
|
||||
}
|
||||
}
|
||||
|
||||
return filterClosedOrders, err
|
||||
}
|
||||
|
||||
func (e *Exchange) queryClosedOrdersByLastOrderID(
|
||||
ctx context.Context, symbol string, lastOrderID uint64,
|
||||
) (orders []types.Order, err error) {
|
||||
|
@ -325,11 +341,24 @@ func (e *Exchange) queryClosedOrdersByLastOrderID(
|
|||
return types.SortOrdersAscending(orders), nil
|
||||
}
|
||||
|
||||
func (e *Exchange) queryClosedOrdersByTime(ctx context.Context, symbol string, since, until time.Time) (orders []types.Order, err error) {
|
||||
func (e *Exchange) queryClosedOrdersByTime(ctx context.Context, symbol string, since, until time.Time, orderByType maxapi.OrderByType) (orders []types.Order, err error) {
|
||||
if err := e.closedOrderQueryLimiter.Wait(ctx); err != nil {
|
||||
return orders, err
|
||||
}
|
||||
|
||||
// there is since limit for closed orders API. If the since is before launch date, it will respond error
|
||||
sinceLimit, err := e.getLaunchDate()
|
||||
if err != nil {
|
||||
return orders, err
|
||||
}
|
||||
if since.Before(sinceLimit) {
|
||||
since = sinceLimit
|
||||
}
|
||||
|
||||
if until.IsZero() {
|
||||
until = time.Now()
|
||||
}
|
||||
|
||||
market := toLocalSymbol(symbol)
|
||||
walletType := maxapi.WalletTypeSpot
|
||||
if e.MarginSettings.IsMargin {
|
||||
|
@ -338,9 +367,23 @@ func (e *Exchange) queryClosedOrdersByTime(ctx context.Context, symbol string, s
|
|||
|
||||
req := e.v3client.NewGetWalletClosedOrdersRequest(walletType).
|
||||
Market(market).
|
||||
Timestamp(since).
|
||||
Limit(1000).
|
||||
OrderBy(maxapi.OrderByAsc)
|
||||
OrderBy(orderByType)
|
||||
|
||||
switch orderByType {
|
||||
case maxapi.OrderByAsc:
|
||||
req.Timestamp(since)
|
||||
case maxapi.OrderByDesc:
|
||||
req.Timestamp(until)
|
||||
case maxapi.OrderByAscUpdatedAt:
|
||||
// not implement yet
|
||||
return nil, fmt.Errorf("unsupported order by type: %s", orderByType)
|
||||
case maxapi.OrderByDescUpdatedAt:
|
||||
// not implement yet
|
||||
return nil, fmt.Errorf("unsupported order by type: %s", orderByType)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported order by type: %s", orderByType)
|
||||
}
|
||||
|
||||
maxOrders, err := req.Do(ctx)
|
||||
if err != nil {
|
||||
|
@ -348,9 +391,11 @@ func (e *Exchange) queryClosedOrdersByTime(ctx context.Context, symbol string, s
|
|||
}
|
||||
|
||||
for _, maxOrder := range maxOrders {
|
||||
if maxOrder.CreatedAt.Time().After(until) {
|
||||
createdAt := maxOrder.CreatedAt.Time()
|
||||
if createdAt.Before(since) || createdAt.After(until) {
|
||||
continue
|
||||
}
|
||||
|
||||
order, err2 := toGlobalOrder(maxOrder)
|
||||
if err2 != nil {
|
||||
err = multierr.Append(err, err2)
|
||||
|
|
Loading…
Reference in New Issue
Block a user