Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
samuael committed Dec 8, 2024
1 parent 37c89a7 commit bf38fc7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
38 changes: 20 additions & 18 deletions exchanges/coinbaseinternational/coinbaseinternational.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,18 @@ const (
)

var (
errArgumentMustBeInterface = errors.New("argument must be an interface")
errMissingPortfolioID = errors.New("missing portfolio identification")
errNetworkArnID = errors.New("identifies the blockchain network")
errMissingTransferID = errors.New("missing transfer ID")
errAddressIsRequired = errors.New("missing address")
errAssetIdentifierRequired = errors.New("asset identified is required")
errIndexNameRequired = errors.New("index name required")
errGranularityRequired = errors.New("granularity value is required")
errStartTimeRequired = errors.New("start time required")
errEmptyArgument = errors.New("empty argument")
errTimeInForceRequired = errors.New("time_in_force is required")
errInstrumentIdentifierRequired = errors.New("instrument information is required")
errInstrumentTypeRequired = errors.New("instrument type required")
errArgumentMustBeInterface = errors.New("argument must be an interface")
errMissingPortfolioID = errors.New("missing portfolio identification")
errNetworkArnID = errors.New("identifies the blockchain network")
errMissingTransferID = errors.New("missing transfer ID")
errAddressIsRequired = errors.New("missing address")
errAssetIdentifierRequired = errors.New("asset identified is required")
errIndexNameRequired = errors.New("index name required")
errGranularityRequired = errors.New("granularity value is required")
errStartTimeRequired = errors.New("start time required")
errTimeInForceRequired = errors.New("time_in_force is required")
errInstrumentIDRequired = errors.New("instrument information is required")
errInstrumentTypeRequired = errors.New("instrument type required")
)

