From bbcc27b358b3226f47eccf63a956bb1fc4c3abbc Mon Sep 17 00:00:00 2001 From: Samuel Reid <43227667+cranktakular@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:46:36 +1000 Subject: [PATCH] Improvements & Appeasements --- currency/pairs.go | 3 +- exchanges/coinbasepro/coinbasepro.go | 32 ++++++++++++------- exchanges/coinbasepro/coinbasepro_test.go | 5 --- .../coinbasepro/coinbasepro_websocket.go | 1 - exchanges/coinbasepro/coinbasepro_wrapper.go | 4 +-- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/currency/pairs.go b/currency/pairs.go index b2a4d5d2052..b9f1637fe73 100644 --- a/currency/pairs.go +++ b/currency/pairs.go @@ -214,9 +214,8 @@ func (p Pairs) Remove(pair Pair) (Pairs, error) { func (p Pairs) Add(pairs ...Pair) Pairs { for x := range pairs { if p.Contains(pairs[x], true) { - continue + p = append(p, pairs[x]) } - p = append(p, pairs[x]) } return p } diff --git a/exchanges/coinbasepro/coinbasepro.go b/exchanges/coinbasepro/coinbasepro.go index c48d70c510f..8ed674463af 100644 --- a/exchanges/coinbasepro/coinbasepro.go +++ b/exchanges/coinbasepro/coinbasepro.go @@ -212,13 +212,15 @@ func (c *CoinbasePro) GetProductBookV3(ctx context.Context, productID string, li vals.Set("limit", strconv.FormatInt(int64(limit), 10)) } var resp ProductBookResponse + var err error if authenticated { - return &resp.Pricebook, c.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, - coinbaseV3+coinbaseProductBook, vals, nil, true, &resp, nil) + err = c.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, coinbaseV3+coinbaseProductBook, + vals, nil, true, &resp, nil) } else { path := coinbaseV3 + coinbaseMarket + "/" + coinbaseProductBook - return &resp.Pricebook, c.SendHTTPRequest(ctx, exchange.RestSpot, path, vals, &resp) + err = c.SendHTTPRequest(ctx, exchange.RestSpot, path, vals, &resp) } + return &resp.Pricebook, err } // GetAllProducts returns information on all currency pairs that are available for trading @@ -243,13 +245,15 @@ func (c *CoinbasePro) GetAllProducts(ctx context.Context, limit, offset int32, p vals.Add("product_ids", productIDs[x]) } var products AllProducts + var err error if authenticated { - return &products, c.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, - coinbaseV3+coinbaseProducts, vals, nil, true, &products, nil) + err = c.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, coinbaseV3+coinbaseProducts, + vals, nil, true, &products, nil) } else { path := coinbaseV3 + coinbaseMarket + "/" + coinbaseProducts - return &products, c.SendHTTPRequest(ctx, exchange.RestSpot, path, vals, &products) + err = c.SendHTTPRequest(ctx, exchange.RestSpot, path, vals, &products) } + return &products, err } // GetProductByID returns information on a single specified currency pair @@ -258,14 +262,16 @@ func (c *CoinbasePro) GetProductByID(ctx context.Context, productID string, auth return nil, errProductIDEmpty } var resp Product + var err error if authenticated { path := coinbaseV3 + coinbaseProducts + "/" + productID - return &resp, c.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, - path, nil, nil, true, &resp, nil) + err = c.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, path, nil, nil, true, &resp, + nil) } else { path := coinbaseV3 + coinbaseMarket + "/" + coinbaseProducts + "/" + productID - return &resp, c.SendHTTPRequest(ctx, exchange.RestSpot, path, nil, &resp) + err = c.SendHTTPRequest(ctx, exchange.RestSpot, path, nil, &resp) } + return &resp, err } // GetHistoricRates returns historic rates for a product. Rates are returned in @@ -314,14 +320,16 @@ func (c *CoinbasePro) GetTicker(ctx context.Context, productID string, limit uin vals.Set("end", strconv.FormatInt(endDate.Unix(), 10)) } var resp Ticker + var err error if authenticated { path := coinbaseV3 + coinbaseProducts + "/" + productID + "/" + coinbaseTicker - return &resp, c.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, - path, vals, nil, true, &resp, nil) + err = c.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, path, vals, nil, true, &resp, + nil) } else { path := coinbaseV3 + coinbaseMarket + "/" + coinbaseProducts + "/" + productID + "/" + coinbaseTicker - return &resp, c.SendHTTPRequest(ctx, exchange.RestSpot, path, vals, &resp) + err = c.SendHTTPRequest(ctx, exchange.RestSpot, path, vals, &resp) } + return &resp, err } // PlaceOrder places either a limit, market, or stop order diff --git a/exchanges/coinbasepro/coinbasepro_test.go b/exchanges/coinbasepro/coinbasepro_test.go index 2a02ae474a6..8e1724d8fe3 100644 --- a/exchanges/coinbasepro/coinbasepro_test.go +++ b/exchanges/coinbasepro/coinbasepro_test.go @@ -1535,11 +1535,6 @@ func TestWsAuth(t *testing.T) { }, }) assert.NoError(t, err) - // require.NoError(t, err, "Dial must not error") - // go c.wsReadData() - - // err = c.Subscribe(subscription.List{{Channel: "user", Pairs: currency.Pairs{testPair}}}) - // require.NoError(t, err, "Subscribe must not error") timer := time.NewTimer(sharedtestvalues.WebsocketResponseDefaultTimeout) select { case badResponse := <-c.Websocket.DataHandler: diff --git a/exchanges/coinbasepro/coinbasepro_websocket.go b/exchanges/coinbasepro/coinbasepro_websocket.go index 7334178aaf4..51198d11162 100644 --- a/exchanges/coinbasepro/coinbasepro_websocket.go +++ b/exchanges/coinbasepro/coinbasepro_websocket.go @@ -321,7 +321,6 @@ func (c *CoinbasePro) generateSubscriptions() (subscription.List, error) { Pairs: enabledPairs, Asset: asset.Spot, }) - } return subscriptions, nil } diff --git a/exchanges/coinbasepro/coinbasepro_wrapper.go b/exchanges/coinbasepro/coinbasepro_wrapper.go index e2fdb03a6d9..fe5f1cb6c25 100644 --- a/exchanges/coinbasepro/coinbasepro_wrapper.go +++ b/exchanges/coinbasepro/coinbasepro_wrapper.go @@ -200,7 +200,7 @@ func (c *CoinbasePro) FetchTradablePairs(ctx context.Context, a asset.Item) (cur return nil, err } } - var pairs []currency.Pair + pairs := make([]currency.Pair, len(products.Products)) for x := range products.Products { if products.Products[x].TradingDisabled { continue @@ -209,7 +209,7 @@ func (c *CoinbasePro) FetchTradablePairs(ctx context.Context, a asset.Item) (cur if err != nil { return nil, err } - pairs = append(pairs, pair) + pairs[x] = pair } return pairs, nil }