From bf38fc78df9a0f539536f52d31590994fc82ca8d Mon Sep 17 00:00:00 2001 From: Samuael A <39623015+samuael@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:23:04 +0300 Subject: [PATCH] minor updates --- .../coinbaseinternational.go | 38 ++++++++++--------- .../coinbaseinternational_test.go | 16 ++++---- .../coinbaseinternational_websocket.go | 3 +- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/exchanges/coinbaseinternational/coinbaseinternational.go b/exchanges/coinbaseinternational/coinbaseinternational.go index 90b08ec52fa..cc6d9414b60 100644 --- a/exchanges/coinbaseinternational/coinbaseinternational.go +++ b/exchanges/coinbaseinternational/coinbaseinternational.go @@ -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. @@ -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) @@ -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) @@ -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, ",")) @@ -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 @@ -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 { @@ -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) } diff --git a/exchanges/coinbaseinternational/coinbaseinternational_test.go b/exchanges/coinbaseinternational/coinbaseinternational_test.go index f730b1a0fe0..dfdd1261e35 100644 --- a/exchanges/coinbaseinternational/coinbaseinternational_test.go +++ b/exchanges/coinbaseinternational/coinbaseinternational_test.go @@ -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 @@ -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) @@ -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) @@ -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) @@ -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{}) @@ -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) @@ -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) @@ -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}}}, diff --git a/exchanges/coinbaseinternational/coinbaseinternational_websocket.go b/exchanges/coinbaseinternational/coinbaseinternational_websocket.go index 718f7bd61a0..ae9cb43421f 100644 --- a/exchanges/coinbaseinternational/coinbaseinternational_websocket.go +++ b/exchanges/coinbaseinternational/coinbaseinternational_websocket.go @@ -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" @@ -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)