From 8c30505d462b4c94dde3e5a115cf2dbdf000a1a7 Mon Sep 17 00:00:00 2001 From: lozdog245 <37864968+lozdog245@users.noreply.github.com> Date: Mon, 9 Dec 2019 11:44:01 +1100 Subject: [PATCH] String concatenation/conversion/formatting improvements (#393) * Magic strings * Comment, format and builder fixes --- common/common.go | 2 +- .../currencylayer/currencylayer.go | 5 ++-- exchanges/anx/anx_wrapper.go | 5 ++-- exchanges/binance/binance.go | 20 ++++++++-------- exchanges/binance/binance_wrapper.go | 7 +++--- exchanges/bitfinex/bitfinex.go | 2 +- exchanges/bitfinex/bitfinex_types.go | 2 +- exchanges/bitfinex/bitfinex_wrapper.go | 20 +++++++--------- exchanges/bitflyer/bitflyer.go | 21 +++++++--------- exchanges/bithumb/bithumb.go | 15 ++++++------ exchanges/bithumb/bithumb_wrapper.go | 4 +++- exchanges/bitmex/bitmex.go | 3 +-- exchanges/bitmex/bitmex_websocket.go | 4 ++-- exchanges/bitstamp/bitstamp.go | 8 +++---- exchanges/bitstamp/bitstamp_websocket.go | 3 +-- exchanges/bitstamp/bitstamp_wrapper.go | 24 +++++++++---------- exchanges/coinbasepro/coinbasepro_wrapper.go | 5 ++-- exchanges/coinut/coinut_websocket.go | 5 +++- exchanges/exchange.go | 10 ++++---- exchanges/exmo/exmo.go | 5 +--- exchanges/gemini/gemini_websocket.go | 2 +- exchanges/hitbtc/hitbtc_wrapper.go | 4 ++-- exchanges/huobi/huobi_wrapper.go | 7 +++--- exchanges/kraken/kraken.go | 1 + exchanges/kraken/kraken_websocket.go | 2 +- exchanges/kraken/kraken_wrapper.go | 7 +++--- exchanges/lakebtc/lakebtc_test.go | 3 +-- exchanges/lakebtc/lakebtc_websocket.go | 7 +++--- exchanges/localbitcoins/localbitcoins.go | 8 +++---- exchanges/okcoin/okcoin_wrapper.go | 5 ++-- exchanges/okgroup/okgroup_websocket.go | 24 +++++++++---------- exchanges/zb/zb_websocket.go | 10 ++++---- 32 files changed, 122 insertions(+), 128 deletions(-) diff --git a/common/common.go b/common/common.go index 83229675..ecccac19 100644 --- a/common/common.go +++ b/common/common.go @@ -282,7 +282,7 @@ func GetURIPath(uri string) string { return "" } if urip.RawQuery != "" { - return fmt.Sprintf("%s?%s", urip.Path, urip.RawQuery) + return urip.Path + "?" + urip.RawQuery } return urip.Path } diff --git a/currency/forexprovider/currencylayer/currencylayer.go b/currency/forexprovider/currencylayer/currencylayer.go index 59c85a31..b0a36fc9 100644 --- a/currency/forexprovider/currencylayer/currencylayer.go +++ b/currency/forexprovider/currencylayer/currencylayer.go @@ -13,7 +13,6 @@ package currencylayer import ( "errors" - "fmt" "net/http" "net/url" "strconv" @@ -200,10 +199,10 @@ func (c *CurrencyLayer) SendHTTPRequest(endPoint string, values url.Values, resu var auth bool if c.APIKeyLvl == AccountFree { - path = fmt.Sprintf("%s%s%s", APIEndpointURL, endPoint, "?") + path = APIEndpointURL + endPoint + "?" } else { auth = true - path = fmt.Sprintf("%s%s%s", APIEndpointURLSSL, endPoint, "?") + path = APIEndpointURLSSL + endPoint + "?" } path += values.Encode() diff --git a/exchanges/anx/anx_wrapper.go b/exchanges/anx/anx_wrapper.go index 2a393832..5c1184bf 100644 --- a/exchanges/anx/anx_wrapper.go +++ b/exchanges/anx/anx_wrapper.go @@ -1,7 +1,6 @@ package anx import ( - "fmt" "strconv" "strings" "sync" @@ -191,7 +190,9 @@ func (a *ANX) FetchTradablePairs(asset asset.Item) ([]string, error) { var currencies []string for x := range result.CurrencyPairs { - currencies = append(currencies, fmt.Sprintf("%v%v%v", result.CurrencyPairs[x].TradedCcy, a.GetPairFormat(asset, false).Delimiter, result.CurrencyPairs[x].SettlementCcy)) + currencies = append(currencies, result.CurrencyPairs[x].TradedCcy+ + a.GetPairFormat(asset, false).Delimiter+ + result.CurrencyPairs[x].SettlementCcy) } return currencies, nil diff --git a/exchanges/binance/binance.go b/exchanges/binance/binance.go index 17e609f1..fb0f8a16 100644 --- a/exchanges/binance/binance.go +++ b/exchanges/binance/binance.go @@ -279,7 +279,7 @@ func (b *Binance) GetPriceChangeStats(symbol string) (PriceChangeStats, error) { // GetTickers returns the ticker data for the last 24 hrs func (b *Binance) GetTickers() ([]PriceChangeStats, error) { var resp []PriceChangeStats - path := fmt.Sprintf("%s%s", b.API.Endpoints.URL, priceChange) + path := b.API.Endpoints.URL + priceChange return resp, b.SendHTTPRequest(path, &resp) } @@ -313,7 +313,7 @@ func (b *Binance) GetBestPrice(symbol string) (BestPrice, error) { func (b *Binance) NewOrder(o *NewOrderRequest) (NewOrderResponse, error) { var resp NewOrderResponse - path := fmt.Sprintf("%s%s", b.API.Endpoints.URL, newOrder) + path := b.API.Endpoints.URL + newOrder params := url.Values{} params.Set("symbol", o.Symbol) @@ -357,7 +357,7 @@ func (b *Binance) NewOrder(o *NewOrderRequest) (NewOrderResponse, error) { func (b *Binance) CancelExistingOrder(symbol string, orderID int64, origClientOrderID string) (CancelOrderResponse, error) { var resp CancelOrderResponse - path := fmt.Sprintf("%s%s", b.API.Endpoints.URL, cancelOrder) + path := b.API.Endpoints.URL + cancelOrder params := url.Values{} params.Set("symbol", symbol) @@ -379,7 +379,7 @@ func (b *Binance) CancelExistingOrder(symbol string, orderID int64, origClientOr func (b *Binance) OpenOrders(symbol string) ([]QueryOrderData, error) { var resp []QueryOrderData - path := fmt.Sprintf("%s%s", b.API.Endpoints.URL, openOrders) + path := b.API.Endpoints.URL + openOrders params := url.Values{} @@ -400,7 +400,7 @@ func (b *Binance) OpenOrders(symbol string) ([]QueryOrderData, error) { func (b *Binance) AllOrders(symbol, orderID, limit string) ([]QueryOrderData, error) { var resp []QueryOrderData - path := fmt.Sprintf("%s%s", b.API.Endpoints.URL, allOrders) + path := b.API.Endpoints.URL + allOrders params := url.Values{} params.Set("symbol", strings.ToUpper(symbol)) @@ -421,7 +421,7 @@ func (b *Binance) AllOrders(symbol, orderID, limit string) ([]QueryOrderData, er func (b *Binance) QueryOrder(symbol, origClientOrderID string, orderID int64) (QueryOrderData, error) { var resp QueryOrderData - path := fmt.Sprintf("%s%s", b.API.Endpoints.URL, queryOrder) + path := b.API.Endpoints.URL + queryOrder params := url.Values{} params.Set("symbol", strings.ToUpper(symbol)) @@ -451,7 +451,7 @@ func (b *Binance) GetAccount() (*Account, error) { var resp response - path := fmt.Sprintf("%s%s", b.API.Endpoints.URL, accountInfo) + path := b.API.Endpoints.URL + accountInfo params := url.Values{} if err := b.SendAuthHTTPRequest(http.MethodGet, path, params, &resp); err != nil { @@ -503,7 +503,7 @@ func (b *Binance) SendAuthHTTPRequest(method, path string, params url.Values, re } path = common.EncodeURLValues(path, params) - path += fmt.Sprintf("&signature=%s", hmacSignedStr) + path += "&signature=" + hmacSignedStr interim := json.RawMessage{} @@ -643,7 +643,7 @@ func getCryptocurrencyWithdrawalFee(c currency.Code) float64 { // WithdrawCrypto sends cryptocurrency to the address of your choosing func (b *Binance) WithdrawCrypto(asset, address, addressTag, name, amount string) (string, error) { var resp WithdrawResponse - path := fmt.Sprintf("%s%s", b.API.Endpoints.URL, withdraw) + path := b.API.Endpoints.URL + withdraw params := url.Values{} params.Set("asset", asset) @@ -669,7 +669,7 @@ func (b *Binance) WithdrawCrypto(asset, address, addressTag, name, amount string // GetDepositAddressForCurrency retrieves the wallet address for a given currency func (b *Binance) GetDepositAddressForCurrency(currency string) (string, error) { - path := fmt.Sprintf("%s%s", b.API.Endpoints.URL, depositAddress) + path := b.API.Endpoints.URL + depositAddress resp := struct { Address string `json:"address"` diff --git a/exchanges/binance/binance_wrapper.go b/exchanges/binance/binance_wrapper.go index 59203ff1..4f79f15c 100644 --- a/exchanges/binance/binance_wrapper.go +++ b/exchanges/binance/binance_wrapper.go @@ -231,10 +231,9 @@ func (b *Binance) FetchTradablePairs(asset asset.Item) ([]string, error) { for x := range info.Symbols { if info.Symbols[x].Status == "TRADING" { - validCurrencyPairs = append(validCurrencyPairs, fmt.Sprintf("%v%v%v", - info.Symbols[x].BaseAsset, - b.GetPairFormat(asset, false).Delimiter, - info.Symbols[x].QuoteAsset)) + validCurrencyPairs = append(validCurrencyPairs, info.Symbols[x].BaseAsset+ + b.GetPairFormat(asset, false).Delimiter+ + info.Symbols[x].QuoteAsset) } } return validCurrencyPairs, nil diff --git a/exchanges/bitfinex/bitfinex.go b/exchanges/bitfinex/bitfinex.go index 2877b2cb..a79811f3 100644 --- a/exchanges/bitfinex/bitfinex.go +++ b/exchanges/bitfinex/bitfinex.go @@ -948,7 +948,7 @@ func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[ n := b.Requester.GetNonce(true) req := make(map[string]interface{}) - req["request"] = fmt.Sprintf("%s%s", bitfinexAPIVersion, path) + req["request"] = bitfinexAPIVersion + path req["nonce"] = n.String() for key, value := range params { diff --git a/exchanges/bitfinex/bitfinex_types.go b/exchanges/bitfinex/bitfinex_types.go index 23864bb4..7ef5ceb6 100644 --- a/exchanges/bitfinex/bitfinex_types.go +++ b/exchanges/bitfinex/bitfinex_types.go @@ -620,7 +620,7 @@ type WsMarginInfoBase struct { MarginNet float64 } -// WsMarginInfoBase recent funding trades received via websocket +// WsFundingTrade recent funding trades received via websocket type WsFundingTrade struct { ID int64 Symbol string diff --git a/exchanges/bitfinex/bitfinex_wrapper.go b/exchanges/bitfinex/bitfinex_wrapper.go index 95838ffc..555dedf4 100644 --- a/exchanges/bitfinex/bitfinex_wrapper.go +++ b/exchanges/bitfinex/bitfinex_wrapper.go @@ -2,7 +2,6 @@ package bitfinex import ( "errors" - "fmt" "net/url" "strconv" "strings" @@ -524,21 +523,20 @@ func (b *Bitfinex) WithdrawFiatFunds(withdrawRequest *exchange.FiatWithdrawReque return "", errors.New("no withdrawID returned. Check order status") } - var withdrawalSuccesses string - var withdrawalErrors string - for _, withdrawal := range resp { - if withdrawal.Status == "error" { - withdrawalErrors += fmt.Sprintf("%v ", withdrawal.Message) + var withdrawalSuccesses, withdrawalErrors strings.Builder + for x := range resp { + if resp[x].Status == "error" { + withdrawalErrors.WriteString(resp[x].Message + " ") } - if withdrawal.Status == "success" { - withdrawalSuccesses += fmt.Sprintf("%v,", withdrawal.WithdrawalID) + if resp[x].Status == "success" { + withdrawalSuccesses.WriteString(strconv.FormatInt(resp[x].WithdrawalID, 10) + ",") } } - if len(withdrawalErrors) > 0 { - return withdrawalSuccesses, errors.New(withdrawalErrors) + if withdrawalErrors.Len() > 0 { + return withdrawalSuccesses.String(), errors.New(withdrawalErrors.String()) } - return withdrawalSuccesses, nil + return withdrawalSuccesses.String(), nil } // WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is submitted diff --git a/exchanges/bitflyer/bitflyer.go b/exchanges/bitflyer/bitflyer.go index 77aad8c5..9c9a520a 100644 --- a/exchanges/bitflyer/bitflyer.go +++ b/exchanges/bitflyer/bitflyer.go @@ -74,8 +74,7 @@ type Bitflyer struct { // analysis system func (b *Bitflyer) GetLatestBlockCA() (ChainAnalysisBlock, error) { var resp ChainAnalysisBlock - path := fmt.Sprintf("%s%s", b.API.Endpoints.URLSecondary, latestBlock) - + path := b.API.Endpoints.URLSecondary + latestBlock return resp, b.SendHTTPRequest(path, &resp) } @@ -83,8 +82,7 @@ func (b *Bitflyer) GetLatestBlockCA() (ChainAnalysisBlock, error) { // analysis system func (b *Bitflyer) GetBlockCA(blockhash string) (ChainAnalysisBlock, error) { var resp ChainAnalysisBlock - path := fmt.Sprintf("%s%s%s", b.API.Endpoints.URLSecondary, blockByBlockHash, blockhash) - + path := b.API.Endpoints.URLSecondary + blockByBlockHash + blockhash return resp, b.SendHTTPRequest(path, &resp) } @@ -92,8 +90,9 @@ func (b *Bitflyer) GetBlockCA(blockhash string) (ChainAnalysisBlock, error) { // analysis system func (b *Bitflyer) GetBlockbyHeightCA(height int64) (ChainAnalysisBlock, error) { var resp ChainAnalysisBlock - path := fmt.Sprintf("%s%s%s", b.API.Endpoints.URLSecondary, blockByBlockHeight, strconv.FormatInt(height, 10)) - + path := b.API.Endpoints.URLSecondary + + blockByBlockHeight + + strconv.FormatInt(height, 10) return resp, b.SendHTTPRequest(path, &resp) } @@ -101,8 +100,7 @@ func (b *Bitflyer) GetBlockbyHeightCA(height int64) (ChainAnalysisBlock, error) // bitflyer chain analysis system func (b *Bitflyer) GetTransactionByHashCA(txHash string) (ChainAnalysisTransaction, error) { var resp ChainAnalysisTransaction - path := fmt.Sprintf("%s%s%s", b.API.Endpoints.URLSecondary, transaction, txHash) - + path := b.API.Endpoints.URLSecondary + transaction + txHash return resp, b.SendHTTPRequest(path, &resp) } @@ -110,7 +108,7 @@ func (b *Bitflyer) GetTransactionByHashCA(txHash string) (ChainAnalysisTransacti // from bitflyer chain analysis system func (b *Bitflyer) GetAddressInfoCA(addressln string) (ChainAnalysisAddress, error) { var resp ChainAnalysisAddress - path := fmt.Sprintf("%s%s%s", b.API.Endpoints.URLSecondary, address, addressln) + path := b.API.Endpoints.URLSecondary + address + addressln return resp, b.SendHTTPRequest(path, &resp) } @@ -118,7 +116,7 @@ func (b *Bitflyer) GetAddressInfoCA(addressln string) (ChainAnalysisAddress, err // GetMarkets returns market information func (b *Bitflyer) GetMarkets() ([]MarketInfo, error) { var resp []MarketInfo - path := fmt.Sprintf("%s%s", b.API.Endpoints.URL, pubGetMarkets) + path := b.API.Endpoints.URL + pubGetMarkets return resp, b.SendHTTPRequest(path, &resp) } @@ -139,7 +137,6 @@ func (b *Bitflyer) GetTicker(symbol string) (Ticker, error) { v := url.Values{} v.Set("product_code", symbol) path := fmt.Sprintf("%s%s?%s", b.API.Endpoints.URL, pubGetTicker, v.Encode()) - return resp, b.SendHTTPRequest(path, &resp) } @@ -157,7 +154,7 @@ func (b *Bitflyer) GetExecutionHistory(symbol string) ([]ExecutedTrade, error) { func (b *Bitflyer) GetExchangeStatus() (string, error) { resp := make(map[string]string) - path := fmt.Sprintf("%s%s", b.API.Endpoints.URL, pubGetHealth) + path := b.API.Endpoints.URL + pubGetHealth err := b.SendHTTPRequest(path, &resp) if err != nil { diff --git a/exchanges/bithumb/bithumb.go b/exchanges/bithumb/bithumb.go index 3cdd892a..d4fc20fc 100644 --- a/exchanges/bithumb/bithumb.go +++ b/exchanges/bithumb/bithumb.go @@ -74,10 +74,9 @@ func (b *Bithumb) GetTradablePairs() ([]string, error) { // symbol e.g. "btc" func (b *Bithumb) GetTicker(symbol string) (Ticker, error) { var response TickerResponse - path := fmt.Sprintf("%s%s%s", - b.API.Endpoints.URL, - publicTicker, - strings.ToUpper(symbol)) + path := b.API.Endpoints.URL + + publicTicker + + strings.ToUpper(symbol) err := b.SendHTTPRequest(path, &response) if err != nil { return response.Data, err @@ -93,7 +92,7 @@ func (b *Bithumb) GetTicker(symbol string) (Ticker, error) { // GetAllTickers returns all ticker information func (b *Bithumb) GetAllTickers() (map[string]Ticker, error) { var response TickersResponse - path := fmt.Sprintf("%s%s%s", b.API.Endpoints.URL, publicTicker, "all") + path := b.API.Endpoints.URL + publicTicker + "all" err := b.SendHTTPRequest(path, &response) if err != nil { return nil, err @@ -123,7 +122,7 @@ func (b *Bithumb) GetAllTickers() (map[string]Ticker, error) { // symbol e.g. "btc" func (b *Bithumb) GetOrderBook(symbol string) (Orderbook, error) { response := Orderbook{} - path := fmt.Sprintf("%s%s%s", b.API.Endpoints.URL, publicOrderBook, strings.ToUpper(symbol)) + path := b.API.Endpoints.URL + publicOrderBook + strings.ToUpper(symbol) err := b.SendHTTPRequest(path, &response) if err != nil { @@ -142,7 +141,9 @@ func (b *Bithumb) GetOrderBook(symbol string) (Orderbook, error) { // symbol e.g. "btc" func (b *Bithumb) GetTransactionHistory(symbol string) (TransactionHistory, error) { response := TransactionHistory{} - path := fmt.Sprintf("%s%s%s", b.API.Endpoints.URL, publicTransactionHistory, strings.ToUpper(symbol)) + path := b.API.Endpoints.URL + + publicTransactionHistory + + strings.ToUpper(symbol) err := b.SendHTTPRequest(path, &response) if err != nil { diff --git a/exchanges/bithumb/bithumb_wrapper.go b/exchanges/bithumb/bithumb_wrapper.go index 8d08da2b..73dc3c3f 100644 --- a/exchanges/bithumb/bithumb_wrapper.go +++ b/exchanges/bithumb/bithumb_wrapper.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "math" + "strconv" "sync" "time" @@ -423,7 +424,8 @@ func (b *Bithumb) WithdrawFiatFunds(withdrawRequest *exchange.FiatWithdrawReques if withdrawRequest.Currency != currency.KRW { return "", errors.New("only KRW is supported") } - bankDetails := fmt.Sprintf("%v_%v", withdrawRequest.BankCode, withdrawRequest.BankName) + bankDetails := strconv.FormatFloat(withdrawRequest.BankCode, 'f', -1, 64) + + "_" + withdrawRequest.BankName resp, err := b.RequestKRWWithdraw(bankDetails, withdrawRequest.BankAccountNumber, int64(withdrawRequest.Amount)) if err != nil { return "", err diff --git a/exchanges/bitmex/bitmex.go b/exchanges/bitmex/bitmex.go index a073a923..5a886b4d 100644 --- a/exchanges/bitmex/bitmex.go +++ b/exchanges/bitmex/bitmex.go @@ -327,9 +327,8 @@ func (b *Bitmex) GetCurrentNotifications() ([]Notification, error) { // GetOrders returns all the orders, open and closed func (b *Bitmex) GetOrders(params *OrdersRequest) ([]Order, error) { var orders []Order - return orders, b.SendAuthenticatedHTTPRequest(http.MethodGet, - fmt.Sprintf("%v%v", bitmexEndpointOrder, ""), + bitmexEndpointOrder, params, &orders) } diff --git a/exchanges/bitmex/bitmex_websocket.go b/exchanges/bitmex/bitmex_websocket.go index b0338ad9..61db8928 100644 --- a/exchanges/bitmex/bitmex_websocket.go +++ b/exchanges/bitmex/bitmex_websocket.go @@ -434,7 +434,7 @@ func (b *Bitmex) GenerateDefaultSubscriptions() { for i := range channels { for j := range allPairs { subscriptions = append(subscriptions, wshandler.WebsocketChannelSubscription{ - Channel: fmt.Sprintf("%v:%v", channels[i], allPairs[j].String()), + Channel: channels[i] + ":" + allPairs[j].String(), Currency: allPairs[j], }) } @@ -474,7 +474,7 @@ func (b *Bitmex) GenerateAuthenticatedSubscriptions() { for i := range channels { for j := range contracts { subscriptions = append(subscriptions, wshandler.WebsocketChannelSubscription{ - Channel: fmt.Sprintf("%v:%v", channels[i], contracts[j].String()), + Channel: channels[i] + ":" + contracts[j].String(), Currency: contracts[j], }) } diff --git a/exchanges/bitstamp/bitstamp.go b/exchanges/bitstamp/bitstamp.go index 61b7b5fc..ad254a60 100644 --- a/exchanges/bitstamp/bitstamp.go +++ b/exchanges/bitstamp/bitstamp.go @@ -681,11 +681,11 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, v2 bool, values url return errors.New(errCap.Error) } if data, ok := errCap.Reason.(map[string][]string); ok { - var details string - for _, v := range data { - details += strings.Join(v, "") + var details strings.Builder + for x := range data { + details.WriteString(strings.Join(data[x], "")) } - return errors.New(details) + return errors.New(details.String()) } if data, ok := errCap.Reason.(string); ok { diff --git a/exchanges/bitstamp/bitstamp_websocket.go b/exchanges/bitstamp/bitstamp_websocket.go index 8bc00249..65be546a 100644 --- a/exchanges/bitstamp/bitstamp_websocket.go +++ b/exchanges/bitstamp/bitstamp_websocket.go @@ -3,7 +3,6 @@ package bitstamp import ( "encoding/json" "errors" - "fmt" "net/http" "strconv" "strings" @@ -128,7 +127,7 @@ func (b *Bitstamp) generateDefaultSubscriptions() { for i := range channels { for j := range enabledCurrencies { subscriptions = append(subscriptions, wshandler.WebsocketChannelSubscription{ - Channel: fmt.Sprintf("%v%v", channels[i], enabledCurrencies[j].Lower().String()), + Channel: channels[i] + enabledCurrencies[j].Lower().String(), }) } } diff --git a/exchanges/bitstamp/bitstamp_wrapper.go b/exchanges/bitstamp/bitstamp_wrapper.go index 5b74ddf6..fc6fa247 100644 --- a/exchanges/bitstamp/bitstamp_wrapper.go +++ b/exchanges/bitstamp/bitstamp_wrapper.go @@ -430,11 +430,11 @@ func (b *Bitstamp) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoW return "", err } if len(resp.Error) != 0 { - var details string - for _, v := range resp.Error { - details += strings.Join(v, "") + var details strings.Builder + for x := range resp.Error { + details.WriteString(strings.Join(resp.Error[x], "")) } - return "", errors.New(details) + return "", errors.New(details.String()) } return resp.ID, nil @@ -458,11 +458,11 @@ func (b *Bitstamp) WithdrawFiatFunds(withdrawRequest *exchange.FiatWithdrawReque return "", err } if resp.Status == errStr { - var details string - for _, v := range resp.Reason { - details += strings.Join(v, "") + var details strings.Builder + for x := range resp.Reason { + details.WriteString(strings.Join(resp.Reason[x], "")) } - return "", errors.New(details) + return "", errors.New(details.String()) } return resp.ID, nil @@ -492,11 +492,11 @@ func (b *Bitstamp) WithdrawFiatFundsToInternationalBank(withdrawRequest *exchang return "", err } if resp.Status == errStr { - var details string - for _, v := range resp.Reason { - details += strings.Join(v, "") + var details strings.Builder + for x := range resp.Reason { + details.WriteString(strings.Join(resp.Reason[x], "")) } - return "", errors.New(details) + return "", errors.New(details.String()) } return resp.ID, nil diff --git a/exchanges/coinbasepro/coinbasepro_wrapper.go b/exchanges/coinbasepro/coinbasepro_wrapper.go index 959a3de8..db4848e8 100644 --- a/exchanges/coinbasepro/coinbasepro_wrapper.go +++ b/exchanges/coinbasepro/coinbasepro_wrapper.go @@ -233,8 +233,9 @@ func (c *CoinbasePro) FetchTradablePairs(asset asset.Item) ([]string, error) { var products []string for x := range pairs { - products = append(products, fmt.Sprintf("%s%s%s", pairs[x].BaseCurrency, - c.GetPairFormat(asset, false).Delimiter, pairs[x].QuoteCurrency)) + products = append(products, pairs[x].BaseCurrency+ + c.GetPairFormat(asset, false).Delimiter+ + pairs[x].QuoteCurrency) } return products, nil diff --git a/exchanges/coinut/coinut_websocket.go b/exchanges/coinut/coinut_websocket.go index c5dfbb19..a60a2c96 100644 --- a/exchanges/coinut/coinut_websocket.go +++ b/exchanges/coinut/coinut_websocket.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net/http" + "strconv" "strings" "time" @@ -377,7 +378,9 @@ func (c *COINUT) wsAuthenticate() error { } timestamp := time.Now().Unix() nonce := c.WebsocketConn.GenerateMessageID(false) - payload := fmt.Sprintf("%v|%v|%v", c.API.Credentials.ClientID, timestamp, nonce) + payload := c.API.Credentials.ClientID + "|" + + strconv.FormatInt(timestamp, 10) + "|" + + strconv.FormatInt(nonce, 10) hmac := crypto.GetHMAC(crypto.HashSHA256, []byte(payload), []byte(c.API.Credentials.Key)) loginRequest := struct { Request string `json:"request"` diff --git a/exchanges/exchange.go b/exchanges/exchange.go index 0f76eb90..2c71fafb 100644 --- a/exchanges/exchange.go +++ b/exchanges/exchange.go @@ -362,21 +362,21 @@ func (e *Base) SupportsPair(p currency.Pair, enabledPairs bool, assetType asset. // FormatExchangeCurrencies returns a string containing // the exchanges formatted currency pairs func (e *Base) FormatExchangeCurrencies(pairs []currency.Pair, assetType asset.Item) (string, error) { - var currencyItems string + var currencyItems strings.Builder pairFmt := e.GetPairFormat(assetType, true) for x := range pairs { - currencyItems += e.FormatExchangeCurrency(pairs[x], assetType).String() + currencyItems.WriteString(e.FormatExchangeCurrency(pairs[x], assetType).String()) if x == len(pairs)-1 { continue } - currencyItems += pairFmt.Separator + currencyItems.WriteString(pairFmt.Separator) } - if currencyItems == "" { + if currencyItems.Len() == 0 { return "", errors.New("returned empty string") } - return currencyItems, nil + return currencyItems.String(), nil } // FormatExchangeCurrency is a method that formats and returns a currency pair diff --git a/exchanges/exmo/exmo.go b/exchanges/exmo/exmo.go index e4f41b26..0e2dd899 100644 --- a/exchanges/exmo/exmo.go +++ b/exchanges/exmo/exmo.go @@ -210,12 +210,9 @@ func (e *EXMO) GetCryptoDepositAddress() (map[string]string, error) { switch r := result.(type) { case map[string]interface{}: mapString := make(map[string]string) - for key, value := range r { - strValue := fmt.Sprintf("%v", value) - mapString[key] = strValue + mapString[key] = value.(string) } - return mapString, nil default: diff --git a/exchanges/gemini/gemini_websocket.go b/exchanges/gemini/gemini_websocket.go index 36bf2cb2..e4c23b06 100644 --- a/exchanges/gemini/gemini_websocket.go +++ b/exchanges/gemini/gemini_websocket.go @@ -104,7 +104,7 @@ func (g *Gemini) WsSecureSubscribe(dialer *websocket.Dialer, url string) error { return fmt.Errorf("%v sendAuthenticatedHTTPRequest: Unable to JSON request", g.Name) } - endpoint := fmt.Sprintf("%v%v", g.API.Endpoints.WebsocketURL, url) + endpoint := g.API.Endpoints.WebsocketURL + url PayloadBase64 := crypto.Base64Encode(PayloadJSON) hmac := crypto.GetHMAC(crypto.HashSHA512_384, []byte(PayloadBase64), []byte(g.API.Credentials.Secret)) headers := http.Header{} diff --git a/exchanges/hitbtc/hitbtc_wrapper.go b/exchanges/hitbtc/hitbtc_wrapper.go index c1cc92b6..3acdf45d 100644 --- a/exchanges/hitbtc/hitbtc_wrapper.go +++ b/exchanges/hitbtc/hitbtc_wrapper.go @@ -222,8 +222,8 @@ func (h *HitBTC) FetchTradablePairs(asset asset.Item) ([]string, error) { var pairs []string for x := range symbols { - pairs = append(pairs, fmt.Sprintf("%v%v%v", symbols[x].BaseCurrency, - h.GetPairFormat(asset, false).Delimiter, symbols[x].QuoteCurrency)) + pairs = append(pairs, symbols[x].BaseCurrency+ + h.GetPairFormat(asset, false).Delimiter+symbols[x].QuoteCurrency) } return pairs, nil } diff --git a/exchanges/huobi/huobi_wrapper.go b/exchanges/huobi/huobi_wrapper.go index c2429488..b224c629 100644 --- a/exchanges/huobi/huobi_wrapper.go +++ b/exchanges/huobi/huobi_wrapper.go @@ -267,10 +267,9 @@ func (h *HUOBI) FetchTradablePairs(asset asset.Item) ([]string, error) { if symbols[x].State != "online" { continue } - pairs = append(pairs, fmt.Sprintf("%v%v%v", - symbols[x].BaseCurrency, - h.GetPairFormat(asset, false).Delimiter, - symbols[x].QuoteCurrency)) + pairs = append(pairs, symbols[x].BaseCurrency+ + h.GetPairFormat(asset, false).Delimiter+ + symbols[x].QuoteCurrency) } return pairs, nil diff --git a/exchanges/kraken/kraken.go b/exchanges/kraken/kraken.go index 46e532db..ca487ee8 100644 --- a/exchanges/kraken/kraken.go +++ b/exchanges/kraken/kraken.go @@ -1039,6 +1039,7 @@ func (k *Kraken) WithdrawCancel(c currency.Code, refID string) (bool, error) { return response.Result, GetError(response.Error) } +// GetWebsocketToken returns a websocket token func (k *Kraken) GetWebsocketToken() (string, error) { var response WsTokenResponse if err := k.SendAuthenticatedHTTPRequest(krakenWebsocketToken, url.Values{}, &response); err != nil { diff --git a/exchanges/kraken/kraken_websocket.go b/exchanges/kraken/kraken_websocket.go index 8faa8761..e6659a99 100644 --- a/exchanges/kraken/kraken_websocket.go +++ b/exchanges/kraken/kraken_websocket.go @@ -849,7 +849,7 @@ func (k *Kraken) GenerateDefaultSubscriptions() { k.Websocket.SubscribeToChannels(subscriptions) } -// GenerateDefaultSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions() +// GenerateAuthenticatedSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions() func (k *Kraken) GenerateAuthenticatedSubscriptions() { var subscriptions []wshandler.WebsocketChannelSubscription for i := range authenticatedChannels { diff --git a/exchanges/kraken/kraken_wrapper.go b/exchanges/kraken/kraken_wrapper.go index fa820996..71c23b31 100644 --- a/exchanges/kraken/kraken_wrapper.go +++ b/exchanges/kraken/kraken_wrapper.go @@ -260,10 +260,9 @@ func (k *Kraken) FetchTradablePairs(asset asset.Item) ([]string, error) { if v.Quote[0] == 'Z' || v.Quote[0] == 'X' { v.Quote = v.Quote[1:] } - products = append(products, fmt.Sprintf("%v%v%v", - v.Base, - k.GetPairFormat(asset, false).Delimiter, - v.Quote)) + products = append(products, v.Base+ + k.GetPairFormat(asset, false).Delimiter+ + v.Quote) } return products, nil } diff --git a/exchanges/lakebtc/lakebtc_test.go b/exchanges/lakebtc/lakebtc_test.go index fd2c87f1..afb75558 100644 --- a/exchanges/lakebtc/lakebtc_test.go +++ b/exchanges/lakebtc/lakebtc_test.go @@ -1,7 +1,6 @@ package lakebtc import ( - "fmt" "log" "os" "testing" @@ -474,7 +473,7 @@ func TestWsTickerProcessing(t *testing.T) { func TestGetCurrencyFromChannel(t *testing.T) { curr := currency.NewPair(currency.LTC, currency.BTC) - result := l.getCurrencyFromChannel(fmt.Sprintf("%v%v%v", marketSubstring, curr, globalSubstring)) + result := l.getCurrencyFromChannel(marketSubstring + curr.String() + globalSubstring) if curr != result { t.Errorf("currency result is not equal. Expected %v", curr) } diff --git a/exchanges/lakebtc/lakebtc_websocket.go b/exchanges/lakebtc/lakebtc_websocket.go index 0639ddc3..0bdf0955 100644 --- a/exchanges/lakebtc/lakebtc_websocket.go +++ b/exchanges/lakebtc/lakebtc_websocket.go @@ -76,10 +76,9 @@ func (l *LakeBTC) GenerateDefaultSubscriptions() { for j := range enabledCurrencies { enabledCurrencies[j].Delimiter = "" - channel := fmt.Sprintf("%v%v%v", - marketSubstring, - enabledCurrencies[j].Lower(), - globalSubstring) + channel := marketSubstring + + enabledCurrencies[j].Lower().String() + + globalSubstring subscriptions = append(subscriptions, wshandler.WebsocketChannelSubscription{ Channel: channel, diff --git a/exchanges/localbitcoins/localbitcoins.go b/exchanges/localbitcoins/localbitcoins.go index 4e97dc89..f84f0728 100644 --- a/exchanges/localbitcoins/localbitcoins.go +++ b/exchanges/localbitcoins/localbitcoins.go @@ -601,11 +601,11 @@ func (l *LocalBitcoins) WalletSend(address string, amount float64, pin int64) er if resp.Data.Message != "Money is being sent" { if len(resp.Error.Errors) != 0 { - var details string - for _, val := range resp.Error.Errors { - details += val + var details strings.Builder + for x := range resp.Error.Errors { + details.WriteString(resp.Error.Errors[x]) } - return errors.New(details) + return errors.New(details.String()) } return errors.New(resp.Data.Message) } diff --git a/exchanges/okcoin/okcoin_wrapper.go b/exchanges/okcoin/okcoin_wrapper.go index f5a80933..eb75893d 100644 --- a/exchanges/okcoin/okcoin_wrapper.go +++ b/exchanges/okcoin/okcoin_wrapper.go @@ -194,8 +194,9 @@ func (o *OKCoin) FetchTradablePairs(asset asset.Item) ([]string, error) { var pairs []string for x := range prods { - pairs = append(pairs, fmt.Sprintf("%v%v%v", prods[x].BaseCurrency, - o.GetPairFormat(asset, false).Delimiter, prods[x].QuoteCurrency)) + pairs = append(pairs, prods[x].BaseCurrency+ + o.GetPairFormat(asset, false).Delimiter+ + prods[x].QuoteCurrency) } return pairs, nil diff --git a/exchanges/okgroup/okgroup_websocket.go b/exchanges/okgroup/okgroup_websocket.go index 13f95a20..c1ae5fb5 100644 --- a/exchanges/okgroup/okgroup_websocket.go +++ b/exchanges/okgroup/okgroup_websocket.go @@ -670,23 +670,23 @@ func (o *OKGroup) WsProcessUpdateOrderbook(wsEventData *WebsocketDataWrapper, in // there are less than 25 entries (for whatever reason) // eg Bid:Ask:Bid:Ask:Ask:Ask func (o *OKGroup) CalculatePartialOrderbookChecksum(orderbookData *WebsocketDataWrapper) int32 { - var checksum string + var checksum strings.Builder for i := 0; i < allowableIterations; i++ { if len(orderbookData.Bids)-1 >= i { - checksum += orderbookData.Bids[i][0].(string) + + checksum.WriteString(orderbookData.Bids[i][0].(string) + delimiterColon + orderbookData.Bids[i][1].(string) + - delimiterColon + delimiterColon) } if len(orderbookData.Asks)-1 >= i { - checksum += orderbookData.Asks[i][0].(string) + + checksum.WriteString(orderbookData.Asks[i][0].(string) + delimiterColon + orderbookData.Asks[i][1].(string) + - delimiterColon + delimiterColon) } } - checksum = strings.TrimSuffix(checksum, delimiterColon) - return int32(crc32.ChecksumIEEE([]byte(checksum))) + checksumStr := strings.TrimSuffix(checksum.String(), delimiterColon) + return int32(crc32.ChecksumIEEE([]byte(checksumStr))) } // CalculateUpdateOrderbookChecksum alternates over the first 25 bid and ask @@ -695,21 +695,21 @@ func (o *OKGroup) CalculatePartialOrderbookChecksum(orderbookData *WebsocketData // there are less than 25 entries (for whatever reason) // eg Bid:Ask:Bid:Ask:Ask:Ask func (o *OKGroup) CalculateUpdateOrderbookChecksum(orderbookData *orderbook.Base) int32 { - var checksum string + var checksum strings.Builder for i := 0; i < allowableIterations; i++ { if len(orderbookData.Bids)-1 >= i { price := strconv.FormatFloat(orderbookData.Bids[i].Price, 'f', -1, 64) amount := strconv.FormatFloat(orderbookData.Bids[i].Amount, 'f', -1, 64) - checksum += price + delimiterColon + amount + delimiterColon + checksum.WriteString(price + delimiterColon + amount + delimiterColon) } if len(orderbookData.Asks)-1 >= i { price := strconv.FormatFloat(orderbookData.Asks[i].Price, 'f', -1, 64) amount := strconv.FormatFloat(orderbookData.Asks[i].Amount, 'f', -1, 64) - checksum += price + delimiterColon + amount + delimiterColon + checksum.WriteString(price + delimiterColon + amount + delimiterColon) } } - checksum = strings.TrimSuffix(checksum, delimiterColon) - return int32(crc32.ChecksumIEEE([]byte(checksum))) + checksumStr := strings.TrimSuffix(checksum.String(), delimiterColon) + return int32(crc32.ChecksumIEEE([]byte(checksumStr))) } // GenerateDefaultSubscriptions Adds default subscriptions to websocket to be diff --git a/exchanges/zb/zb_websocket.go b/exchanges/zb/zb_websocket.go index b4d31804..bc4466a9 100644 --- a/exchanges/zb/zb_websocket.go +++ b/exchanges/zb/zb_websocket.go @@ -377,7 +377,7 @@ func (z *ZB) wsSubmitOrder(pair currency.Pair, amount, price float64, tradeType TradeType: tradeType, No: z.WebsocketConn.GenerateMessageID(true), } - request.Channel = fmt.Sprintf("%v_order", pair.String()) + request.Channel = pair.String() + "_order" request.Event = zWebsocketAddChannel request.Accesskey = z.API.Credentials.Key request.Sign = z.wsGenerateSignature(request) @@ -405,7 +405,7 @@ func (z *ZB) wsCancelOrder(pair currency.Pair, orderID int64) (*WsCancelOrderRes ID: orderID, No: z.WebsocketConn.GenerateMessageID(true), } - request.Channel = fmt.Sprintf("%v_cancelorder", pair.String()) + request.Channel = pair.String() + "_cancelorder" request.Event = zWebsocketAddChannel request.Accesskey = z.API.Credentials.Key request.Sign = z.wsGenerateSignature(request) @@ -433,7 +433,7 @@ func (z *ZB) wsGetOrder(pair currency.Pair, orderID int64) (*WsGetOrderResponse, ID: orderID, No: z.WebsocketConn.GenerateMessageID(true), } - request.Channel = fmt.Sprintf("%v_getorder", pair.String()) + request.Channel = pair.String() + "_getorder" request.Event = zWebsocketAddChannel request.Accesskey = z.API.Credentials.Key request.Sign = z.wsGenerateSignature(request) @@ -462,7 +462,7 @@ func (z *ZB) wsGetOrders(pair currency.Pair, pageIndex, tradeType int64) (*WsGet TradeType: tradeType, No: z.WebsocketConn.GenerateMessageID(true), } - request.Channel = fmt.Sprintf("%v_getorders", pair.String()) + request.Channel = pair.String() + "_getorders" request.Event = zWebsocketAddChannel request.Accesskey = z.API.Credentials.Key request.Sign = z.wsGenerateSignature(request) @@ -490,7 +490,7 @@ func (z *ZB) wsGetOrdersIgnoreTradeType(pair currency.Pair, pageIndex, pageSize PageSize: pageSize, No: z.WebsocketConn.GenerateMessageID(true), } - request.Channel = fmt.Sprintf("%v_getordersignoretradetype", pair.String()) + request.Channel = pair.String() + "_getordersignoretradetype" request.Event = zWebsocketAddChannel request.Accesskey = z.API.Credentials.Key request.Sign = z.wsGenerateSignature(request)