From 8b2c94f70e10cbb9e148bf88d57933607959e536 Mon Sep 17 00:00:00 2001 From: khcchiu <37725541+khcchiu@users.noreply.github.com> Date: Thu, 30 Sep 2021 13:33:56 +0800 Subject: [PATCH] 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 --- exchanges/coinbasepro/coinbasepro_test.go | 16 +++++++++++++ exchanges/coinbasepro/coinbasepro_wrapper.go | 25 +++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/exchanges/coinbasepro/coinbasepro_test.go b/exchanges/coinbasepro/coinbasepro_test.go index aa592d33..ee0565db 100644 --- a/exchanges/coinbasepro/coinbasepro_test.go +++ b/exchanges/coinbasepro/coinbasepro_test.go @@ -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 diff --git a/exchanges/coinbasepro/coinbasepro_wrapper.go b/exchanges/coinbasepro/coinbasepro_wrapper.go index 950ed195..05bf9e8d 100644 --- a/exchanges/coinbasepro/coinbasepro_wrapper.go +++ b/exchanges/coinbasepro/coinbasepro_wrapper.go @@ -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, }) }