mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 15:11:03 +00:00
orders: add Filter() method to GetOrdersRequest and force FilteredOrders return type on wrapper functions (#1055)
* orders: filter options return on validate * exchanges: force filter usage by wrapper return type and shift method functionality * exchanges: update tests and fix err shadow * exchanges: shadowland * exchanges: more shadow land spookyness * glorious: nits and ftx upgrade * linter: fix * orders: preserve unpopulated fields through filtering operation * glorious: nits Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
@@ -293,6 +293,7 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
Type: order.AnyType,
|
||||
Pairs: []currency.Pair{currency.NewPair(currency.ETH, currency.BTC)},
|
||||
AssetType: asset.Spot,
|
||||
Side: order.AnySide,
|
||||
}
|
||||
|
||||
_, err := h.GetActiveOrders(context.Background(), &getOrdersRequest)
|
||||
@@ -308,6 +309,7 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
Pairs: []currency.Pair{currency.NewPair(currency.ETH, currency.BTC)},
|
||||
Side: order.AnySide,
|
||||
}
|
||||
|
||||
_, err := h.GetOrderHistory(context.Background(), &getOrdersRequest)
|
||||
|
||||
@@ -723,8 +723,9 @@ func (h *HitBTC) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuild
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (h *HitBTC) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
func (h *HitBTC) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) (order.FilteredOrders, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -734,7 +735,8 @@ func (h *HitBTC) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
|
||||
|
||||
var allOrders []OrderHistoryResponse
|
||||
for i := range req.Pairs {
|
||||
resp, err := h.GetOpenOrders(ctx, req.Pairs[i].String())
|
||||
var resp []OrderHistoryResponse
|
||||
resp, err = h.GetOpenOrders(ctx, req.Pairs[i].String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -769,19 +771,14 @@ func (h *HitBTC) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
|
||||
Pair: symbol,
|
||||
}
|
||||
}
|
||||
|
||||
err = order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", h.Name, err)
|
||||
}
|
||||
order.FilterOrdersBySide(&orders, req.Side)
|
||||
return orders, nil
|
||||
return req.Filter(h.Name, orders), nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (h *HitBTC) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
func (h *HitBTC) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) (order.FilteredOrders, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -791,7 +788,8 @@ func (h *HitBTC) GetOrderHistory(ctx context.Context, req *order.GetOrdersReques
|
||||
|
||||
var allOrders []OrderHistoryResponse
|
||||
for i := range req.Pairs {
|
||||
resp, err := h.GetOrders(ctx, req.Pairs[i].String())
|
||||
var resp []OrderHistoryResponse
|
||||
resp, err = h.GetOrders(ctx, req.Pairs[i].String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -838,13 +836,7 @@ func (h *HitBTC) GetOrderHistory(ctx context.Context, req *order.GetOrdersReques
|
||||
detail.InferCostsAndTimes()
|
||||
orders[i] = detail
|
||||
}
|
||||
|
||||
err = order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", h.Name, err)
|
||||
}
|
||||
order.FilterOrdersBySide(&orders, req.Side)
|
||||
return orders, nil
|
||||
return req.Filter(h.Name, orders), nil
|
||||
}
|
||||
|
||||
// AuthenticateWebsocket sends an authentication message to the websocket
|
||||
|
||||
Reference in New Issue
Block a user