From cdab89a58ac6524481fa989024204067c7cf8448 Mon Sep 17 00:00:00 2001 From: leilaes <44886693+leilaes@users.noreply.github.com> Date: Thu, 16 May 2019 12:19:08 +1200 Subject: [PATCH] Replace a zero-length, non-nil slice with a nil slice (#299) * Replace a zero-length, non-nil slice with a nil slice * Update codelingo.yaml --- codelingo.yaml | 2 +- common/common_test.go | 2 +- exchanges/binance/binance.go | 6 +-- exchanges/bitfinex/bitfinex.go | 38 +++++++++---------- exchanges/bitfinex/bitfinex_websocket.go | 10 ++--- exchanges/bitstamp/bitstamp.go | 12 +++--- exchanges/btcmarkets/btcmarkets.go | 4 +- exchanges/coinbasepro/coinbasepro.go | 26 ++++++------- .../coinbasepro/coinbasepro_websocket.go | 2 +- exchanges/coinbasepro/coinbasepro_wrapper.go | 2 +- exchanges/coinut/coinut.go | 2 +- exchanges/coinut/coinut_wrapper.go | 2 +- exchanges/exchange.go | 2 +- exchanges/exchange_websocket.go | 2 +- exchanges/exmo/exmo.go | 2 +- exchanges/gateio/gateio.go | 2 +- exchanges/gemini/gemini.go | 12 +++--- exchanges/hitbtc/hitbtc.go | 14 +++---- exchanges/itbit/itbit.go | 2 +- exchanges/lakebtc/lakebtc.go | 10 ++--- exchanges/localbitcoins/localbitcoins.go | 4 +- exchanges/okgroup/okgroup.go | 15 ++------ exchanges/orders/orders.go | 2 +- exchanges/poloniex/poloniex.go | 6 +-- exchanges/zb/zb.go | 2 +- helpers_test.go | 6 +-- 26 files changed, 90 insertions(+), 99 deletions(-) diff --git a/codelingo.yaml b/codelingo.yaml index a35408fb..e87d9bea 100644 --- a/codelingo.yaml +++ b/codelingo.yaml @@ -6,7 +6,7 @@ tenets: - import: codelingo/effective-go/single-method-interface-name - import: codelingo/effective-go/underscores-in-name - import: codelingo/effective-go/unnecessary-else - + - import: codelingo/code-review-comments/declare-empty-slice # Overwrite one tenet with custom logic # - import: codelingo/effective-go/comment-first-word-when-empty - name: comment-first-word-when-empty diff --git a/common/common_test.go b/common/common_test.go index 116af829..8905bb6f 100644 --- a/common/common_test.go +++ b/common/common_test.go @@ -715,7 +715,7 @@ func TestExtractPort(t *testing.T) { func TestOutputCSV(t *testing.T) { path := "../testdata/dump" - data := [][]string{} + var data [][]string rowOne := []string{"Appended", "to", "two", "dimensional", "array"} rowTwo := []string{"Appended", "to", "two", "dimensional", "array", "two"} data = append(data, rowOne, rowTwo) diff --git a/exchanges/binance/binance.go b/exchanges/binance/binance.go index 508f37f3..52b9d336 100644 --- a/exchanges/binance/binance.go +++ b/exchanges/binance/binance.go @@ -239,7 +239,7 @@ func (b *Binance) GetOrderBook(obd OrderBookDataRequestParams) (OrderBook, error // GetRecentTrades returns recent trade activity // limit: Up to 500 results returned func (b *Binance) GetRecentTrades(rtr RecentTradeRequestParams) ([]RecentTrade, error) { - resp := []RecentTrade{} + var resp []RecentTrade params := url.Values{} params.Set("symbol", common.StringToUpper(rtr.Symbol)) @@ -256,7 +256,7 @@ func (b *Binance) GetRecentTrades(rtr RecentTradeRequestParams) ([]RecentTrade, // limit: Optional. Default 500; max 1000. // fromID: func (b *Binance) GetHistoricalTrades(symbol string, limit int, fromID int64) ([]HistoricalTrade, error) { - resp := []HistoricalTrade{} + var resp []HistoricalTrade if err := b.CheckLimit(limit); err != nil { return resp, err @@ -277,7 +277,7 @@ func (b *Binance) GetHistoricalTrades(symbol string, limit int, fromID int64) ([ // symbol: string of currency pair // limit: Optional. Default 500; max 1000. func (b *Binance) GetAggregatedTrades(symbol string, limit int) ([]AggregatedTrade, error) { - resp := []AggregatedTrade{} + var resp []AggregatedTrade if err := b.CheckLimit(limit); err != nil { return resp, err diff --git a/exchanges/bitfinex/bitfinex.go b/exchanges/bitfinex/bitfinex.go index 2d88d627..9368e0a7 100644 --- a/exchanges/bitfinex/bitfinex.go +++ b/exchanges/bitfinex/bitfinex.go @@ -310,7 +310,7 @@ func (b *Bitfinex) GetTickersV2(symbols string) ([]Tickersv2, error) { // GetStats returns various statistics about the requested pair func (b *Bitfinex) GetStats(symbol string) ([]Stat, error) { - response := []Stat{} + var response []Stat path := fmt.Sprint(b.APIUrl + bitfinexAPIVersion + bitfinexStats + symbol) return response, b.SendHTTPRequest(path, &response, b.Verbose) @@ -402,7 +402,7 @@ func (b *Bitfinex) GetOrderbookV2(symbol, precision string, values url.Values) ( // Values can contain limit amounts for the number of trades returned - Example // "limit_trades" = 1000 func (b *Bitfinex) GetTrades(currencyPair string, values url.Values) ([]TradeStructure, error) { - response := []TradeStructure{} + var response []TradeStructure path := common.EncodeURLValues( b.APIUrl+bitfinexAPIVersion+bitfinexTrades+currencyPair, values, @@ -480,7 +480,7 @@ func (b *Bitfinex) GetLendbook(symbol string, values url.Values) (Lendbook, erro // over time // Symbol - example "USD" func (b *Bitfinex) GetLends(symbol string, values url.Values) ([]Lends, error) { - response := []Lends{} + var response []Lends path := common.EncodeURLValues(b.APIUrl+bitfinexAPIVersion+bitfinexLends+symbol, values) @@ -489,7 +489,7 @@ func (b *Bitfinex) GetLends(symbol string, values url.Values) ([]Lends, error) { // GetSymbols returns the available currency pairs on the exchange func (b *Bitfinex) GetSymbols() ([]string, error) { - products := []string{} + var products []string path := fmt.Sprint(b.APIUrl + bitfinexAPIVersion + bitfinexSymbols) return products, b.SendHTTPRequest(path, &products, b.Verbose) @@ -497,7 +497,7 @@ func (b *Bitfinex) GetSymbols() ([]string, error) { // GetSymbolsDetails a list of valid symbol IDs and the pair details func (b *Bitfinex) GetSymbolsDetails() ([]SymbolDetails, error) { - response := []SymbolDetails{} + var response []SymbolDetails path := fmt.Sprint(b.APIUrl + bitfinexAPIVersion + bitfinexSymbolsDetails) return response, b.SendHTTPRequest(path, &response, b.Verbose) @@ -560,7 +560,7 @@ func (b *Bitfinex) GetKeyPermissions() (KeyPermissions, error) { // GetMarginInfo shows your trading wallet information for margin trading func (b *Bitfinex) GetMarginInfo() ([]MarginInfo, error) { - response := []MarginInfo{} + var response []MarginInfo return response, b.SendAuthenticatedHTTPRequest(http.MethodPost, @@ -569,7 +569,7 @@ func (b *Bitfinex) GetMarginInfo() ([]MarginInfo, error) { // GetAccountBalance returns full wallet balance information func (b *Bitfinex) GetAccountBalance() ([]Balance, error) { - response := []Balance{} + var response []Balance return response, b.SendAuthenticatedHTTPRequest(http.MethodPost, @@ -582,7 +582,7 @@ func (b *Bitfinex) GetAccountBalance() ([]Balance, error) { // WalletFrom - example "exchange" // WalletTo - example "deposit" func (b *Bitfinex) WalletTransfer(amount float64, currency, walletFrom, walletTo string) ([]WalletTransfer, error) { - response := []WalletTransfer{} + var response []WalletTransfer req := make(map[string]interface{}) req["amount"] = amount req["currency"] = currency @@ -599,7 +599,7 @@ func (b *Bitfinex) WalletTransfer(amount float64, currency, walletFrom, walletTo // WithdrawCryptocurrency requests a withdrawal from one of your wallets. // For FIAT, use WithdrawFIAT func (b *Bitfinex) WithdrawCryptocurrency(withdrawType, wallet, address, paymentID string, amount float64, c currency.Code) ([]Withdrawal, error) { - response := []Withdrawal{} + var response []Withdrawal req := make(map[string]interface{}) req["withdraw_type"] = withdrawType req["walletselected"] = wallet @@ -618,7 +618,7 @@ func (b *Bitfinex) WithdrawCryptocurrency(withdrawType, wallet, address, payment // WithdrawFIAT requests a withdrawal from a designated fiat wallet func (b *Bitfinex) WithdrawFIAT(withdrawalType, walletType string, withdrawRequest *exchange.WithdrawRequest) ([]Withdrawal, error) { - response := []Withdrawal{} + var response []Withdrawal req := make(map[string]interface{}) req["withdraw_type"] = withdrawalType @@ -787,7 +787,7 @@ func (b *Bitfinex) GetOpenOrders() ([]Order, error) { // GetActivePositions returns an array of active positions func (b *Bitfinex) GetActivePositions() ([]Position, error) { - response := []Position{} + var response []Position return response, b.SendAuthenticatedHTTPRequest(http.MethodPost, @@ -811,7 +811,7 @@ func (b *Bitfinex) ClaimPosition(positionID int) (Position, error) { // GetBalanceHistory returns balance history for the account func (b *Bitfinex) GetBalanceHistory(symbol string, timeSince, timeUntil time.Time, limit int, wallet string) ([]BalanceHistory, error) { - response := []BalanceHistory{} + var response []BalanceHistory req := make(map[string]interface{}) req["currency"] = symbol @@ -837,7 +837,7 @@ func (b *Bitfinex) GetBalanceHistory(symbol string, timeSince, timeUntil time.Ti // GetMovementHistory returns an array of past deposits and withdrawals func (b *Bitfinex) GetMovementHistory(symbol, method string, timeSince, timeUntil time.Time, limit int) ([]MovementHistory, error) { - response := []MovementHistory{} + var response []MovementHistory req := make(map[string]interface{}) req["currency"] = symbol @@ -863,7 +863,7 @@ func (b *Bitfinex) GetMovementHistory(symbol, method string, timeSince, timeUnti // GetTradeHistory returns past executed trades func (b *Bitfinex) GetTradeHistory(currencyPair string, timestamp, until time.Time, limit, reverse int) ([]TradeHistory, error) { - response := []TradeHistory{} + var response []TradeHistory req := make(map[string]interface{}) req["currency"] = currencyPair req["timestamp"] = timestamp @@ -931,7 +931,7 @@ func (b *Bitfinex) GetOfferStatus(offerID int64) (Offer, error) { // GetActiveCredits returns all available credits func (b *Bitfinex) GetActiveCredits() ([]Offer, error) { - response := []Offer{} + var response []Offer return response, b.SendAuthenticatedHTTPRequest(http.MethodPost, @@ -942,7 +942,7 @@ func (b *Bitfinex) GetActiveCredits() ([]Offer, error) { // GetActiveOffers returns all current active offers func (b *Bitfinex) GetActiveOffers() ([]Offer, error) { - response := []Offer{} + var response []Offer return response, b.SendAuthenticatedHTTPRequest(http.MethodPost, @@ -953,7 +953,7 @@ func (b *Bitfinex) GetActiveOffers() ([]Offer, error) { // GetActiveMarginFunding returns an array of active margin funds func (b *Bitfinex) GetActiveMarginFunding() ([]MarginFunds, error) { - response := []MarginFunds{} + var response []MarginFunds return response, b.SendAuthenticatedHTTPRequest(http.MethodPost, @@ -965,7 +965,7 @@ func (b *Bitfinex) GetActiveMarginFunding() ([]MarginFunds, error) { // GetUnusedMarginFunds returns an array of funding borrowed but not currently // used func (b *Bitfinex) GetUnusedMarginFunds() ([]MarginFunds, error) { - response := []MarginFunds{} + var response []MarginFunds return response, b.SendAuthenticatedHTTPRequest(http.MethodPost, @@ -977,7 +977,7 @@ func (b *Bitfinex) GetUnusedMarginFunds() ([]MarginFunds, error) { // GetMarginTotalTakenFunds returns an array of active funding used in a // position func (b *Bitfinex) GetMarginTotalTakenFunds() ([]MarginTotalTakenFunds, error) { - response := []MarginTotalTakenFunds{} + var response []MarginTotalTakenFunds return response, b.SendAuthenticatedHTTPRequest(http.MethodPost, diff --git a/exchanges/bitfinex/bitfinex_websocket.go b/exchanges/bitfinex/bitfinex_websocket.go index ad8ade13..603a9ce6 100644 --- a/exchanges/bitfinex/bitfinex_websocket.go +++ b/exchanges/bitfinex/bitfinex_websocket.go @@ -286,7 +286,7 @@ func (b *Bitfinex) WsDataHandler() { switch chanInfo.Channel { case "book": - newOrderbook := []WebsocketBook{} + var newOrderbook []WebsocketBook switch len(chanData) { case 2: data := chanData[1].([]interface{}) @@ -340,7 +340,7 @@ func (b *Bitfinex) WsDataHandler() { case "account": switch chanData[1].(string) { case bitfinexWebsocketPositionSnapshot: - positionSnapshot := []WebsocketPosition{} + var positionSnapshot []WebsocketPosition data := chanData[2].([]interface{}) for _, x := range data { y := x.([]interface{}) @@ -374,7 +374,7 @@ func (b *Bitfinex) WsDataHandler() { case bitfinexWebsocketWalletSnapshot: data := chanData[2].([]interface{}) - walletSnapshot := []WebsocketWallet{} + var walletSnapshot []WebsocketWallet for _, x := range data { y := x.([]interface{}) walletSnapshot = append(walletSnapshot, @@ -398,7 +398,7 @@ func (b *Bitfinex) WsDataHandler() { b.Websocket.DataHandler <- wallet case bitfinexWebsocketOrderSnapshot: - orderSnapshot := []WebsocketOrder{} + var orderSnapshot []WebsocketOrder data := chanData[2].([]interface{}) for _, x := range data { y := x.([]interface{}) @@ -447,7 +447,7 @@ func (b *Bitfinex) WsDataHandler() { } case "trades": - trades := []WebsocketTrade{} + var trades []WebsocketTrade switch len(chanData) { case 2: data := chanData[1].([]interface{}) diff --git a/exchanges/bitstamp/bitstamp.go b/exchanges/bitstamp/bitstamp.go index c40b8cc1..2712024b 100644 --- a/exchanges/bitstamp/bitstamp.go +++ b/exchanges/bitstamp/bitstamp.go @@ -316,7 +316,7 @@ func (b *Bitstamp) GetTradingPairs() ([]TradingPair, error) { // value paramater ["time"] = "minute", "hour", "day" will collate your // response into time intervals. Implementation of value in test code. func (b *Bitstamp) GetTransactions(currencyPair string, values url.Values) ([]Transactions, error) { - transactions := []Transactions{} + var transactions []Transactions path := common.EncodeURLValues( fmt.Sprintf( "%s/v%s/%s/%s/", @@ -361,7 +361,7 @@ func (b *Bitstamp) GetUserTransactions(currencyPair string) ([]UserTransactions, Fee float64 `json:"fee,string"` OrderID int64 `json:"order_id"` } - response := []Response{} + var response []Response if currencyPair != "" { if err := b.SendAuthenticatedHTTPRequest(bitstampAPIUserTransactions, true, url.Values{}, &response); err != nil { @@ -373,7 +373,7 @@ func (b *Bitstamp) GetUserTransactions(currencyPair string) ([]UserTransactions, } } - transactions := []UserTransactions{} + var transactions []UserTransactions for _, y := range response { tx := UserTransactions{} @@ -416,7 +416,7 @@ func (b *Bitstamp) GetUserTransactions(currencyPair string) ([]UserTransactions, // GetOpenOrders returns all open orders on the exchange func (b *Bitstamp) GetOpenOrders(currencyPair string) ([]Order, error) { - resp := []Order{} + var resp []Order path := fmt.Sprintf( "%s/%s", bitstampAPIOpenOrders, common.StringToLower(currencyPair), ) @@ -478,7 +478,7 @@ func (b *Bitstamp) PlaceOrder(currencyPair string, price, amount float64, buy, m // timedelta - positive integer with max value 50000000 which returns requests // from number of seconds ago to now. func (b *Bitstamp) GetWithdrawalRequests(timedelta int64) ([]WithdrawalRequests, error) { - resp := []WithdrawalRequests{} + var resp []WithdrawalRequests if timedelta > 50000000 || timedelta < 0 { return resp, errors.New("time delta exceeded, max: 50000000 min: 0") } @@ -613,7 +613,7 @@ func (b *Bitstamp) GetCryptoDepositAddress(crypto currency.Code) (string, error) // GetUnconfirmedBitcoinDeposits returns unconfirmed transactions func (b *Bitstamp) GetUnconfirmedBitcoinDeposits() ([]UnconfirmedBTCTransactions, error) { - response := []UnconfirmedBTCTransactions{} + var response []UnconfirmedBTCTransactions return response, b.SendAuthenticatedHTTPRequest(bitstampAPIUnconfirmedBitcoin, false, nil, &response) diff --git a/exchanges/btcmarkets/btcmarkets.go b/exchanges/btcmarkets/btcmarkets.go index 6c41ab11..42bb2505 100644 --- a/exchanges/btcmarkets/btcmarkets.go +++ b/exchanges/btcmarkets/btcmarkets.go @@ -165,7 +165,7 @@ func (b *BTCMarkets) GetOrderbook(firstPair, secondPair string) (Orderbook, erro // symbol - example "btc" or "ltc" // values - optional paramater "since" example values.Set(since, "59868345231") func (b *BTCMarkets) GetTrades(firstPair, secondPair string, values url.Values) ([]Trade, error) { - trades := []Trade{} + var trades []Trade path := common.EncodeURLValues(fmt.Sprintf("%s/market/%s/%s/trades", b.APIUrl, common.StringToUpper(firstPair), common.StringToUpper(secondPair)), values) @@ -352,7 +352,7 @@ func (b *BTCMarkets) GetOrderDetail(orderID []int64) ([]Order, error) { // GetAccountBalance returns the full account balance func (b *BTCMarkets) GetAccountBalance() ([]AccountBalance, error) { - balance := []AccountBalance{} + var balance []AccountBalance err := b.SendAuthenticatedRequest(http.MethodGet, btcMarketsAccountBalance, nil, &balance) if err != nil { diff --git a/exchanges/coinbasepro/coinbasepro.go b/exchanges/coinbasepro/coinbasepro.go index 9f61b14f..5222c2e3 100644 --- a/exchanges/coinbasepro/coinbasepro.go +++ b/exchanges/coinbasepro/coinbasepro.go @@ -144,7 +144,7 @@ func (c *CoinbasePro) Setup(exch *config.ExchangeConfig) { // GetProducts returns supported currency pairs on the exchange with specific // information about the pair func (c *CoinbasePro) GetProducts() ([]Product, error) { - products := []Product{} + var products []Product return products, c.SendHTTPRequest(c.APIUrl+coinbaseproProducts, &products) } @@ -233,7 +233,7 @@ func (c *CoinbasePro) GetTicker(currencyPair string) (Ticker, error) { // GetTrades listd the latest trades for a product // currencyPair - example "BTC-USD" func (c *CoinbasePro) GetTrades(currencyPair string) ([]Trade, error) { - trades := []Trade{} + var trades []Trade path := fmt.Sprintf( "%s/%s/%s", c.APIUrl+coinbaseproProducts, currencyPair, coinbaseproTrades) @@ -244,7 +244,7 @@ func (c *CoinbasePro) GetTrades(currencyPair string) ([]Trade, error) { // grouped buckets based on requested granularity. func (c *CoinbasePro) GetHistoricRates(currencyPair string, start, end, granularity int64) ([]History, error) { var resp [][]interface{} - history := []History{} + var history []History values := url.Values{} if start > 0 { @@ -300,7 +300,7 @@ func (c *CoinbasePro) GetStats(currencyPair string) (Stats, error) { // GetCurrencies returns a list of supported currency on the exchange // Warning: Not all currencies may be currently in use for tradinc. func (c *CoinbasePro) GetCurrencies() ([]Currency, error) { - currencies := []Currency{} + var currencies []Currency return currencies, c.SendHTTPRequest(c.APIUrl+coinbaseproCurrencies, ¤cies) } @@ -314,7 +314,7 @@ func (c *CoinbasePro) GetServerTime() (ServerTime, error) { // GetAccounts returns a list of trading accounts associated with the APIKEYS func (c *CoinbasePro) GetAccounts() ([]AccountResponse, error) { - resp := []AccountResponse{} + var resp []AccountResponse return resp, c.SendAuthenticatedHTTPRequest(http.MethodGet, coinbaseproAccounts, nil, &resp) @@ -333,7 +333,7 @@ func (c *CoinbasePro) GetAccount(accountID string) (AccountResponse, error) { // increases or decreases your account balance. Items are paginated and sorted // latest first. func (c *CoinbasePro) GetAccountHistory(accountID string) ([]AccountLedgerResponse, error) { - resp := []AccountLedgerResponse{} + var resp []AccountLedgerResponse path := fmt.Sprintf("%s/%s/%s", coinbaseproAccounts, accountID, coinbaseproLedger) return resp, c.SendAuthenticatedHTTPRequest(http.MethodGet, path, nil, &resp) @@ -344,7 +344,7 @@ func (c *CoinbasePro) GetAccountHistory(accountID string) ([]AccountLedgerRespon // is updated. If an order is canceled, any remaining hold is removed. For a // withdraw, once it is completed, the hold is removed. func (c *CoinbasePro) GetHolds(accountID string) ([]AccountHolds, error) { - resp := []AccountHolds{} + var resp []AccountHolds path := fmt.Sprintf("%s/%s/%s", coinbaseproAccounts, accountID, coinbaseproHolds) return resp, c.SendAuthenticatedHTTPRequest(http.MethodGet, path, nil, &resp) @@ -514,7 +514,7 @@ func (c *CoinbasePro) CancelAllExistingOrders(currencyPair string) ([]string, er // status - can be a range of "open", "pending", "done" or "active" // currencyPair - [optional] for example "BTC-USD" func (c *CoinbasePro) GetOrders(status []string, currencyPair string) ([]GeneralizedOrderResponse, error) { - resp := []GeneralizedOrderResponse{} + var resp []GeneralizedOrderResponse params := url.Values{} for _, individualStatus := range status { @@ -541,7 +541,7 @@ func (c *CoinbasePro) GetOrder(orderID string) (GeneralizedOrderResponse, error) // GetFills returns a list of recent fills func (c *CoinbasePro) GetFills(orderID, currencyPair string) ([]FillResponse, error) { - resp := []FillResponse{} + var resp []FillResponse params := url.Values{} if orderID != "" { @@ -566,7 +566,7 @@ func (c *CoinbasePro) GetFills(orderID, currencyPair string) ([]FillResponse, er // // status - "outstanding", "settled", or "rejected" func (c *CoinbasePro) GetFundingRecords(status string) ([]Funding, error) { - resp := []Funding{} + var resp []Funding params := url.Values{} params.Set("status", status) @@ -636,7 +636,7 @@ func (c *CoinbasePro) ClosePosition(repayOnly bool) (AccountOverview, error) { // GetPayMethods returns a full list of payment methods func (c *CoinbasePro) GetPayMethods() ([]PaymentMethod, error) { - resp := []PaymentMethod{} + var resp []PaymentMethod return resp, c.SendAuthenticatedHTTPRequest(http.MethodGet, coinbaseproPaymentMethod, nil, &resp) @@ -729,7 +729,7 @@ func (c *CoinbasePro) WithdrawCrypto(amount float64, currency, cryptoAddress str // GetCoinbaseAccounts returns a list of coinbase accounts func (c *CoinbasePro) GetCoinbaseAccounts() ([]CoinbaseAccounts, error) { - resp := []CoinbaseAccounts{} + var resp []CoinbaseAccounts return resp, c.SendAuthenticatedHTTPRequest(http.MethodGet, coinbaseproCoinbaseAccounts, nil, &resp) @@ -784,7 +784,7 @@ func (c *CoinbasePro) GetReportStatus(reportID string) (Report, error) { // GetTrailingVolume this request will return your 30-day trailing volume for // all products. func (c *CoinbasePro) GetTrailingVolume() ([]Volume, error) { - resp := []Volume{} + var resp []Volume return resp, c.SendAuthenticatedHTTPRequest(http.MethodGet, coinbaseproTrailingVolume, nil, &resp) diff --git a/exchanges/coinbasepro/coinbasepro_websocket.go b/exchanges/coinbasepro/coinbasepro_websocket.go index 32874a08..af1adcc9 100644 --- a/exchanges/coinbasepro/coinbasepro_websocket.go +++ b/exchanges/coinbasepro/coinbasepro_websocket.go @@ -22,7 +22,7 @@ const ( // WebsocketSubscriber subscribes to websocket channels with respect to enabled // currencies func (c *CoinbasePro) WebsocketSubscriber() error { - currencies := []string{} + var currencies []string for _, x := range c.EnabledPairs.Strings() { currency := x[0:3] + "-" + x[3:] currencies = append(currencies, currency) diff --git a/exchanges/coinbasepro/coinbasepro_wrapper.go b/exchanges/coinbasepro/coinbasepro_wrapper.go index 91b4177b..baf3d83e 100644 --- a/exchanges/coinbasepro/coinbasepro_wrapper.go +++ b/exchanges/coinbasepro/coinbasepro_wrapper.go @@ -36,7 +36,7 @@ func (c *CoinbasePro) Run() { if err != nil { log.Errorf("%s Failed to get available products.\n", c.GetName()) } else { - currencies := []string{} + var currencies []string for _, x := range exchangeProducts { if x.ID != "BTC" && x.ID != "USD" && x.ID != "GBP" { currencies = append(currencies, x.ID[0:3]+x.ID[4:]) diff --git a/exchanges/coinut/coinut.go b/exchanges/coinut/coinut.go index 236f4ae1..fcfb3412 100644 --- a/exchanges/coinut/coinut.go +++ b/exchanges/coinut/coinut.go @@ -252,7 +252,7 @@ func (c *COINUT) CancelOrders(orders []CancelOrders) (CancelOrdersResponse, erro OrderID int `json:"order_id"` } - entries := []CancelOrders{} + var entries []CancelOrders entries = append(entries, orders...) params["entries"] = entries diff --git a/exchanges/coinut/coinut_wrapper.go b/exchanges/coinut/coinut_wrapper.go index 01d57993..916ae934 100644 --- a/exchanges/coinut/coinut_wrapper.go +++ b/exchanges/coinut/coinut_wrapper.go @@ -39,7 +39,7 @@ func (c *COINUT) Run() { return } - currencies := []string{} + var currencies []string c.InstrumentMap = make(map[string]int) for x, y := range exchangeProducts.Instruments { c.InstrumentMap[x] = y[0].InstID diff --git a/exchanges/exchange.go b/exchanges/exchange.go index 7df68795..9bdebd0b 100644 --- a/exchanges/exchange.go +++ b/exchanges/exchange.go @@ -896,7 +896,7 @@ func (e *Base) SupportsWithdrawPermissions(permissions uint32) bool { // FormatWithdrawPermissions will return each of the exchange's compatible withdrawal methods in readable form func (e *Base) FormatWithdrawPermissions() string { - services := []string{} + var services []string for i := 0; i < 32; i++ { var check uint32 = 1 << uint32(i) if e.GetWithdrawPermissions()&check != 0 { diff --git a/exchanges/exchange_websocket.go b/exchanges/exchange_websocket.go index 57276ad9..57d73650 100644 --- a/exchanges/exchange_websocket.go +++ b/exchanges/exchange_websocket.go @@ -645,7 +645,7 @@ func (w *Websocket) SupportsFunctionality(f uint32) bool { // FormatFunctionality will return each of the websocket connection compatible // stream methods as a string func (w *Websocket) FormatFunctionality() string { - functionality := []string{} + var functionality []string for i := 0; i < 32; i++ { var check uint32 = 1 << uint32(i) if w.GetFunctionality()&check != 0 { diff --git a/exchanges/exmo/exmo.go b/exchanges/exmo/exmo.go index a089d63a..10d59e60 100644 --- a/exchanges/exmo/exmo.go +++ b/exchanges/exmo/exmo.go @@ -154,7 +154,7 @@ func (e *EXMO) GetPairSettings() (map[string]PairSettings, error) { // GetCurrency returns a list of currencies func (e *EXMO) GetCurrency() ([]string, error) { - result := []string{} + var result []string urlPath := fmt.Sprintf("%s/v%s/%s", e.APIUrl, exmoAPIVersion, exmoCurrency) return result, e.SendHTTPRequest(urlPath, &result) } diff --git a/exchanges/gateio/gateio.go b/exchanges/gateio/gateio.go index cb56159e..a972951e 100644 --- a/exchanges/gateio/gateio.go +++ b/exchanges/gateio/gateio.go @@ -292,7 +292,7 @@ func (g *Gateio) GetSpotKline(arg KlinesRequestParams) ([]*KLineResponse, error) } rawKlineDatasString, _ := json.Marshal(rawKlines["data"].([]interface{})) - rawKlineDatas := [][]interface{}{} + var rawKlineDatas [][]interface{} if err := json.Unmarshal(rawKlineDatasString, &rawKlineDatas); err != nil { return nil, fmt.Errorf("rawKlines unmarshal failed. Err: %s", err) } diff --git a/exchanges/gemini/gemini.go b/exchanges/gemini/gemini.go index 13e9da76..c625b4ce 100644 --- a/exchanges/gemini/gemini.go +++ b/exchanges/gemini/gemini.go @@ -178,7 +178,7 @@ func (g *Gemini) Setup(exch *config.ExchangeConfig) { // GetSymbols returns all available symbols for trading func (g *Gemini) GetSymbols() ([]string, error) { - symbols := []string{} + var symbols []string path := fmt.Sprintf("%s/v%s/%s", g.APIUrl, geminiAPIVersion, geminiSymbols) return symbols, g.SendHTTPRequest(path, &symbols) @@ -255,7 +255,7 @@ func (g *Gemini) GetOrderbook(currencyPair string, params url.Values) (Orderbook // default. Can be '1' or 'true' to activate func (g *Gemini) GetTrades(currencyPair string, params url.Values) ([]Trade, error) { path := common.EncodeURLValues(fmt.Sprintf("%s/v%s/%s/%s", g.APIUrl, geminiAPIVersion, geminiTrades, currencyPair), params) - trades := []Trade{} + var trades []Trade return trades, g.SendHTTPRequest(path, &trades) } @@ -281,7 +281,7 @@ func (g *Gemini) GetAuction(currencyPair string) (Auction, error) { // indicative prices and quantities. func (g *Gemini) GetAuctionHistory(currencyPair string, params url.Values) ([]AuctionHistory, error) { path := common.EncodeURLValues(fmt.Sprintf("%s/v%s/%s/%s/%s", g.APIUrl, geminiAPIVersion, geminiAuction, currencyPair, geminiAuctionHistory), params) - auctionHist := []AuctionHistory{} + var auctionHist []AuctionHistory return auctionHist, g.SendHTTPRequest(path, &auctionHist) } @@ -397,7 +397,7 @@ func (g *Gemini) GetOrders() ([]Order, error) { // currencyPair - example "btcusd" // timestamp - [optional] Only return trades on or after this timestamp. func (g *Gemini) GetTradeHistory(currencyPair string, timestamp int64) ([]TradeHistory, error) { - response := []TradeHistory{} + var response []TradeHistory req := make(map[string]interface{}) req["symbol"] = currencyPair @@ -419,7 +419,7 @@ func (g *Gemini) GetNotionalVolume() (NotionalVolume, error) { // GetTradeVolume returns a multi-arrayed volume response func (g *Gemini) GetTradeVolume() ([][]TradeVolume, error) { - response := [][]TradeVolume{} + var response [][]TradeVolume return response, g.SendAuthenticatedHTTPRequest(http.MethodPost, geminiTradeVolume, nil, &response) @@ -427,7 +427,7 @@ func (g *Gemini) GetTradeVolume() ([][]TradeVolume, error) { // GetBalances returns available balances in the supported currencies func (g *Gemini) GetBalances() ([]Balance, error) { - response := []Balance{} + var response []Balance return response, g.SendAuthenticatedHTTPRequest(http.MethodPost, geminiBalances, nil, &response) diff --git a/exchanges/hitbtc/hitbtc.go b/exchanges/hitbtc/hitbtc.go index 5ddb1928..09be9548 100644 --- a/exchanges/hitbtc/hitbtc.go +++ b/exchanges/hitbtc/hitbtc.go @@ -172,7 +172,7 @@ func (h *HitBTC) GetCurrency(currency string) (Currencies, error) { // pair indicates how much of the quote currency is needed to purchase one unit // of the base currency. func (h *HitBTC) GetSymbols(symbol string) ([]string, error) { - resp := []Symbol{} + var resp []Symbol path := fmt.Sprintf("%s/%s/%s", h.APIUrl, apiV2Symbol, symbol) ret := make([]string, 0, len(resp)) @@ -190,7 +190,7 @@ func (h *HitBTC) GetSymbols(symbol string) ([]string, error) { // GetSymbolsDetailed is the same as above but returns an array of symbols with // all their details. func (h *HitBTC) GetSymbolsDetailed() ([]Symbol, error) { - resp := []Symbol{} + var resp []Symbol path := fmt.Sprintf("%s/%s", h.APIUrl, apiV2Symbol) return resp, h.SendHTTPRequest(path, &resp) @@ -198,7 +198,7 @@ func (h *HitBTC) GetSymbolsDetailed() ([]Symbol, error) { // GetTicker returns ticker information func (h *HitBTC) GetTicker(symbol string) (map[string]Ticker, error) { - resp1 := []TickerResponse{} + var resp1 []TickerResponse resp2 := TickerResponse{} ret := make(map[string]TickerResponse) result := make(map[string]Ticker) @@ -292,7 +292,7 @@ func (h *HitBTC) GetTrades(currencyPair, from, till, limit, offset, by, sort str vals.Set("sort", sort) } - resp := []TradeHistory{} + var resp []TradeHistory path := fmt.Sprintf("%s/%s/%s?%s", h.APIUrl, apiV2Trades, currencyPair, vals.Encode()) return resp, h.SendHTTPRequest(path, &resp) @@ -337,7 +337,7 @@ func (h *HitBTC) GetCandles(currencyPair, limit, period string) ([]ChartData, er vals.Set("period", period) } - resp := []ChartData{} + var resp []ChartData path := fmt.Sprintf("%s/%s/%s?%s", h.APIUrl, apiV2Candles, currencyPair, vals.Encode()) return resp, h.SendHTTPRequest(path, &resp) @@ -348,7 +348,7 @@ func (h *HitBTC) GetCandles(currencyPair, limit, period string) ([]ChartData, er // GetBalances returns full balance for your account func (h *HitBTC) GetBalances() (map[string]Balance, error) { - result := []Balance{} + var result []Balance err := h.SendAuthenticatedHTTPRequest(http.MethodGet, apiV2Balance, url.Values{}, &result) ret := make(map[string]Balance) @@ -384,7 +384,7 @@ func (h *HitBTC) GenerateNewAddress(currency string) (DepositCryptoAddresses, er // GetActiveorders returns all your active orders func (h *HitBTC) GetActiveorders(currency string) ([]Order, error) { - resp := []Order{} + var resp []Order err := h.SendAuthenticatedHTTPRequest(http.MethodGet, orders+"?symbol="+currency, url.Values{}, &resp) return resp, err diff --git a/exchanges/itbit/itbit.go b/exchanges/itbit/itbit.go index 200f7df9..f9bf026e 100644 --- a/exchanges/itbit/itbit.go +++ b/exchanges/itbit/itbit.go @@ -142,7 +142,7 @@ func (i *ItBit) GetTradeHistory(currencyPair, timestamp string) (Trades, error) // page - [optional] page to return example 1. default 1 // perPage - [optional] items per page example 50, default 50 max 50 func (i *ItBit) GetWallets(params url.Values) ([]Wallet, error) { - resp := []Wallet{} + var resp []Wallet params.Set("userId", i.ClientID) path := fmt.Sprintf("/%s?%s", itbitWallets, params.Encode()) diff --git a/exchanges/lakebtc/lakebtc.go b/exchanges/lakebtc/lakebtc.go index caec611d..96ad6c7b 100644 --- a/exchanges/lakebtc/lakebtc.go +++ b/exchanges/lakebtc/lakebtc.go @@ -205,7 +205,7 @@ func (l *LakeBTC) GetOrderBook(currency string) (Orderbook, error) { // GetTradeHistory returns the trade history for a given currency pair func (l *LakeBTC) GetTradeHistory(currency string) ([]TradeHistory, error) { path := fmt.Sprintf("%s/%s?symbol=%s", l.APIUrl, lakeBTCTrades, common.StringToLower(currency)) - resp := []TradeHistory{} + var resp []TradeHistory return resp, l.SendHTTPRequest(path, &resp) } @@ -242,7 +242,7 @@ func (l *LakeBTC) Trade(isBuyOrder bool, amount, price float64, currency string) // GetOpenOrders returns all open orders associated with your account func (l *LakeBTC) GetOpenOrders() ([]OpenOrders, error) { - orders := []OpenOrders{} + var orders []OpenOrders return orders, l.SendAuthenticatedHTTPRequest(lakeBTCOpenOrders, "", &orders) } @@ -254,7 +254,7 @@ func (l *LakeBTC) GetOrders(orders []int64) ([]Orders, error) { ordersStr = append(ordersStr, strconv.FormatInt(x, 10)) } - resp := []Orders{} + var resp []Orders return resp, l.SendAuthenticatedHTTPRequest(lakeBTCGetOrders, common.JoinStrings(ordersStr, ","), &resp) } @@ -304,13 +304,13 @@ func (l *LakeBTC) GetTrades(timestamp int64) ([]AuthenticatedTradeHistory, error params = strconv.FormatInt(timestamp, 10) } - trades := []AuthenticatedTradeHistory{} + var trades []AuthenticatedTradeHistory return trades, l.SendAuthenticatedHTTPRequest(lakeBTCGetTrades, params, &trades) } // GetExternalAccounts returns your external accounts WARNING: Only for BTC! func (l *LakeBTC) GetExternalAccounts() ([]ExternalAccounts, error) { - resp := []ExternalAccounts{} + var resp []ExternalAccounts return resp, l.SendAuthenticatedHTTPRequest(lakeBTCGetExternalAccounts, "", &resp) } diff --git a/exchanges/localbitcoins/localbitcoins.go b/exchanges/localbitcoins/localbitcoins.go index 172fee20..860743a4 100644 --- a/exchanges/localbitcoins/localbitcoins.go +++ b/exchanges/localbitcoins/localbitcoins.go @@ -461,7 +461,7 @@ func (l *LocalBitcoins) DeleteInvoice() (Invoice, error) { // GetNotifications returns recent notifications. func (l *LocalBitcoins) GetNotifications() ([]NotificationInfo, error) { - resp := []NotificationInfo{} + var resp []NotificationInfo return resp, l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIGetNotification, nil, &resp) } @@ -668,7 +668,7 @@ func (l *LocalBitcoins) GetTradableCurrencies() ([]string, error) { // updated every 15 minutes. func (l *LocalBitcoins) GetTrades(currency string, values url.Values) ([]Trade, error) { path := common.EncodeURLValues(fmt.Sprintf("%s/%s/trades.json", l.APIUrl+localbitcoinsAPIBitcoincharts, currency), values) - result := []Trade{} + var result []Trade return result, l.SendHTTPRequest(path, &result) } diff --git a/exchanges/okgroup/okgroup.go b/exchanges/okgroup/okgroup.go index 1f255e81..563164ee 100644 --- a/exchanges/okgroup/okgroup.go +++ b/exchanges/okgroup/okgroup.go @@ -275,7 +275,7 @@ func (o *OKGroup) PlaceMultipleSpotOrders(request []PlaceSpotOrderRequest) (map[ return resp, []error{err} } - orderErrors := []error{} + var orderErrors []error for currency, orderResponse := range resp { for _, order := range orderResponse { if !order.Result { @@ -283,9 +283,6 @@ func (o *OKGroup) PlaceMultipleSpotOrders(request []PlaceSpotOrderRequest) (map[ } } } - if len(orderErrors) == 0 { - orderErrors = nil - } return resp, orderErrors } @@ -475,7 +472,7 @@ func (o *OKGroup) PlaceMultipleMarginOrders(request []PlaceSpotOrderRequest) (ma return resp, []error{err} } - orderErrors := []error{} + var orderErrors []error for currency, orderResponse := range resp { for _, order := range orderResponse { if !order.Result { @@ -483,9 +480,6 @@ func (o *OKGroup) PlaceMultipleMarginOrders(request []PlaceSpotOrderRequest) (ma } } } - if len(orderErrors) == 0 { - orderErrors = nil - } return resp, orderErrors } @@ -508,7 +502,7 @@ func (o *OKGroup) CancelMultipleMarginOrders(request CancelMultipleSpotOrdersReq return resp, []error{err} } - orderErrors := []error{} + var orderErrors []error for currency, orderResponse := range resp { for _, order := range orderResponse { if !order.Result { @@ -516,9 +510,6 @@ func (o *OKGroup) CancelMultipleMarginOrders(request CancelMultipleSpotOrdersReq } } } - if len(orderErrors) == 0 { - orderErrors = nil - } return resp, orderErrors } diff --git a/exchanges/orders/orders.go b/exchanges/orders/orders.go index 698a0bc6..8308b4b0 100644 --- a/exchanges/orders/orders.go +++ b/exchanges/orders/orders.go @@ -46,7 +46,7 @@ func DeleteOrder(orderID int) bool { // GetOrdersByExchange returns order pointer grouped by exchange func GetOrdersByExchange(exchange string) []*Order { - orders := []*Order{} + var orders []*Order for i := range Orders { if Orders[i].Exchange == exchange { orders = append(orders, Orders[i]) diff --git a/exchanges/poloniex/poloniex.go b/exchanges/poloniex/poloniex.go index d4c6574d..d3c9b88a 100644 --- a/exchanges/poloniex/poloniex.go +++ b/exchanges/poloniex/poloniex.go @@ -248,7 +248,7 @@ func (p *Poloniex) GetTradeHistory(currencyPair, start, end string) ([]TradeHist vals.Set("end", end) } - resp := []TradeHistory{} + var resp []TradeHistory path := fmt.Sprintf("%s/public?command=returnTradeHistory&%s", p.APIUrl, vals.Encode()) return resp, p.SendHTTPRequest(path, &resp) @@ -271,7 +271,7 @@ func (p *Poloniex) GetChartData(currencyPair, start, end, period string) ([]Char vals.Set("period", period) } - resp := []ChartData{} + var resp []ChartData path := fmt.Sprintf("%s/public?command=returnChartData&%s", p.APIUrl, vals.Encode()) err := p.SendHTTPRequest(path, &resp) @@ -822,7 +822,7 @@ func (p *Poloniex) GetLendingHistory(start, end string) ([]LendingHistory, error vals.Set("end", end) } - resp := []LendingHistory{} + var resp []LendingHistory err := p.SendAuthenticatedHTTPRequest(http.MethodPost, poloniexLendingHistory, vals, diff --git a/exchanges/zb/zb.go b/exchanges/zb/zb.go index 35256f6e..b076b855 100644 --- a/exchanges/zb/zb.go +++ b/exchanges/zb/zb.go @@ -321,7 +321,7 @@ func (z *ZB) GetSpotKline(arg KlinesRequestParams) (KLineResponse, error) { res.MoneyType = rawKlines["moneyType"].(string) rawKlineDatasString, _ := json.Marshal(rawKlines["data"].([]interface{})) - rawKlineDatas := [][]interface{}{} + var rawKlineDatas [][]interface{} if err := json.Unmarshal(rawKlineDatasString, &rawKlineDatas); err != nil { return res, errors.New("zb rawKlines unmarshal failed") } diff --git a/helpers_test.go b/helpers_test.go index 2fc3d1a5..45049bc6 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -264,7 +264,7 @@ func TestGetSpecificOrderbook(t *testing.T) { LoadExchange("Bitstamp", false, nil) - bids := []orderbook.Item{} + var bids []orderbook.Item bids = append(bids, orderbook.Item{Price: 1000, Amount: 1}) base := orderbook.Base{ @@ -329,7 +329,7 @@ func TestGetSpecificTicker(t *testing.T) { func TestGetCollatedExchangeAccountInfoByCoin(t *testing.T) { SetupTestHelpers(t) - exchangeInfo := []exchange.AccountInfo{} + var exchangeInfo []exchange.AccountInfo var info exchange.AccountInfo info.Exchange = "Bitfinex" @@ -383,7 +383,7 @@ func TestGetCollatedExchangeAccountInfoByCoin(t *testing.T) { func TestGetAccountCurrencyInfoByExchangeName(t *testing.T) { SetupTestHelpers(t) - exchangeInfo := []exchange.AccountInfo{} + var exchangeInfo []exchange.AccountInfo var info exchange.AccountInfo info.Exchange = "Bitfinex" info.Accounts = append(info.Accounts,