mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-01 23:16:51 +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:
@@ -368,6 +368,7 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
currency.NewPair(currency.LTC, currency.BTC),
|
||||
},
|
||||
AssetType: asset.Spot,
|
||||
Side: order.AnySide,
|
||||
}
|
||||
|
||||
_, err := g.GetActiveOrders(context.Background(), &getOrdersRequest)
|
||||
@@ -387,6 +388,7 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
Type: order.AnyType,
|
||||
Pairs: []currency.Pair{currency.NewPair(currency.LTC, currency.BTC)},
|
||||
AssetType: asset.Spot,
|
||||
Side: order.AnySide,
|
||||
}
|
||||
|
||||
_, err := g.GetOrderHistory(context.Background(), &getOrdersRequest)
|
||||
|
||||
@@ -676,8 +676,9 @@ func (g *Gemini) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuild
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (g *Gemini) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
func (g *Gemini) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) (order.FilteredOrders, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -729,21 +730,14 @@ func (g *Gemini) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
|
||||
Date: orderDate,
|
||||
}
|
||||
}
|
||||
|
||||
err = order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", g.Name, err)
|
||||
}
|
||||
order.FilterOrdersBySide(&orders, req.Side)
|
||||
order.FilterOrdersByType(&orders, req.Type)
|
||||
order.FilterOrdersByPairs(&orders, req.Pairs)
|
||||
return orders, nil
|
||||
return req.Filter(g.Name, orders), nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (g *Gemini) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
func (g *Gemini) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) (order.FilteredOrders, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -753,14 +747,14 @@ func (g *Gemini) GetOrderHistory(ctx context.Context, req *order.GetOrdersReques
|
||||
|
||||
var trades []TradeHistory
|
||||
for j := range req.Pairs {
|
||||
fpair, err := g.FormatExchangeCurrency(req.Pairs[j], asset.Spot)
|
||||
var fPair currency.Pair
|
||||
fPair, err = g.FormatExchangeCurrency(req.Pairs[j], asset.Spot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := g.GetTradeHistory(ctx,
|
||||
fpair.String(),
|
||||
req.StartTime.Unix())
|
||||
var resp []TradeHistory
|
||||
resp, err = g.GetTradeHistory(ctx, fPair.String(), req.StartTime.Unix())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -805,13 +799,7 @@ func (g *Gemini) 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", g.Name, err)
|
||||
}
|
||||
order.FilterOrdersBySide(&orders, req.Side)
|
||||
return orders, nil
|
||||
return req.Filter(g.Name, orders), nil
|
||||
}
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
|
||||
Reference in New Issue
Block a user