Skip to content

Commit

Permalink
Improvements & Appeasements
Browse files Browse the repository at this point in the history
  • Loading branch information
cranktakular committed Jun 11, 2024
1 parent eec8a5d commit bbcc27b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
3 changes: 1 addition & 2 deletions currency/pairs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
32 changes: 20 additions & 12 deletions exchanges/coinbasepro/coinbasepro.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions exchanges/coinbasepro/coinbasepro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion exchanges/coinbasepro/coinbasepro_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ func (c *CoinbasePro) generateSubscriptions() (subscription.List, error) {
Pairs: enabledPairs,
Asset: asset.Spot,
})

}
return subscriptions, nil
}
Expand Down
4 changes: 2 additions & 2 deletions exchanges/coinbasepro/coinbasepro_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit bbcc27b

Please sign in to comment.