// ListAssets returns a list of all supported assets.
Expand Down Expand Up @@ -168,7 +167,7 @@ func (co *CoinbaseInternational) GetInstrumentDetails(ctx context.Context, instr
case instrumentID != "":
path += instrumentID
default:
return nil, errInstrumentIdentifierRequired
return nil, errInstrumentIDRequired
}
var resp *InstrumentInfo
return resp, co.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, path, nil, nil, &resp, false)
Expand All @@ -185,7 +184,7 @@ func (co *CoinbaseInternational) GetQuotePerInstrument(ctx context.Context, inst
case instrumentID != "":
path += instrumentID
default:
return nil, errInstrumentIdentifierRequired
return nil, errInstrumentIDRequired
}
var resp *QuoteInformation
return resp, co.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, path+"/quote", nil, nil, &resp, false)
Expand All @@ -194,7 +193,7 @@ func (co *CoinbaseInternational) GetQuotePerInstrument(ctx context.Context, inst
// GetDailyTradingVolumes retrieves the trading volumes for each instrument separated by day
func (co *CoinbaseInternational) GetDailyTradingVolumes(ctx context.Context, instruments []string, resultLimit, resultOffset int64, timeFrom time.Time, showOther bool) (*InstrumentsTradingVolumeInfo, error) {
if len(instruments) == 0 {
return nil, errInstrumentIdentifierRequired
return nil, errInstrumentIDRequired
}
params := url.Values{}
params.Set("instruments", strings.Join(instruments, ","))
Expand All @@ -217,7 +216,7 @@ func (co *CoinbaseInternational) GetDailyTradingVolumes(ctx context.Context, ins
// GetAggregatedCandlesDataPerInstrument retrieves a list of aggregated candles data for a given instrument, granularity and time range
func (co *CoinbaseInternational) GetAggregatedCandlesDataPerInstrument(ctx context.Context, instrument string, granularity kline.Interval, start, end time.Time) (*CandlestickDataHistory, error) {
if instrument == "" {
return nil, errInstrumentIdentifierRequired
return nil, errInstrumentIDRequired
}
if start.IsZero() {
return nil, errStartTimeRequired
Expand Down Expand Up @@ -252,7 +251,7 @@ func stringFromInterval(interval kline.Interval) (string, error) {
// GetHistoricalFundingRate retrieves the historical funding rates for a specific instrument.
func (co *CoinbaseInternational) GetHistoricalFundingRate(ctx context.Context, instrument string, resultOffset, resultLimit int64) (*FundingRateHistory, error) {
if instrument == "" {
return nil, errInstrumentIdentifierRequired
return nil, errInstrumentIDRequired
}
params := url.Values{}
if resultOffset > 0 {
Expand Down Expand Up @@ -361,6 +360,9 @@ func (co *CoinbaseInternational) ModifyOpenOrder(ctx context.Context, orderID st

// GetOrderDetail retrieves a single order. The order retrieved can be either active or inactive.
func (co *CoinbaseInternational) GetOrderDetail(ctx context.Context, orderID string) (*OrderItem, error) {
if orderID == "" {
return nil, order.ErrOrderIDNotSet
}
var resp *OrderItem
return resp, co.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, "orders/"+orderID, nil, nil, &resp, true)
}
Expand Down
16 changes: 9 additions & 7 deletions exchanges/coinbaseinternational/coinbaseinternational_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func TestMain(m *testing.M) {
}

co.Enabled = true
co.Websocket.Enable()
if apiKey != "" && apiSecret != "" {
co.API.AuthenticatedSupport = true
co.API.AuthenticatedWebsocketSupport = true
Expand Down Expand Up @@ -145,7 +144,7 @@ func TestGetInstruments(t *testing.T) {
func TestGetInstrumentDetails(t *testing.T) {
t.Parallel()
_, err := co.GetInstrumentDetails(context.Background(), "", "", "")
require.ErrorIs(t, err, errInstrumentIdentifierRequired)
require.ErrorIs(t, err, errInstrumentIDRequired)

result, err := co.GetInstrumentDetails(context.Background(), "BTC-PERP", "", "")
require.NoError(t, err)
Expand All @@ -155,7 +154,7 @@ func TestGetInstrumentDetails(t *testing.T) {
func TestGetQuotePerInstrument(t *testing.T) {
t.Parallel()
_, err := co.GetQuotePerInstrument(context.Background(), "", "", "")
require.ErrorIs(t, err, errInstrumentIdentifierRequired)
require.ErrorIs(t, err, errInstrumentIDRequired)

result, err := co.GetQuotePerInstrument(context.Background(), "BTC-PERP", "", "")
require.NoError(t, err)
Expand All @@ -165,7 +164,7 @@ func TestGetQuotePerInstrument(t *testing.T) {
func TestGetDailyTradingVolumes(t *testing.T) {
t.Parallel()
_, err := co.GetDailyTradingVolumes(context.Background(), []string{}, 10, 10, time.Now().Add(-time.Hour*100), true)
require.ErrorIs(t, err, errInstrumentIdentifierRequired)
require.ErrorIs(t, err, errInstrumentIDRequired)

result, err := co.GetDailyTradingVolumes(context.Background(), []string{"BTC-PERP"}, 10, 1, time.Now().Add(-time.Hour*100), true)
require.NoError(t, err)
Expand All @@ -175,7 +174,7 @@ func TestGetDailyTradingVolumes(t *testing.T) {
func TestGetAggregatedCandlesDataPerInstrument(t *testing.T) {
t.Parallel()
_, err := co.GetAggregatedCandlesDataPerInstrument(context.Background(), "", kline.FiveMin, time.Time{}, time.Time{})
require.ErrorIs(t, err, errInstrumentIdentifierRequired)
require.ErrorIs(t, err, errInstrumentIDRequired)
_, err = co.GetAggregatedCandlesDataPerInstrument(context.Background(), "BTC-PERP", kline.FiveMin, time.Time{}, time.Time{})
require.ErrorIs(t, err, errStartTimeRequired)
_, err = co.GetAggregatedCandlesDataPerInstrument(context.Background(), "BTC-PERP", kline.TenMin, time.Now().Add(-time.Hour*100), time.Time{})
Expand All @@ -189,7 +188,7 @@ func TestGetAggregatedCandlesDataPerInstrument(t *testing.T) {
func TestGetHistoricalFundingRates(t *testing.T) {
t.Parallel()
_, err := co.GetHistoricalFundingRate(context.Background(), "", 0, 10)
require.ErrorIs(t, err, errInstrumentIdentifierRequired)
require.ErrorIs(t, err, errInstrumentIDRequired)

result, err := co.GetHistoricalFundingRate(context.Background(), "BTC-PERP", 0, 10)
require.NoError(t, err)
Expand Down Expand Up @@ -288,6 +287,9 @@ func TestModifyOpenOrder(t *testing.T) {

func TestGetOrderDetails(t *testing.T) {
t.Parallel()
_, err := co.GetOrderDetail(context.Background(), "")
require.ErrorIs(t, err, order.ErrOrderIDNotSet)

sharedtestvalues.SkipTestIfCredentialsUnset(t, co)
result, err := co.GetOrderDetail(context.Background(), "1234")
require.NoError(t, err)
Expand Down Expand Up @@ -732,7 +734,7 @@ func TestUpdateTickers(t *testing.T) {
func TestGenerateSubscriptionPayload(t *testing.T) {
t.Parallel()
_, err := co.GenerateSubscriptionPayload(subscription.List{}, "SUBSCRIBE")
require.ErrorIs(t, err, errEmptyArgument)
require.ErrorIs(t, err, common.ErrEmptyParams)

payload, err := co.GenerateSubscriptionPayload(subscription.List{
{Channel: cnlFunding, Pairs: currency.Pairs{{Base: currency.BTC, Delimiter: "-", Quote: currency.USDT}}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/gorilla/websocket"
"github.com/shopspring/decimal"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
Expand Down Expand Up @@ -299,7 +300,7 @@ func (co *CoinbaseInternational) processInstruments(respRaw []byte) error {
// GenerateSubscriptionPayload generates a subscription payloads list.
func (co *CoinbaseInternational) GenerateSubscriptionPayload(subscriptions subscription.List, operation string) ([]SubscriptionInput, error) {
if len(subscriptions) == 0 {
return nil, errEmptyArgument
return nil, common.ErrEmptyParams
}
channelPairsMap := make(map[string]currency.Pairs)
format, err := co.GetPairFormat(asset.Spot, true)
Expand Down

0 comments on commit bf38fc7

Please sign in to comment.