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:
Ryan O'Hara-Reid
2022-10-24 13:28:32 +11:00
committed by GitHub
parent 4e135c9590
commit 558a70e87f
65 changed files with 705 additions and 617 deletions

View File

@@ -623,6 +623,7 @@ func TestGetActiveOrders(t *testing.T) {
var getOrdersRequest = order.GetOrdersRequest{
Type: order.AnyType,
AssetType: asset.Spot,
Side: order.AnySide,
}
_, err := b.GetActiveOrders(context.Background(), &getOrdersRequest)
@@ -636,10 +637,10 @@ func TestGetActiveOrders(t *testing.T) {
func TestGetOrderHistory(t *testing.T) {
t.Parallel()
var getOrdersRequest = order.GetOrdersRequest{
Type: order.AnyType,
Pairs: []currency.Pair{currency.NewPair(currency.LTC,
currency.BTC)},
Type: order.AnyType,
Pairs: []currency.Pair{currency.NewPair(currency.LTC, currency.BTC)},
AssetType: asset.Spot,
Side: order.AnySide,
}
_, err := b.GetOrderHistory(context.Background(), &getOrdersRequest)

View File

@@ -797,8 +797,9 @@ func (b *Bitmex) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuild
// GetActiveOrders retrieves any orders that are active/open
// This function is not concurrency safe due to orderSide/orderType maps
func (b *Bitmex) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
if err := req.Validate(); err != nil {
func (b *Bitmex) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) (order.FilteredOrders, error) {
err := req.Validate()
if err != nil {
return nil, err
}
@@ -845,22 +846,15 @@ func (b *Bitmex) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
orders[i] = orderDetail
}
order.FilterOrdersBySide(&orders, req.Side)
order.FilterOrdersByType(&orders, req.Type)
err = order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
if err != nil {
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
}
order.FilterOrdersByPairs(&orders, req.Pairs)
return orders, nil
return req.Filter(b.Name, orders), nil
}
// GetOrderHistory retrieves account order information
// Can Limit response to specific order status
// This function is not concurrency safe due to orderSide/orderType maps
func (b *Bitmex) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
if err := req.Validate(); err != nil {
func (b *Bitmex) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) (order.FilteredOrders, error) {
err := req.Validate()
if err != nil {
return nil, err
}
@@ -911,15 +905,7 @@ func (b *Bitmex) GetOrderHistory(ctx context.Context, req *order.GetOrdersReques
orders[i] = orderDetail
}
order.FilterOrdersBySide(&orders, req.Side)
order.FilterOrdersByType(&orders, req.Type)
err = order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
if err != nil {
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
}
order.FilterOrdersByPairs(&orders, req.Pairs)
return orders, nil
return req.Filter(b.Name, orders), nil
}
// AuthenticateWebsocket sends an authentication message to the websocket