CoinbasePro: GetOrderHistory pair handling improvements (#789)

* Remove settled from Coinbase Pro order history status

* Get Coinbase Pro order history without restricting currency pair and include price

* Add empty and nil pairs scenario for TestGetOrderHistory

* Include fee and fee asset in Coinbase Pro history order
This commit is contained in:
khcchiu
2021-09-30 13:33:56 +08:00
committed by GitHub
parent a959b6cce6
commit 8b2c94f70e
2 changed files with 35 additions and 6 deletions

View File

@@ -425,6 +425,22 @@ func TestGetOrderHistory(t *testing.T) {
} else if !areTestAPIKeysSet() && err == nil {
t.Error("Expecting an error when no keys are set")
}
getOrdersRequest.Pairs = []currency.Pair{}
_, err = c.GetOrderHistory(context.Background(), &getOrdersRequest)
if areTestAPIKeysSet() && err != nil {
t.Errorf("Could not get order history: %s", err)
} else if !areTestAPIKeysSet() && err == nil {
t.Error("Expecting an error when no keys are set")
}
getOrdersRequest.Pairs = nil
_, err = c.GetOrderHistory(context.Background(), &getOrdersRequest)
if areTestAPIKeysSet() && err != nil {
t.Errorf("Could not get order history: %s", err)
} else if !areTestAPIKeysSet() && err == nil {
t.Error("Expecting an error when no keys are set")
}
}
// Any tests below this line have the ability to impact your orders on the exchange. Enable canManipulateRealOrders to run them

View File

@@ -792,18 +792,28 @@ func (c *CoinbasePro) GetOrderHistory(ctx context.Context, req *order.GetOrdersR
return nil, err
}
var respOrders []GeneralizedOrderResponse
for i := range req.Pairs {
fpair, err := c.FormatExchangeCurrency(req.Pairs[i], asset.Spot)
if err != nil {
return nil, err
if len(req.Pairs) > 0 {
for i := range req.Pairs {
fpair, err := c.FormatExchangeCurrency(req.Pairs[i], asset.Spot)
if err != nil {
return nil, err
}
resp, err := c.GetOrders(ctx,
[]string{"done"},
fpair.String())
if err != nil {
return nil, err
}
respOrders = append(respOrders, resp...)
}
} else {
resp, err := c.GetOrders(ctx,
[]string{"done"},
fpair.String())
"")
if err != nil {
return nil, err
}
respOrders = append(respOrders, resp...)
respOrders = resp
}
format, err := c.GetPairFormat(asset.Spot, false)
@@ -827,8 +837,11 @@ func (c *CoinbasePro) GetOrderHistory(ctx context.Context, req *order.GetOrdersR
ExecutedAmount: respOrders[i].FilledSize,
Type: orderType,
Date: respOrders[i].CreatedAt,
Fee: respOrders[i].FillFees,
FeeAsset: curr.Quote,
Side: orderSide,
Pair: curr,
Price: respOrders[i].Price,
Exchange: c.Name,
})
}