From ce76ad3c0380650801555b33f2688dbafedb5418 Mon Sep 17 00:00:00 2001 From: "chiahung.lin" Date: Mon, 20 Nov 2023 15:32:04 +0800 Subject: [PATCH] use OrderByType --- pkg/exchange/max/exchange.go | 2 +- pkg/exchange/max/maxapi/order.go | 9 +++++++++ .../maxapi/v3/get_wallet_closed_orders_request.go | 8 ++++---- .../get_wallet_closed_orders_request_requestgen.go | 13 +------------ pkg/exchange/max/maxapi/v3/order.go | 1 + 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pkg/exchange/max/exchange.go b/pkg/exchange/max/exchange.go index d28aa0908..583494b07 100644 --- a/pkg/exchange/max/exchange.go +++ b/pkg/exchange/max/exchange.go @@ -339,7 +339,7 @@ func (e *Exchange) queryClosedOrdersByTime(ctx context.Context, symbol string, s for _, maxOrder := range maxOrders { if maxOrder.CreatedAt.Time().Before(since) { - break + continue } order, err2 := toGlobalOrder(maxOrder) if err2 != nil { diff --git a/pkg/exchange/max/maxapi/order.go b/pkg/exchange/max/maxapi/order.go index be3fdb1fe..6f783c33a 100644 --- a/pkg/exchange/max/maxapi/order.go +++ b/pkg/exchange/max/maxapi/order.go @@ -17,6 +17,15 @@ const ( WalletTypeMargin WalletType = "m" ) +type OrderByType string + +const ( + OrderByAsc OrderByType = "asc" + OrderByDesc OrderByType = "desc" + OrderByAscUpdatedAt OrderByType = "asc_updated_at" + OrderByDescUpdatedAt OrderByType = "desc_updated_at" +) + type OrderStateToQuery int const ( diff --git a/pkg/exchange/max/maxapi/v3/get_wallet_closed_orders_request.go b/pkg/exchange/max/maxapi/v3/get_wallet_closed_orders_request.go index 36cd947ca..9ac43eadb 100644 --- a/pkg/exchange/max/maxapi/v3/get_wallet_closed_orders_request.go +++ b/pkg/exchange/max/maxapi/v3/get_wallet_closed_orders_request.go @@ -20,8 +20,8 @@ type GetWalletClosedOrdersRequest struct { walletType WalletType `param:"walletType,slug,required"` - market string `param:"market,required"` - timestamp *time.Time `param:"timestamp,milliseconds,omitempty"` - orderBy *string `param:"order_by,omitempty" validValues:"asc,desc,asc_updated_at,desc_updated_at"` - limit *uint `param:"limit,omitempty"` + market string `param:"market,required"` + timestamp *time.Time `param:"timestamp,milliseconds,omitempty"` + orderBy *OrderByType `param:"order_by,omitempty"` + limit *uint `param:"limit,omitempty"` } diff --git a/pkg/exchange/max/maxapi/v3/get_wallet_closed_orders_request_requestgen.go b/pkg/exchange/max/maxapi/v3/get_wallet_closed_orders_request_requestgen.go index d1d9ec0b1..551f7ee9d 100644 --- a/pkg/exchange/max/maxapi/v3/get_wallet_closed_orders_request_requestgen.go +++ b/pkg/exchange/max/maxapi/v3/get_wallet_closed_orders_request_requestgen.go @@ -24,7 +24,7 @@ func (g *GetWalletClosedOrdersRequest) Timestamp(timestamp time.Time) *GetWallet return g } -func (g *GetWalletClosedOrdersRequest) OrderBy(orderBy string) *GetWalletClosedOrdersRequest { +func (g *GetWalletClosedOrdersRequest) OrderBy(orderBy max.OrderByType) *GetWalletClosedOrdersRequest { g.orderBy = &orderBy return g } @@ -78,17 +78,6 @@ func (g *GetWalletClosedOrdersRequest) GetParameters() (map[string]interface{}, if g.orderBy != nil { orderBy := *g.orderBy - // TEMPLATE check-valid-values - switch orderBy { - case "asc", "desc": - params["order_by"] = orderBy - - default: - return nil, fmt.Errorf("order_by value %v is invalid", orderBy) - - } - // END TEMPLATE check-valid-values - // assign parameter of orderBy params["order_by"] = orderBy } else { diff --git a/pkg/exchange/max/maxapi/v3/order.go b/pkg/exchange/max/maxapi/v3/order.go index 4244857b6..dc3e316a0 100644 --- a/pkg/exchange/max/maxapi/v3/order.go +++ b/pkg/exchange/max/maxapi/v3/order.go @@ -8,6 +8,7 @@ import ( // create type alias type WalletType = maxapi.WalletType +type OrderByType = maxapi.OrderByType type OrderType = maxapi.OrderType type Order = maxapi.Order