String concatenation/conversion/formatting improvements (#393)

* Magic strings

* Comment, format and builder fixes
This commit is contained in:
lozdog245
2019-12-09 11:44:01 +11:00
committed by Adrian Gallagher
parent 17a786536d
commit 8c30505d46
32 changed files with 122 additions and 128 deletions

View File

@@ -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
}

View File

@@ -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()

View File

@@ -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

View File

@@ -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"`

View File

@@ -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

View File

@@ -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 {

View File

@@ -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

View File

@@ -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

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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

View File

@@ -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)
}

View File

@@ -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],
})
}

View File

@@ -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 {

View File

@@ -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(),
})
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -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"`

View File

@@ -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

View File

@@ -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:

View File

@@ -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{}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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)
}

View File

@@ -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,

View File

@@ -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)
}

View File

@@ -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

View File

@@ -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

View File

@@ -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)